frNN: Find the Fixed Radius Nearest Neighbors

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/frNN.R

Description

This function uses a kd-tree to find the fixed radius nearest neighbors (including distances) fast.

Usage

1
2
frNN(x, eps, sort = TRUE, search = "kdtree", bucketSize = 10,
  splitRule = "suggest", approx = 0)

Arguments

x

a data matrix, a dist object or a frNN object.

eps

neighbors radius.

search

nearest neighbor search strategy (one of "kdtree" or "linear", "dist").

sort

sort the neighbors by distance? This is expensive and can be done later using sort().

bucketSize

max size of the kd-tree leafs.

splitRule

rule to split the kd-tree. One of "STD", "MIDPT", "FAIR", "SL_MIDPT", "SL_FAIR" or "SUGGEST" (SL stands for sliding). "SUGGEST" uses ANNs best guess.

approx

use approximate nearest neighbors. All NN up to a distance of a factor of 1+approx eps may be used. Some actual NN may be omitted leading to spurious clusters and noise points. However, the algorithm will enjoy a significant speedup.

Details

For details on the parameters see kNN.

Note: self-matches are not returned!

To create a frNN object from scratch, you need to supply at least the elements id with a list of integer vectors with the nearest neighbor ids for each point and eps (see below).

Value

An object of class frNN (subclass of NN) containing a list with the following components:

id

a list of integer vectors. Each vector contains the ids of the fixed radius nearest neighbors.

dist

a list with distances (same structure as ids).

eps

eps used.

Author(s)

Michael Hahsler

References

David M. Mount and Sunil Arya (2010). ANN: A Library for Approximate Nearest Neighbor Searching, http://www.cs.umd.edu/~mount/ANN/.

See Also

NN and kNN for k nearest neighbor search.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
data(iris)
x <- iris[, -5]

# Find fixed radius nearest neighbors for each point
nn <- frNN(x, eps=.5)

# Number of neighbors
hist(sapply(adjacencylist(nn), length),
  xlab = "k", main="Number of Neighbors",
  sub = paste("Neighborhood size eps =", nn$eps))

# Explore neighbors of point i = 10
i <- 10
nn$id[[i]]
nn$dist[[i]]
plot(x, col = ifelse(1:nrow(iris) %in% nn$id[[i]], "red", "black"))

# get an adjacency list
head(adjacencylist(nn))

# plot the fixed radius neighbors (and then reduced to a radius of .3)
plot(nn, x)
plot(frNN(nn, .3), x)

## manually create a frNN object for dbscan (dbscan only needs ids and eps)
nn <- list(ids = list(c(2,3), c(1,3), c(1,2,3), c(3,5), c(4,5)), eps = 1)
class(nn) <- c("NN", "frNN")
nn
dbscan(nn, minPts = 2)

mhahsler/dbscan documentation built on Dec. 13, 2018, 2:52 a.m.