ml-distance

Crates.ioml-distance
lib.rsml-distance
version1.0.1
sourcesrc
created_at2024-04-20 00:17:44.435824
updated_at2024-04-21 16:26:46.925474
descriptionDistance-based methods for vector comparison and analysis. (Porting of the JS/TS pkg `ml-distance` to Rust)
homepagehttps://github.com/PierreLouisLetoquart/ml-distances/
repositoryhttps://github.com/PierreLouisLetoquart/ml-distances/
max_upload_size
id1214248
size30,874
Pierre-Louis (PierreLouisLetoquart)

documentation

README

ML Distance

This Rust crate is based on the paper Comprehensive Survey on Distance/Similarity Measures between Probability Density Functions and implemented to port the ml-distance pkg from js/ts to rust.

Usage

Run the following Cargo command in your project directory:

cargo add ml-distance

Or add the following line to your Cargo.toml:

ml-distance = "^1.0.0"

And then use it in your code like this:

Note: The distances and similarities are implemented for all types that implement the Into\<f64\> trait. (e.g. f64, i32, u32, i64, ...)

use ml_distance::distance;

let p: [f64; 3] = [0.000, 1.700, 2.350];
let q: [f64; 3] = [0.300, 1.700, 1.001];

let dist = distance::euclidean(&p, &q);
assert_eq!(dist, 1.3819554985599212);

Or for similarityies

use ml_distance::similarity;

let p = vec![0, 1, 2, 1, 1, 3];
let q = vec![0, 1, 1, 5, 9, 3];

let dist = similarity::cosine(&p, &q);
assert_eq!(dist, 0.6009252125773316);

Distances Implemented

Name Formula Link Status
euclidean Link
manhattan Link
minkowski Link
chebyshev Link
sorensen Link
gower Link
soergel Link
kulczynski Link
canberra Link
lorentzian Link
intersection Link
waveHedges Link
czekanowski Link
motyka Link
ruzicka Link
tanimoto Link 🔜
innerProduct Link
harmonicMean Link
kumarHassebrook Link
jaccard Link
dice Link
bhattacharyya Link
hellinger Link
matusita Link
squaredChord Link
squaredEuclidean Link
pearson Link
neyman Link
squared Link
probabilisticSymmetric Link
divergence Link
clark Link
additiveSymmetric Link
kullbackLeibler Link
jeffreys Link
kdivergence Link
topsoe Link
jensenShannon Link
jensenDifference Link
taneja Link
kumarJohnson Link
avg Link

Similarities Implemented

Name Formula Link Status
cosine Link
dice Link
fidelity Link
kulczynski Link
czekanowski Link
intersection Link
jaccard Link
motyka Link
squaredChord Link
Commit count: 26

cargo fmt