FocusAreafunction  R Documentation 
This function computes the KantorovichWasserstein distance within a given focus area embedded into a large region described as a grid map. Both the focus and the embedding areas are are described by spatial histograms, similarly to the input data of the other functions of this package.
The grid map is described by the two lists Xs
and Ys
of N
coordinates, which specify the coordinates of the centroid of every single tile.
For each tile i
with coordinates Xs[i], Ys[i]
, we have an entry in the two lists of weights W1
and W2
, one for the first histograms, and the other for the second histogram.
The two lists of coordinates Xs
and Ys
are passed to the focusArea
function as a matrix with N
rows and two columns.
The two lists of weights W1
and W2
are passed as a matrix with N
rows and two columns, a column for each histogram.
The focus area is specified by three parameters: the coordinates x
and y
of the center of the focus area, and the (circular) radius
of the focus area.
The pair of coordinates (x,y
) must correspond to a pair of coordinates contained in the vectors Xs,Ys
.
Every tile whose distance is less or equal to the radius
will be included in the focus area.
The focus area by default is circular, that is, the area is based on a L_2 norm. By setting the parameter area
to the value linf
it is possible to obtain
a squared focus area, induced by the norm L_infinity.
focusArea(Coordinates, Weights, x, y, radius, L = 3, recode = TRUE, method = "approx", algorithm = "colgen", model="mincostflow", verbosity = "silent", timelimit = 14400, opt_tolerance = 1e06, area = "l2")
Coordinates 
A

Weights 
A

x 
Horizontal coordinate of the centroid of the focus area. 
y 
Vertical coordinate of the centroid of the focus area. 
radius 
The radius of the focus area. 
L 
Approximation parameter. Higher values of L give a more accurate solution, but they require a longer running time. Data type: positive integer. 
recode 
If equal to 
method 
Method for computing the KW distances: 
algorithm 
Algorithm for computing the KW distances: 
model 
Model for building the underlying network: 
verbosity 
Level of verbosity of the log: 
timelimit 
Time limit in second for running the solver. 
opt_tolerance 
Numerical tolerance on the negative reduced cost for the optimal solution. 
area 
Type of norm for delimiting the focus area: 
The function focusArea(Coordinates, Weights, x, y, radius, ...)
computes the KW distance within a focus area by implicitly considering the surrounding larger area.
The mass contained within the focus area is transported to a destination either within or outside the focus area.
All the mass contained outside the focus area could be used to balance the mass within the focus area.
Return an R List with the following named attributes:
distance
: The value of the KWdistance between the two input areas.
status
: Status of the solver used to compute the distances.
runtime
: Overall runtime in seconds to compute all the distances.
iterations
: Overall number of iterations of the Capacitated Network Simplex algorithm.
nodes
: Number of nodes in the network model used to compute the distances.
arcs
: Number of arcs in the network model used to compute the distances.
See also compareOneToOne
, compareOneToMany
, compareAll
, Histogram2D
, and Solver
.
# Define a simple example library(SpatialKWD) # Random coordinates N = 90 Xs < as.integer(runif(N, 0, 31)) Ys < as.integer(runif(N, 0, 31)) coordinates < matrix(c(Xs, Ys), ncol=2, nrow=N) # Random weights test1 < matrix(runif(2*N, 0, 1), ncol=2, nrow=N) # Compute distance print("Compare onetoone with exact algorithm:") d < focusArea(coordinates, Weights=test1, x=15, y=15, radius=5, method="exact", recode=TRUE, verbosity = "info") cat("runtime:", d$runtime, " distance:", d$distance, " nodes:", d$nodes, " arcs:", d$arcs, "\n")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.