#nearest-neighbor-search #nearest-neighbor #knn #search-index #dataset #high-dimensional #bulk-loading

srtree

Rust implementation of SR-Tree: a high-dimensional nearest neighbor search index

3 unstable releases

0.2.1 Jun 21, 2023
0.2.0 May 31, 2023
0.1.0 May 16, 2023

#1321 in Algorithms

Download history 30/week @ 2024-03-10 2/week @ 2024-03-17 45/week @ 2024-03-24 31/week @ 2024-03-31 1/week @ 2024-04-07 1/week @ 2024-04-21 5/week @ 2024-05-05 7/week @ 2024-05-19 14/week @ 2024-05-26 20/week @ 2024-06-02 4/week @ 2024-06-09 10/week @ 2024-06-16 19/week @ 2024-06-23

56 downloads per month

Apache-2.0

43KB
1K SLoC

GitHub Workflow Status crates.io

srtree

Rust implementation of SR-Tree: nearest neighbor search index for high-dimensional clustered datasets, modified to support variance-based bulk-loading. This crate applies fundamental concepts presented in the paper, and the original C++ version can be found here.

Examples

This example shows how to query nearest neighbors on Euclidean SRTree:

use srtree::SRTree;

fn main() {
    let points = vec![
        vec![0., 0.],
        vec![1., 1.],
        vec![2., 2.],
        vec![3., 3.],
        vec![4., 4.],
    ];
    let tree = SRTree::euclidean(&points).expect("Failed to build SRTree");

    let (indices, distances) = tree.query(&[8., 8.], 3);
    println!("{indices:?}"); // [4, 3, 2] (sorted by distance)
    println!("{distances:?}");
}

Other distance metrics can be defined using Metric trait:

use srtree::{SRTree, Metric};

struct Manhattan;
impl Metric<f64> for Manhattan {
    fn distance(&self, point1: &[f64], point2: &[f64]) -> f64 {
        point1.iter().zip(point2).map(|(a, b)| (a - b).abs()).sum()
    }

    fn distance_squared(&self, _: &[f64], _: &[f64]) -> f64 {
        0.
    }
}

fn main() {
    let points = vec![
        vec![0., 0.],
        vec![1., 1.],
        vec![2., 2.],
        vec![3., 3.],
        vec![4., 4.],
    ];
    let tree = SRTree::default(&points, Manhattan).expect("Failed to build SRTree");
    let (indices, distances) = tree.query(&[8., 8.], 3);
    println!("{indices:?}"); // [4, 3, 2] (sorted by distance)
    println!("{distances:?}"); // [8., 10., 12.]
}

License

Copyright 2019-2023 EINSIS, Inc.

Licensed under Apache License, Version 2.0 (the "License"); you may not use this crate except in compliance with the License.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See LICENSE for the specific language governing permissions and limitations under the License.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be licensed as above, without any additional terms or conditions.

Dependencies

~240KB