How do you measure similarity between 2 series of

2019-03-22 02:24发布

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?

标签: similarity
3条回答
放荡不羁爱自由
2楼-- · 2019-03-22 03:02

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

查看更多
手持菜刀,她持情操
3楼-- · 2019-03-22 03:03

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.

查看更多
地球回转人心会变
4楼-- · 2019-03-22 03:04

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
查看更多
登录 后发表回答