#include <math.h>
#include <gsl/gsl_histogram.h>

/* Computes the earth mover's distance, aka 1-Wasserstein
 * metric, of two histograms. It gives the minimum cost
 * (weight * distance) associated to shifting around the
 * weights of the bins to turn one histogram into the other.
 *
 * For a 1D normalised histogram the distance can be proven
 * to be equal to the L¹ distance of the CDF. If the bins are
 * equally sized this can be futher simplified to give a simple
 * O(n) solution.
 */
double emd_between(gsl_histogram *a, gsl_histogram *b);


/* Normalise a histogram: ie rescaling the bin
 * weights to sum to 1
 */
void normalise(gsl_histogram *h);