求两条曲线相似度的算法【高分求】
两条曲线的相似程度,能得出数值结果,最好是归一化的,0.几或者?%
[解决办法]
public class CosineCompare {
/*余弦相似度算法*/
public static void main(String[] args) throws Exception {
double[] curve_1 = { 1, 4, 5, 7, 8, 9, 6, 5, 3, 2, 1 }; //坐标
double[] curve_2 = { 1, 1.2, 8, 20, 9, 8, 6, 5, 3, 2, 1 }; //坐标
double x = 0, y = 0, z = 0;
for (int i = 0; i < curve_1.length; i++) {
x += curve_1[i] * curve_1[i];
y += curve_2[i] * curve_2[i];
z += curve_1[i] * curve_2[i];
}
x = Math.sqrt(x);
y = Math.sqrt(y);
System.out.println(z / (x * y));
}
}