Crates.io | ml-distance |
lib.rs | ml-distance |
version | 1.0.1 |
source | src |
created_at | 2024-04-20 00:17:44.435824 |
updated_at | 2024-04-21 16:26:46.925474 |
description | Distance-based methods for vector comparison and analysis. (Porting of the JS/TS pkg `ml-distance` to Rust) |
homepage | https://github.com/PierreLouisLetoquart/ml-distances/ |
repository | https://github.com/PierreLouisLetoquart/ml-distances/ |
max_upload_size | |
id | 1214248 |
size | 30,874 |
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.
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);
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 | ✅ |
Name | Formula Link | Status |
---|---|---|
cosine | Link | ✅ |
dice | Link | ✅ |
fidelity | Link | ✅ |
kulczynski | Link | ✅ |
czekanowski | Link | ✅ |
intersection | Link | ✅ |
jaccard | Link | ✅ |
motyka | Link | ✅ |
squaredChord | Link | ✅ |