| create.mknn.graph | R Documentation |
Creates an undirected graph where two points are connected by an edge if and only if they are present in each other's k-nearest neighbor (kNN) lists. The weight of each edge represents the distance between the connected vertices.
create.mknn.graph(
X,
k,
prune.method = c("none", "local.geodesic", "global.geodesic.ratio"),
max.path.edge.ratio.deviation.thld = 0.1,
path.edge.ratio.percentile = 0.5,
prune.tau = 1.05,
prune.local.k = NULL,
with.pruned.edge.stats = FALSE,
connect.components = FALSE,
connect.method = c("component.mst", "component.mst.ann", "global.mst"),
bridge.k = NULL,
bridge.k.max = NULL,
bridge.growth = 2
)
X |
A numeric matrix or data frame where each row represents a data point and each column represents a feature/dimension. |
k |
A positive integer specifying the number of nearest neighbors to consider. Must be at least 2. |
prune.method |
Character scalar. |
max.path.edge.ratio.deviation.thld |
Numeric scalar in |
path.edge.ratio.percentile |
Numeric scalar in |
prune.tau |
Numeric scalar greater than 1. For local geometric pruning, an edge may be removed when a retained local alternative path is at most this multiplicative factor times the direct edge length. |
prune.local.k |
Integer scalar or |
with.pruned.edge.stats |
Logical scalar. If |
connect.components |
Logical scalar. If |
connect.method |
Character scalar. |
bridge.k |
Integer scalar or |
bridge.k.max |
Integer scalar or |
bridge.growth |
Numeric scalar greater than 1. Multiplicative growth factor for ANN bridge neighborhoods. |
The mutual k-nearest neighbor graph is a symmetric graph where an edge between vertices i and j exists if and only if:
j is among the k nearest neighbors of i, AND
i is among the k nearest neighbors of j
This mutual relationship ensures that the resulting graph is undirected and typically sparser than a standard k-nearest neighbor graph.
The final graph is always stored in adj_list/weight_list.
Lifecycle diagnostic fields follow the same convention as the other graph
constructors: raw_* is before pruning and MST repair, and
pruned_* is after pruning but before MST repair.
The raw_repaired_*, pruned_repaired_*, and
repaired_pruned_* branches allow one constructor call to compare
native, prune-first, and repair-first graph geodesic geometries.
A list with class "mknn_graph" containing:
A list where element i contains the indices of vertices connected to vertex i by an edge in the final graph after optional MST component repair.
A list where element i contains the distances between
vertex i and its connected neighbors in the final graph (in the same
order as adj_list[[i]]).
The native mutual-kNN graph before pruning and before optional MST component repair.
The graph after optional local geometric pruning and before optional MST component repair. If pruning is disabled, these fields are identical to the raw graph.
The native mutual kNN graph after MST component repair.
The prune-first branch after MST component repair.
The repair-first branch after applying local geometric pruning to the repaired raw graph.
The number of vertices in the graph.
The total number of edges in the graph.
The k value used to construct the graph.
create.mknn.graphs for creating multiple graphs with different k values,
summary.mknn_graphs for summarizing graph properties
set.seed(123)
X <- matrix(rnorm(60), ncol = 2)
graph <- create.mknn.graph(X, k = 4)
graph$n_vertices
graph$n_edges
graph$adj_list[[1]]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.