WANN-class: WANN objects encapsulating points/kd trees allowing repeated...

WANN-classR Documentation

WANN objects encapsulating points/kd trees allowing repeated searches

Description

Methods for WANN objects include

  • build_tree

  • delete_tree

  • getPoints

  • querySelf

Details

WANN objects will primarily be useful if you make repeated queries. You can also delay building the k-d tree if you are not sure if the object in question will be searched; the tree will automatically be built when it is queried. You can also explicitly control when the tree is built or deleted (for memory management). The tree is wrapped in an R reference class (R5) object which imposes a significant performance penalty for building small trees (< ~ 1000 points). Summarising, WANN objects provide experimental functionality to:

  • keep ANN points in memory to avoid repeated copying

  • keep the ANN k-d tree in memory to avoid repeated building

  • separate building the k-d tree from allocating the points

  • permit very fast self queries

  • permit queries of the points from one ANN tree against a second tree

Examples

p1=kcpoints[[1]]
w1=WANN(p1)

# 2 neighbours since the first neighbour will be a self match of each point
k <- 2
# Find the exact nearest neighbors
epsilon <- 0.0

w1sq=w1$querySelf(k, epsilon)
w1sq$nn.dists[,2]
w1$query(p1, k, epsilon)

p2=kcpoints[[2]]
w1$query(p2, k, epsilon)
# equivalent to
nn2(p1, p2, k)

# Fixed radius search
w1$query_FR(p1, k, radius = 1, epsilon)
# equivalent to
nn2(p1, p2, k, radius = 1)

# Explicitly build or delete k-d tree
w1$build_tree()
w1$delete_tree()

jefferis/RANN2 documentation built on Feb. 27, 2024, 4:42 p.m.