[−][src]Crate emd
Earth Mover's Distance (EMD)
This is a wrapper around pyemd
[1] for computing the EMD (or Wasserstein)
metric.
By default, it uses Euclidean distance as a cost function, but this
can be changed by using the generic distance function distance_generic()
.
Examples
It allows computing the distance between two vectors (e.g., histograms):
extern crate emd; #[macro_use(array)] extern crate ndarray; use emd::*; use ndarray::*; let x = array![0., 1.]; let y = array![5., 3.]; assert_eq!(distance(&x.view(), &y.view()), 3.5);
Or between matrices (e.g., multivariate histograms). Note that in this case the two matrices must have the same number of columns.
extern crate emd; #[macro_use(array)] extern crate ndarray; use emd::*; use ndarray::*; let x = array![[4., 3.], [3., 6.], [2., 3.]]; let y = array![[2., 3.], [1., 3.]]; assert_eq!(distance_multi(&x.view(), &y.view()), 2.035183758487996);
Alternatively, one can compute EMD for matrices (and, by extension,
vectors) with a chosen distance as cost function by using
distance_generic()
.
References
[1] https://github.com/garydoranjr/pyemd
Functions
distance | Computes the EMD between two vectors. |
distance_generic | Computes the EMD with a desired cost function (i.e., distance). |
distance_multi | Computes the EMD between two matrices. |
euclidean_distance | Returns the Euclidean distance between two vectors of f64 values. |