Trait acap::knn::NearestNeighbors [−][src]
pub trait NearestNeighbors<K: Proximity<V>, V = K> {
fn search<'k, 'v, N>(&'v self, neighborhood: N) -> N
where
K: 'k,
V: 'v,
N: Neighborhood<&'k K, &'v V>;
fn nearest(&self, target: &K) -> Option<Neighbor<&V, K::Distance>> { ... }
fn nearest_within<D>(
&self,
target: &K,
threshold: D
) -> Option<Neighbor<&V, K::Distance>>
where
D: TryInto<K::Distance>,
{ ... }
fn k_nearest(&self, target: &K, k: usize) -> Vec<Neighbor<&V, K::Distance>> { ... }
fn k_nearest_within<D>(
&self,
target: &K,
k: usize,
threshold: D
) -> Vec<Neighbor<&V, K::Distance>>
where
D: TryInto<K::Distance>,
{ ... }
fn merge_k_nearest<'v>(
&'v self,
target: &K,
k: usize,
neighbors: &mut Vec<Neighbor<&'v V, K::Distance>>
) { ... }
fn merge_k_nearest_within<'v, D>(
&'v self,
target: &K,
k: usize,
threshold: D,
neighbors: &mut Vec<Neighbor<&'v V, K::Distance>>
)
where
D: TryInto<K::Distance>,
{ ... }
}
Expand description
A nearest neighbor search index.
Type parameters:
K
: The type of the search target (the “key” type)V
: The type of the returned neighbors (the “value” type)
In general, exact nearest neighbor searches may be prohibitively expensive due to the curse of dimensionality. Therefore, NearestNeighbor implementations are allowed to give approximate results. The marker trait ExactNeighbors denotes implementations which are guaranteed to give exact results.
Required methods
fn search<'k, 'v, N>(&'v self, neighborhood: N) -> N where
K: 'k,
V: 'v,
N: Neighborhood<&'k K, &'v V>,
fn search<'k, 'v, N>(&'v self, neighborhood: N) -> N where
K: 'k,
V: 'v,
N: Neighborhood<&'k K, &'v V>,
Search for nearest neighbors and add them to a neighborhood.
Provided methods
Returns the nearest neighbor to target
(or None
if this index is empty).
Returns the nearest neighbor to target
within the distance threshold
, if one exists.
Returns the up to k
nearest neighbors to target
.
The result will be sorted from nearest to farthest.
Returns the up to k
nearest neighbors to target
within the distance threshold
.
The result will be sorted from nearest to farthest.
Merges up to k
nearest neighbors into an existing sorted vector.