Ellenberg { public static double distance(double[] v1,double[] v2){ Asserts.assertEqualLength(v1, v2); Asserts.assertHasAllZeros(v1); Asserts.assertHasAllZeros(v2); Asserts.assertPositiveValues(v1); Asserts.assertPositiveValues(v2); double sumNum = 0; double sumDenom = 0; for(int i=0;i<v1.length;i++){ sumNum += (v1[i] + v2[i])*CommonStats.zeroProduct(v1[i],v2[i],false); sumDenom += (v1[i] + v2[i])*(1+CommonStats.zeroProduct(v1[i],v2[i],true)); } return sumNum/sumDenom; }  static double distance(double[] v1,double[] v2);  }
@Test public void test1(){ double[] v1 = new double[]{8,3,7}; double[] v2 = new double[]{9,8,4}; double res = Ellenberg.distance(v1, v2); Asserts.assertEquals(res, 1); }
@Test public void test2(){ double[] v1 = new double[]{8,32,7,0,45}; double[] v2 = new double[]{97,0,41,4,78}; double res = Ellenberg.distance(v1, v2); Asserts.assertEquals(res, 0.793103448); }
@Test public void test3(){ double[] v1 = new double[]{248.124,321.574,0,0.001,0}; double[] v2 = new double[]{0,78.658,417.0004,4.02,0}; double res = Ellenberg.distance(v1, v2); Asserts.assertEquals(res, 0.233065771); }