neighbor_overlap | R Documentation |
Calculates the mean average number of neighbors in common between the two graphs. The per-item overlap can also be returned. This function can be useful as a measure of accuracy of approximation algorithms, if the exact nearest neighbors are known, or as a measure of diversity of two different approximate graphs.
neighbor_overlap(idx1, idx2, k = NULL, ret_vec = FALSE)
idx1 |
Indices of a nearest neighbor graph, i.e. a matrix of nearest
neighbor indices. Can also be a list containing an |
idx2 |
Indices of a nearest neighbor graph, i.e. a matrix of nearest
neighbor indices. Can also be a list containing an |
k |
Number of neighbors to consider. If |
ret_vec |
If |
The graph format is the same as that returned by e.g. nnd_knn()
and should
be of dimensions n by k, where n is the number of points and k is the number
of neighbors. If you pass a neighbor graph directly, the index matrix will be
extracted if present. If the two graphs have different numbers of neighbors,
then the smaller number of neighbors is used.
The mean overlap between idx1
and idx2
. If ret_vec = TRUE
,
then a list containing the mean overlap and the overlap of each item in
is returned with names mean
and overlaps
, respectively.
set.seed(1337)
# Generate two random neighbor graphs for iris
iris_rnn1 <- random_knn(iris, k = 15)
iris_rnn2 <- random_knn(iris, k = 15)
# Overlap between the two graphs
mean_overlap <- neighbor_overlap(iris_rnn1, iris_rnn2)
# Also get a vector of per-item overlap
overlap_res <- neighbor_overlap(iris_rnn1, iris_rnn2, ret_vec = TRUE)
summary(overlap_res$overlaps)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.