distUnitk | R Documentation |
Calculate the squared Euclidean distance from unit k
to the other units.
distUnitk(X, k, tore, toreBound)
X |
matrix representing the spatial coordinates. |
k |
the unit index to be used. |
tore |
an optional logical value, if we are considering the distance on a tore. See Details. |
toreBound |
an optional numeric value that specify the length of the tore. |
Let \mathbf{x}_k,\mathbf{x}_l
be the spatial coordinates of the unit k,l \in U
. The classical euclidean distance is given by
d^2(k,l) = (\mathbf{x}_k - \mathbf{x}_l)^\top (\mathbf{x}_k - \mathbf{x}_l).
When the points are distributed on a N_1 \times N_2
regular grid of R^2
.
It is possible to consider the units like they were placed on a tore. It can be illustrated by Pac-Man passing through the wall to get away from ghosts. Specifically,
we could consider two units on the same column (resp. row) that are on the opposite have a small distance,
d^2_T(k,l) = min( (x_{k_1} - x_{l_1})^2,
(x_{k_1} + N_1 - x_{l_1})^2,
(x_{k_1} - N_1 - x_{l_1})^2) +
min( (x_{k_2} - x_{l_2})^2,
(x_{k_2} + N_2 - x_{l_2})^2,
(x_{k_2} - N_2 - x_{l_2})^2).
The option toreBound
specify the length of the tore in the case of N_1 = N_2 = N
.
It is omitted if the tore
option is equal to FALSE
.
a vector of length N
that contains the distances from the unit k
to all other units.
dist
.
N <- 5
x <- seq(1,N,1)
X <- as.matrix(expand.grid(x,x))
distUnitk(X,k = 2,tore = TRUE,toreBound = 5)
distUnitk(X,k = 2,tore = FALSE,toreBound = -1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.