-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tools.java
executable file
·65 lines (61 loc) · 1.96 KB
/
Tools.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package APCluster;
import java.util.ArrayList;
import APCluster.APNode.Complete;
import APCluster.APNode.Incomplete;
public class Tools {
static class MaxMin{
double max;
double min;
public MaxMin(double max, double min) {
super();
this.max = max;
this.min = min;
}
}
static ArrayList<MaxMin> maxmin = new ArrayList<>();
public static double compareNumSimilarity(ArrayList<Double> n1,ArrayList<Double> n2){
if((n1==null||n1.isEmpty())&&(n2==null||n2.isEmpty()))return 0;
double res = 0;
int num = n1.size();
for(int i=0; i<num; i++){
if(n1.get(i).isNaN()||n2.get(i).isNaN())continue;
res += Math.pow(normalize(n1.get(i),maxmin.get(i).max,maxmin.get(i).max)-normalize(n2.get(i),maxmin.get(i).max,maxmin.get(i).max), 2);
}
return -Math.sqrt(res);
}
public static double compareClaSimilarity(ArrayList<String> n1,ArrayList<String> n2){
if((n1==null||n1.isEmpty())&&(n2==null||n2.isEmpty()))return 0;
double res = 0;
int num = n1.size();
for(int i=0; i<num; i++){
if(n1.get(i).equals("?")||n2.get(i).equals("?"))continue;
if(n1.get(i).equals(n2.get(i))){
res += 1;
}
}
return (res+1)/(num+1)-1;
}
public static double compareSimilarity(Complete n1, Complete n2){
return compareNumSimilarity(n1.numData,n2.numData)+compareClaSimilarity(n1.claData,n2.claData);
}
public static double compareSimilarity(Complete n1, Incomplete n2){
return compareNumSimilarity(n1.numData,n2.numData)+compareClaSimilarity(n1.claData,n2.claData);
}
public static double normalize(double c, double max, double min){
return (c-min+1)/(max-min+1);
}
public static void getMaxMin(APNode node){
int num = node.NN;
for(int i = 0; i<num; i++){
double max,min;
max = Double.NEGATIVE_INFINITY;
min = Double.POSITIVE_INFINITY;
for(int j=0; j<node.completeData.size(); j++){
double tmp = node.completeData.get(j).numData.get(i);
max = Math.max(max, tmp);
min = Math.min(min, tmp);
}
maxmin.add(new MaxMin(max,min));
}
}
}