@Test public void test01() { double[] v1 = new double[] {2, 4, 6, 3}; double[] v2 = new double[] {3, 5, 1, 4}; Asserts.assertEqualLength(v1, v2); Asserts.assertGreaterThanZero(v1); Asserts.assertGreaterThanZero(v2); double res = Chi.distance(v1, v2); Asserts.assertEquals(res, 0.7485665069492319); }
public static double distance(double[] v1, double[] v2) { double mean_v1 = CommonStats.mean(v1); double mean_v2 = CommonStats.mean(v2); double cons = (mean_v1 + mean_v2) / (((double)v1.length) * (mean_v1 * mean_v2) * (mean_v1 * mean_v2)); double res = 0; int i = 0; while (i < v1.length) { double t = (v1[i] * mean_v2) - (v2[i] * mean_v1); t = t * t; t = (t / (v1[i] + v2[i])); res += (cons * t); i++; } return Math.sqrt(res); }
Chi { public static double distance(double[] v1, double[] v2) { double mean_v1 = CommonStats.mean(v1); double mean_v2 = CommonStats.mean(v2); double cons = (mean_v1 + mean_v2) / (((double)v1.length) * (mean_v1 * mean_v2) * (mean_v1 * mean_v2)); double res = 0; int i = 0; while (i < v1.length) { double t = (v1[i] * mean_v2) - (v2[i] * mean_v1); t = t * t; t = (t / (v1[i] + v2[i])); res += (cons * t); i++; } return Math.sqrt(res); } }
Chi { public static double distance(double[] v1, double[] v2) { double mean_v1 = CommonStats.mean(v1); double mean_v2 = CommonStats.mean(v2); double cons = (mean_v1 + mean_v2) / (((double)v1.length) * (mean_v1 * mean_v2) * (mean_v1 * mean_v2)); double res = 0; int i = 0; while (i < v1.length) { double t = (v1[i] * mean_v2) - (v2[i] * mean_v1); t = t * t; t = (t / (v1[i] + v2[i])); res += (cons * t); i++; } return Math.sqrt(res); }  }
Chi { public static double distance(double[] v1, double[] v2) { double mean_v1 = CommonStats.mean(v1); double mean_v2 = CommonStats.mean(v2); double cons = (mean_v1 + mean_v2) / (((double)v1.length) * (mean_v1 * mean_v2) * (mean_v1 * mean_v2)); double res = 0; int i = 0; while (i < v1.length) { double t = (v1[i] * mean_v2) - (v2[i] * mean_v1); t = t * t; t = (t / (v1[i] + v2[i])); res += (cons * t); i++; } return Math.sqrt(res); }  static double distance(double[] v1, double[] v2); }
Chi { public static double distance(double[] v1, double[] v2) { double mean_v1 = CommonStats.mean(v1); double mean_v2 = CommonStats.mean(v2); double cons = (mean_v1 + mean_v2) / (((double)v1.length) * (mean_v1 * mean_v2) * (mean_v1 * mean_v2)); double res = 0; int i = 0; while (i < v1.length) { double t = (v1[i] * mean_v2) - (v2[i] * mean_v1); t = t * t; t = (t / (v1[i] + v2[i])); res += (cons * t); i++; } return Math.sqrt(res); }  static double distance(double[] v1, double[] v2);  }