Skip to contents

Find Geodesic Neighbors from Grid Queries to Observations

Usage

geodesic.knnx(
  X,
  X.grid,
  k,
  k.graph = 5,
  small.component = c("error", "truncate")
)

Arguments

X

Finite numeric matrix of data observations.

X.grid

Finite numeric matrix of grid query points, with the same number of coordinate columns as X.

k

Number of data observations returned per grid query, in 1:nrow(X). Grid and data rows have distinct identities: a coincident observation is a valid zero-distance neighbor. Ties are ordered by data row index.

k.graph

Number of grid vertices attached to each observation, in 1:nrow(X.grid). Grid vertices connect to up to twice the coordinate dimension other grid vertices. No components are automatically bridged.

small.component

Error on insufficient reachable observations, or explicitly "truncate" and pad absent indices and distances with NA.

Value

A list with combined coordinates V (grid rows first), edge pairs E in V row indices, nn.index (indices into X), nn.dist and effective.k (the number returned per grid query).

See also

Examples

X.grid <- as.matrix(expand.grid(x = 0:2, y = 0:2))
X <- rbind(c(0, 0), c(1.2, 0.8), c(1.8, 1.7))
geodesic.knnx(X, X.grid, k = 2)
#> $V
#>         x   y
#>  [1,] 0.0 0.0
#>  [2,] 1.0 0.0
#>  [3,] 2.0 0.0
#>  [4,] 0.0 1.0
#>  [5,] 1.0 1.0
#>  [6,] 2.0 1.0
#>  [7,] 0.0 2.0
#>  [8,] 1.0 2.0
#>  [9,] 2.0 2.0
#> [10,] 0.0 0.0
#> [11,] 1.2 0.8
#> [12,] 1.8 1.7
#> 
#> $E
#>       [,1] [,2]
#>  [1,]    1    4
#>  [2,]    2    3
#>  [3,]    3    2
#>  [4,]    4    7
#>  [5,]    5    6
#>  [6,]    6    9
#>  [7,]    7    8
#>  [8,]    8    5
#>  [9,]    9    6
#> [10,]    1    2
#> [11,]    2    5
#> [12,]    3    6
#> [13,]    4    1
#> [14,]    5    2
#> [15,]    6    5
#> [16,]    7    4
#> [17,]    8    9
#> [18,]    9    8
#> [19,]    1    5
#> [20,]    2    1
#> [21,]    3    5
#> [22,]    4    5
#> [23,]    5    8
#> [24,]    6    3
#> [25,]    7    5
#> [26,]    8    7
#> [27,]    9    5
#> [28,]    1    7
#> [29,]    2    6
#> [30,]    3    9
#> [31,]    4    8
#> [32,]    5    4
#> [33,]    6    2
#> [34,]    7    1
#> [35,]    8    6
#> [36,]    9    3
#> [37,]   10    1
#> [38,]   11    5
#> [39,]   12    9
#> [40,]   10    4
#> [41,]   11    2
#> [42,]   12    6
#> [43,]   10    2
#> [44,]   11    6
#> [45,]   12    8
#> [46,]   10    5
#> [47,]   11    3
#> [48,]   12    5
#> [49,]   10    7
#> [50,]   11    4
#> [51,]   12    3
#> 
#> $nn.index
#>       [,1] [,2]
#>  [1,]    1    2
#>  [2,]    2    1
#>  [3,]    2    3
#>  [4,]    1    2
#>  [5,]    2    3
#>  [6,]    3    2
#>  [7,]    2    3
#>  [8,]    3    2
#>  [9,]    3    2
#> 
#> $nn.dist
#>            [,1]      [,2]
#>  [1,] 0.0000000 1.6970563
#>  [2,] 0.8246211 1.0000000
#>  [3,] 1.1313708 1.7117243
#>  [4,] 1.0000000 1.2165525
#>  [5,] 0.2828427 1.0630146
#>  [6,] 0.7280110 0.8246211
#>  [7,] 1.6970563 1.8544004
#>  [8,] 0.8544004 1.2828427
#>  [9,] 0.3605551 1.6970563
#> 
#> $effective.k
#> [1] 2 2 2 2 2 2 2 2 2
#>