Learn R Programming

HyperG (version 1.0.0)

knn_hypergraph: K-Nearest Neighbor Hypergraph.

Description

A hypergraph is constructed from data in which each hyper-edge corresponds to a vertex and its k-nearest neighbors.

Usage

knn_hypergraph(x, k = 1, method = "Euclidean", reduce=FALSE,
   as.graph=FALSE)

Arguments

x

a matrix of data points.

k

the number of neighbors. May be a vector.

method

distance type passed to dist.

reduce

logical. Whether to remove redundant hyper-edges.

as.graph

logical. Whether to return a graph instead of a hypergraph.

Value

a hypergraph or graph.

Details

Each vertex is in one-to-one correspondence with the points (rows) of x. For each vertex, the k-closest vertices and itself form a hyper-edge.

If reduce=TRUE reduntant hyper-edges (those contained in other hyper-edges) are removed. If as.graph=TRUE, reduce is ignored and the incidence matrix is treated as an adjacency matrix, returning a (directed) igraph graph.

See Also

epsilon_hypergraph, dist.

Examples

Run this code
# NOT RUN {
   set.seed(565)
	x <- matrix(rnorm(100),ncol=2)
	k <- knn_hypergraph(x,k=4)
	
# }
# NOT RUN {
	   plot(k)
		plot(k,layout=x)
	
# }

Run the code above in your browser using DataLab