Find Geodesic Neighbors Within a Point Cloud
Usage
geodesic.knn(
X,
k,
k.graph = 5,
graph = NULL,
small.component = c("error", "truncate")
)Arguments
- X
Finite numeric matrix of observations, one per row.
- k
Number of other vertices to return, an integer in
1:(nrow(X)-1). Self is excluded by vertex index; coincident other observations remain valid zero-distance neighbors. Ties are ordered by vertex index.- k.graph
Number of other neighbors used to construct the auxiliary symmetric kNN graph. Components are not automatically connected. Ignored when
graphis supplied.- graph
Optional
dgraphcontaining stored edge lengths, in X row order.- small.component
Error if fewer than
kother vertices are reachable ("error", default), or return the available neighbors ("truncate").
Value
A list with nn.index and nn.dist matrices with k columns and
effective.k, the number returned per row. Under explicit truncation,
absent indices and distances are NA; unreachable vertices are never
reported as neighbors.
Examples
X <- cbind(0:3, 0)
geodesic.knn(X, k = 1, k.graph = 1) # one other vertex per row
#> $nn.index
#> [,1]
#> [1,] 2
#> [2,] 1
#> [3,] 2
#> [4,] 3
#>
#> $nn.dist
#> [,1]
#> [1,] 1
#> [2,] 1
#> [3,] 1
#> [4,] 1
#>
#> $effective.k
#> [1] 1 1 1 1
#>