6 releases (2 stable)
1.0.1 | Apr 21, 2024 |
---|---|
0.2.3 | Apr 20, 2024 |
0.2.1 | Apr 20, 2024 |
0.2.0 | Apr 20, 2024 |
0.1.0 | Apr 20, 2024 |
#296 in Math
399 downloads per month
30KB
651 lines
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 | ✅ |
Dependencies
~190KB