[−][src]Module smartcore::algorithm::neighbour::linear_search
very simple algorithm that sequentially checks each element of the list until a match is found or the whole list has been searched.
Brute Force Linear Search
see KNN algorithms
use smartcore::algorithm::neighbour::linear_search::*; 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 knn = LinearKNNSearch::new(data, SimpleDistance {}).unwrap(); knn.find(&5, 3); // find 3 knn points from 5
Structs
LinearKNNSearch | Implements Linear Search algorithm, see KNN algorithms |