3 releases
0.1.3 | May 22, 2020 |
---|---|
0.1.2 |
|
0.1.1 | May 22, 2020 |
0.1.0 | May 22, 2020 |
#2121 in Algorithms
10KB
179 lines
Pointcloud
A library to find nearest neighbours in rust.
Usage
Add this to your Cargo.toml
[dependencies]
knn = "0.1.3"
and use like this
extern crate knn;
use knn::PointCloud;
fn main() {
let manhattan = |p: &[f64;2], q: &[f64;2]| {(q[0] - p[0]).abs() + (q[1] - p[1]).abs()};
let mut pc = PointCloud::new(manhattan);
let coords = vec![[1.0, 1.0], [2.0, 2.0], [10.0, 5.0], [11.0, 15.0]];
for i in 0..coords.len() {
pc.add_point(&coords[i]);
}
let d = pc.get_nearest_n(&[2.1, 2.1], 2);
println!("{:?}", d)
// output :
// [(0.20000000000000018, [2.0, 2.0]), (2.2, [1.0, 1.0])]
}
For updated and detailed docs refer here
lib.rs
:
KNN
knn
provides for fast method of finding exact k nearest neighbours
for higher dimensional data. Also supports custom distance function.