@Test public void test2() { double[] v1 = new double[]{17,8,11}; double[] v2 = new double[]{12,7,8}; Asserts.assertEqualLength(v1, v2); double res = PearsonCorrelation.distance(v1, v2); Asserts.assertEquals(res, 0.010256681389212985); }
public static double distance(double v1[],double v2[]){ double sum=0; double meanV1=CommonStats.mean(v1); double meanV2=CommonStats.mean(v2); for(int i=0;i<v1.length;i++){ sum+=(v1[i]-meanV1)*(v2[i]-meanV2); } return 1-(sum/Math.sqrt(sumDenom(v1,meanV1)*sumDenom(v2,meanV2))); }
PearsonCorrelation { public static double distance(double v1[],double v2[]){ double sum=0; double meanV1=CommonStats.mean(v1); double meanV2=CommonStats.mean(v2); for(int i=0;i<v1.length;i++){ sum+=(v1[i]-meanV1)*(v2[i]-meanV2); } return 1-(sum/Math.sqrt(sumDenom(v1,meanV1)*sumDenom(v2,meanV2))); } }
PearsonCorrelation { public static double distance(double v1[],double v2[]){ double sum=0; double meanV1=CommonStats.mean(v1); double meanV2=CommonStats.mean(v2); for(int i=0;i<v1.length;i++){ sum+=(v1[i]-meanV1)*(v2[i]-meanV2); } return 1-(sum/Math.sqrt(sumDenom(v1,meanV1)*sumDenom(v2,meanV2))); }  }
PearsonCorrelation { public static double distance(double v1[],double v2[]){ double sum=0; double meanV1=CommonStats.mean(v1); double meanV2=CommonStats.mean(v2); for(int i=0;i<v1.length;i++){ sum+=(v1[i]-meanV1)*(v2[i]-meanV2); } return 1-(sum/Math.sqrt(sumDenom(v1,meanV1)*sumDenom(v2,meanV2))); }  static double sumDenom(double v[],double mean); static double distance(double v1[],double v2[]); }
PearsonCorrelation { public static double distance(double v1[],double v2[]){ double sum=0; double meanV1=CommonStats.mean(v1); double meanV2=CommonStats.mean(v2); for(int i=0;i<v1.length;i++){ sum+=(v1[i]-meanV1)*(v2[i]-meanV2); } return 1-(sum/Math.sqrt(sumDenom(v1,meanV1)*sumDenom(v2,meanV2))); }  static double sumDenom(double v[],double mean); static double distance(double v1[],double v2[]);  }