-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathUtil.java
More file actions
168 lines (150 loc) · 4.19 KB
/
Copy pathUtil.java
File metadata and controls
168 lines (150 loc) · 4.19 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import java.util.ArrayList;
public class Util {
public static ArrayList<Double> copy(ArrayList<Double> a){
ArrayList<Double> out=new ArrayList<Double>();
for(int i=0;i<a.size();i++){
out.add(a.get(i));
}
return out;
}
public static ArrayList<ArrayList<Integer>>getSym(ArrayList<double[]>means, char c){
if(c!='x'&&c!='y') return null;
ArrayList<ArrayList<Integer>> base=new ArrayList<ArrayList<Integer>>();
for(int i=0;i<means.size();i++){
if(containsMul(i, base)) continue;
ArrayList<Integer> temp=new ArrayList<Integer>();
temp.add(i);
double min=-1;
int index=-1;
for(int j=0;j<means.size();j++){
if(containsMul(j, base)) continue;
if(i==j)continue;
double[] tmp={means.get(j)[0],means.get(j)[1]};
if(c=='x') tmp[0]=-tmp[0];
else if(c=='y') tmp[1]=-tmp[1];
double dot=Vec.dotProd(means.get(i), tmp);
if(dot>=0.99&&dot>min){
min=dot;
index=j;
}
}
if(index!=-1){
temp.add(index);
}
base.add(temp);
}
return base;
}
public static ArrayList<ArrayList<Integer>>getNegs(ArrayList<double[]>means){
ArrayList<ArrayList<Integer>> base=new ArrayList<ArrayList<Integer>>();
for(int i=0;i<means.size();i++){
if(containsMul(i, base)) continue;
ArrayList<Integer> temp=new ArrayList<Integer>();
temp.add(i);
double min=1;
int index=-1;
for(int j=0;j<means.size();j++){
if(containsMul(j, base)) continue;
if(i==j)continue;
double dot=Vec.dotProd(means.get(i), means.get(j));
if(dot<=-0.99&&dot<min){
min=dot;
index=j;
}
}
if(index!=-1){
temp.add(index);
}
base.add(temp);
}
return base;
}
public static boolean contains(int n,ArrayList<Integer> a){
for(int i=0;i<a.size();i++){
if(a.get(i)==n) return true;
}
return false;
}
public static boolean contains(String n,ArrayList<String> a){
for(int i=0;i<a.size();i++){
if(a.get(i).equals(n)) return true;
}
return false;
}
public static boolean containsMul(int n,ArrayList<ArrayList<Integer>> a){
for(int i=0;i<a.size();i++){
if(contains(n,a.get(i))) return true;
}
return false;
}
public static double[] intToDoubleVec(int[] input, int size){
double[] temp=new double[size];
for(int i=0;i<size;i++){
temp[i]=(double)input[i];
}
return temp;
}
public static int locate(int n,ArrayList<ArrayList<Integer>> a){
for(int i=0;i<a.size();i++){
if(contains(n,a.get(i))) return i;
}
return -1;
}
public static ArrayList<double[]> copyVec(ArrayList<double[]> a){
ArrayList<double[]> out=new ArrayList<double[]>();
for(int i=0;i<a.size();i++){
double[] temp=new double[2];
temp[0]=a.get(i)[0];
temp[1]=a.get(i)[1];
out.add(temp);
}
return out;
}
public static double[] copyTab(double[] a){
double[] temp=new double[a.length];
for(int i=0;i<a.length;i++){
temp[i]=a[i];
}
return temp;
}
public static void printListInt(ArrayList<Integer> a){
for(int i=0;i<a.size();i++){
System.out.print(a.get(i));
if(i!=a.size()-1)System.out.print(", ");
else System.out.println();
}
}
public static void printListString(ArrayList<String> a){
for(int i=0;i<a.size();i++){
System.out.print(a.get(i));
if(i!=a.size()-1)System.out.print(", ");
else System.out.println();
}
}
public static void printListDouble(ArrayList<Double> a){
for(int i=0;i<a.size();i++){
System.out.print(a.get(i));
if(i!=a.size()-1)System.out.print(", ");
else System.out.println();
}
}
public static void printListIntMul(ArrayList<ArrayList<Integer>> list){
for(int i=0;i<list.size();i++){
printListInt(list.get(i));
}
}
public static void printListVec(ArrayList<double[]> a){
for(int i=0;i<a.size();i++){
System.out.print("( "+a.get(i)[0]+" , "+a.get(i)[1]+" )");
if(i!=a.size()-1)System.out.print(", ");
else System.out.println();
}
}
public static void printListVecInt(ArrayList<int[]> a){
for(int i=0;i<a.size();i++){
System.out.print("( "+a.get(i)[0]+" , "+a.get(i)[1]+" )");
if(i!=a.size()-1)System.out.print(", ");
else System.out.println();
}
}
}