2つの配列認識アルゴリズムtanimoto
日常のプログラムでは2つの配列の認識度を比較する可能性がありますが、ここではいくつかの資料を見てlireプログラムに基づいて抽出した2つの配列の認識度を計算するアルゴリズムtanimotoです.
2つの集合間の類似度を測定する方法.
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
ユーザーがユーザー間の類似度を計算できる
ネット上ではこれらの配列の認識度を計算できると言われていますが、私は試したことがありません(
tanimotoとオーステナイト距離、Cosineとピルソン係数)
2つの集合間の類似度を測定する方法.
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とピルソン係数)