EarthMoversDistance implements DistanceMeasure { public double compute(double[] a, double[] b) { double lastDistance = 0; double totalDistance = 0; for (int i = 0; i < a.length; i++) { final double currentDistance = (a[i] + lastDistance) - b[i]; totalDistance += FastMath.abs(currentDistance); lastDistance = currentDistance; } return totalDistance; }  double compute(double[] a, double[] b);  }
@Test public void testZero() { Assert.assertEquals(0, distance.compute(a, a), 0d); }
@Test public void testZero2() { final double[] zero = new double[] { 0, 0 }; Assert.assertEquals(0, distance.compute(zero, zero), 0d); }
@Test public void test() { double expected = 0.65; Assert.assertEquals(expected, distance.compute(a, b), 1e-10); Assert.assertEquals(expected, distance.compute(b, a), 1e-10); }