@Test public void test2() { double[] v1 = new double[] { 8, -32, 7, 0, -45 }; double[] v2 = new double[] { 97, -78, 41, -4, -78 }; Asserts.assertEqualLength(v1, v2); double res = Angular.distance(v1, v2); Asserts.assertEquals(res, 0.60231338113778); }
public static double distance(double[] v1,double[] v2){ Asserts.assertEqualLength(v1, v2); Asserts.assertHasAllZeros(v1); Asserts.assertHasAllZeros(v2); if(v1==v2){ return 0; } double res; res=CommonStats.dotProduct(v1, v2)/(CommonStats.norm(v1)*CommonStats.norm(v2)); Asserts.assertBetween1andMinus1(res); return Math.acos(res); }
Angular { public static double distance(double[] v1,double[] v2){ Asserts.assertEqualLength(v1, v2); Asserts.assertHasAllZeros(v1); Asserts.assertHasAllZeros(v2); if(v1==v2){ return 0; } double res; res=CommonStats.dotProduct(v1, v2)/(CommonStats.norm(v1)*CommonStats.norm(v2)); Asserts.assertBetween1andMinus1(res); return Math.acos(res); } }
Angular { public static double distance(double[] v1,double[] v2){ Asserts.assertEqualLength(v1, v2); Asserts.assertHasAllZeros(v1); Asserts.assertHasAllZeros(v2); if(v1==v2){ return 0; } double res; res=CommonStats.dotProduct(v1, v2)/(CommonStats.norm(v1)*CommonStats.norm(v2)); Asserts.assertBetween1andMinus1(res); return Math.acos(res); }  }
Angular { public static double distance(double[] v1,double[] v2){ Asserts.assertEqualLength(v1, v2); Asserts.assertHasAllZeros(v1); Asserts.assertHasAllZeros(v2); if(v1==v2){ return 0; } double res; res=CommonStats.dotProduct(v1, v2)/(CommonStats.norm(v1)*CommonStats.norm(v2)); Asserts.assertBetween1andMinus1(res); return Math.acos(res); }  static double distance(double[] v1,double[] v2); }
Angular { public static double distance(double[] v1,double[] v2){ Asserts.assertEqualLength(v1, v2); Asserts.assertHasAllZeros(v1); Asserts.assertHasAllZeros(v2); if(v1==v2){ return 0; } double res; res=CommonStats.dotProduct(v1, v2)/(CommonStats.norm(v1)*CommonStats.norm(v2)); Asserts.assertBetween1andMinus1(res); return Math.acos(res); }  static double distance(double[] v1,double[] v2);  }