问题
I'm looking for an algorithm to calculate correlation between two array of doubles.
What are the names of the algorithms and I need c++ source code if it's possible.
And by correlation I mean the similarity of data in the array...
for example:
Array1: 1 2 3 Array2: 2 3 5
should have a higher similarity measure than these 2 arrays:
Array1: 1 2 3 Array2: 9 8 15
回答1:
You need to calculate the sample Pearson product-moment correlation coefficient: "The above formula suggests a convenient single-pass algorithm for calculating sample correlations". Write a loop to calculate sum(xi), sum(yi), sum(xi^2), sum(yi^2), and sum(xi*yi). Then insert these sums into the formula.
来源:https://stackoverflow.com/questions/8370857/efficient-algorithm-to-calculate-correlation-between-two-arrays