nng: Nearest Neighbor Graphs

View source: R/nng.R

nngR Documentation

Nearest Neighbor Graphs

Description

nearest neighbor, k-nearest neighbor, and mutual k-nearest neighbor (di)graphs.

Usage

nng(x = NULL, dx = NULL, k = 1, mutual = FALSE, method = NULL, 
    use.fnn = FALSE, algorithm = 'cover_tree')

Arguments

x

a data matrix. Either x or dx is required

dx

interpoint distance matrix

k

number of neighbors

mutual

logical. if true the neighbors must be mutual. See details.

method

the method used for the distance. See dist

use.fnn

logical. If TRUE, get.knn from the FNN package is used to obtain the neighbors.

algorithm

see get.knn.

Details

a k-nearest neighbor graph is a digraph where each vertex is associated with an observation and there is a directed edge between the vertex and it's k nearest neighbors. A mutual k-nearest neighbor graph is a graph where there is an edge between x and y if x is one of the k nearest neighbors of y AND y is one of the k nearest neighbors of x.

Value

an object of class igraph with the extra attributes

layout

the x vectors.

k,mutual,p

arguments given to nn.

Author(s)

David J. Marchette david.marchette@navy.mil

References

D.J. Marchette, Random Graphs for Statistical Pattern Recognition, John Wiley & Sons, 2004.

See Also

dist get.knn

Examples


x <- matrix(runif(100),ncol=2)

G1 <- nng(x,k=1)
## Not run: 
par(mfrow=c(2,2))
plot(G1)

## End(Not run)

G2 <- nng(x,k=2)
## Not run: 
plot(G2)

## End(Not run)

G5 <- nng(x,k=5)
## Not run: 
plot(G5)

## End(Not run)

G5m <- nng(x,k=5,mutual=TRUE)
## Not run: 
plot(G5m)
par(mfrow=c(1,1))

## End(Not run)


cccd documentation built on April 8, 2022, 5:08 p.m.

Related to nng in cccd...