@Test public void test2(){ double[] v1 = new double[]{8,32,7,0,45}; double[] v2 = new double[]{97,78,41,4,78}; double res = BrayCurtis.distance(v1, v2); Asserts.assertEquals(res, 0.47179487179487); }
public static double distance(double[] v1,double[] v2){ Asserts.assertEqualLength(v1, v2); Asserts.assertGreaterOrEqualThanValue(v1, 0); Asserts.assertGreaterOrEqualThanValue(v2, 0); Asserts.assertHasAllZeros(v1); Asserts.assertHasAllZeros(v2); double sum = 0; double promV1 = 0; double promV2 = 0; for(int i=0;i<v1.length;i++){ promV1 += v1[i]; promV2 += v2[i]; sum += CommonStats.min(v1[i], v2[i]); } promV1 /= v1.length; promV2 /= v1.length; return ((2/(v1.length*(promV1+promV2)))*sum); }
BrayCurtis { public static double distance(double[] v1,double[] v2){ Asserts.assertEqualLength(v1, v2); Asserts.assertGreaterOrEqualThanValue(v1, 0); Asserts.assertGreaterOrEqualThanValue(v2, 0); Asserts.assertHasAllZeros(v1); Asserts.assertHasAllZeros(v2); double sum = 0; double promV1 = 0; double promV2 = 0; for(int i=0;i<v1.length;i++){ promV1 += v1[i]; promV2 += v2[i]; sum += CommonStats.min(v1[i], v2[i]); } promV1 /= v1.length; promV2 /= v1.length; return ((2/(v1.length*(promV1+promV2)))*sum); } }
BrayCurtis { public static double distance(double[] v1,double[] v2){ Asserts.assertEqualLength(v1, v2); Asserts.assertGreaterOrEqualThanValue(v1, 0); Asserts.assertGreaterOrEqualThanValue(v2, 0); Asserts.assertHasAllZeros(v1); Asserts.assertHasAllZeros(v2); double sum = 0; double promV1 = 0; double promV2 = 0; for(int i=0;i<v1.length;i++){ promV1 += v1[i]; promV2 += v2[i]; sum += CommonStats.min(v1[i], v2[i]); } promV1 /= v1.length; promV2 /= v1.length; return ((2/(v1.length*(promV1+promV2)))*sum); }  }
BrayCurtis { public static double distance(double[] v1,double[] v2){ Asserts.assertEqualLength(v1, v2); Asserts.assertGreaterOrEqualThanValue(v1, 0); Asserts.assertGreaterOrEqualThanValue(v2, 0); Asserts.assertHasAllZeros(v1); Asserts.assertHasAllZeros(v2); double sum = 0; double promV1 = 0; double promV2 = 0; for(int i=0;i<v1.length;i++){ promV1 += v1[i]; promV2 += v2[i]; sum += CommonStats.min(v1[i], v2[i]); } promV1 /= v1.length; promV2 /= v1.length; return ((2/(v1.length*(promV1+promV2)))*sum); }  static double distance(double[] v1,double[] v2); }
BrayCurtis { public static double distance(double[] v1,double[] v2){ Asserts.assertEqualLength(v1, v2); Asserts.assertGreaterOrEqualThanValue(v1, 0); Asserts.assertGreaterOrEqualThanValue(v2, 0); Asserts.assertHasAllZeros(v1); Asserts.assertHasAllZeros(v2); double sum = 0; double promV1 = 0; double promV2 = 0; for(int i=0;i<v1.length;i++){ promV1 += v1[i]; promV2 += v2[i]; sum += CommonStats.min(v1[i], v2[i]); } promV1 /= v1.length; promV2 /= v1.length; return ((2/(v1.length*(promV1+promV2)))*sum); }  static double distance(double[] v1,double[] v2);  }