在日常程序中可能会出现对比两个数组相识程度,我这里是看到一些资料后根据lire程序提取的计算两个数组相识度的算法 tanimoto
度量两个集合之间的相似程度的方法。
A=[1,2,3,4]
B=[1,2,5]
C = A & B = [1,2]
T = Nc / ( Na + Nb -Nc) = len(c) / ( len(a) + len(b) - len(c)) = 2 / (4+3-2) = 0.4
可以用户计算用户之间的相似程度
public void getDistance(int[] t, int[] s) {
double Result = 0;
if ((t.length == s.length)) {
double Temp1 = 0;
double Temp2 = 0;
double TempCount1 = 0, TempCount2 = 0, TempCount3 = 0;
for (int i = 0; i < t.length; i++) {
Temp1 += t[i];
Temp2 += s[i];
}
if (Temp1 == 0 || Temp2 == 0)
Result = 100;
if (Temp1 == 0 && Temp2 == 0)
Result = 0;
if (Temp1 > 0 && Temp2 > 0) {
for (int i = 0; i < tImg.length; i++) {
TempCount1 += (t[i] / Temp1) * (s[i] / Temp2);
TempCount2 += (s[i] / Temp2) * (s[i] / Temp2);
TempCount3 += (t[i] / Temp1) * (t[i] / Temp1);
}
Result = (100 - 100 * (TempCount1 / (TempCount2 + TempCount3 - TempCount1))); // Tanimoto
}
}
}
网上有人说这几个都可以计算数组的相识度,但是我没有尝试过( tanimoto和欧氏距离、Cosine和皮尔逊系数 )