[−][src]Module smartcore::algorithm::neighbour::cover_tree
tree data structure for fast nearest neighbor search
Cover Tree
The Cover Tree data structure is specifically designed to facilitate the speed-up of a nearest neighbor search, see KNN algorithms.
use smartcore::algorithm::neighbour::cover_tree::*; use smartcore::math::distance::Distance; #[derive(Clone)] struct SimpleDistance {} // Our distance function impl Distance<i32, f64> for SimpleDistance { fn distance(&self, a: &i32, b: &i32) -> f64 { // simple simmetrical scalar distance (a - b).abs() as f64 } } let data = vec![1, 2, 3, 4, 5, 6, 7, 8, 9]; // data points let mut tree = CoverTree::new(data, SimpleDistance {}).unwrap(); tree.find(&5, 3); // find 3 knn points from 5
Structs
CoverTree | Implements Cover Tree algorithm |