distUnitk: Squared Euclidean distances of the unit k.

View source: R/RcppExports.R

distUnitkR Documentation

Squared Euclidean distances of the unit k.

Description

Calculate the squared Euclidean distance from unit k to the other units.

Usage

distUnitk(X, k, tore, toreBound)

Arguments

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.

Details

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.

Value

a vector of length N that contains the distances from the unit k to all other units.

Author(s)

Raphaël Jauslin raphael.jauslin@unine.ch

See Also

dist.

Examples

  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)

StratifiedSampling documentation built on Oct. 26, 2022, 5:09 p.m.