我有2个带有8个浮点变量的向量。
每个向量都有不同的值。
比较这两个向量并返回相似性的总体百分比的有效方法是什么? (例如~80%)
float[] emotion1 = {0.050, 0.200, 0.025, 0.225, 0.075, 0.175, 0.0125, 0.2375}; //sum = 1.00
float[] emotion2 = {0.10, 0.150, 0.175, 0.075, 0.225, 0.025, 0.0125, 0.2375}; //sum = 1.00
答案 0 :(得分:0)
double[] emotion1 = {0.05, 0.2, 0.025, 0.225, 0.075, 0.175, 0.0125, 0.2375}; // sum = 1,0
double[] emotion2 = {0.1, 0.15, 0.125, 0.125, 0.175, 0.075, 0.1125, 0.1375};
Set<Double> floatSet = new HashSet<>();
for (double value : emotion1) {
floatSet.add(value);
}
for (double value : emotion2) {
floatSet.add(value);
}
int arraysLength = emotion1.length + emotion2.length;
int totalElementsNumber = floatSet.size();
double percentage = 100 - ((totalElementsNumber * 100) / arraysLength);
System.out.println("similarity: " + percentage + " %");