Reputation: 22561
I need to find a similarity measurement between two arrays of data. You can call similarity measurement whatever you want, difference, correlation or whatever.
For example:
1, 2, 3, 4, 5 < Series 1
2, 3, 4, 5, 6 < Series 2
Should be far more similar to each other than these 2 series:
1, 2, 3, 4, 5 < Series 1
1, 1, 5, 8, 7 < Series 2
Any suggestions?
Is there a source code available for it?
Upvotes: 3
Views: 5606
Reputation: 1
Another way to do this is to calculate mutual information, there is a toolbox for this in matlab and C http://www.cs.man.ac.uk/~pococka4/MIToolbox.html
Upvotes: 0
Reputation: 31579
If your definition of similarity is how much same elements there are you can use set intersection:
std::multiset<int> Series1 = std::multiset({ 1, 2, 3, 4, 5 });
std::multiset<int> Series2 = std::multiset({ 2, 3, 4, 5, 6 });
std::multiset<int> Intersection;
std::set_intersection(Series1.begin(), Series1.end(),
Series2.begin(), Series2.end(),
std::back_inserter(Intersection));
int similarity = Intersection.size(); // = 4
Upvotes: 0
Reputation: 28688
You can 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.
Upvotes: 3