-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrepareSusyWeighted_0.java
290 lines (220 loc) · 7.73 KB
/
PrepareSusyWeighted_0.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
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
public class PrepareSusyWeighted_0 {
public static void main(String args[]) {
String fichero = args[0];
long Inicio=System.nanoTime();
Double Conta=0.0;
Double ContLe =0.0;
Double Cont0=0.0;
Double Cont1=0.0;
Double [] Max =new Double[9];
Double [] Min =new Double[9];
Max[1]= 20.553449630737305;
Max[2]= 2.10160493850708;
Max[3]= 1.7348390817642212;
Max[4]= 33.035621643066406;
Max[5]= 2.059720754623413;
Max[6]= 1.734686255455017;
Max[7]= 21.068876266479492;
Max[8]= 1.7406890392303467;
Min[1]= 0.25488153100013733;
Min[2]= -2.1029269695281982;
Min[3]= -1.7347885370254517;
Min[4]= 0.4285859763622284;
Min[5]= -2.0593061447143555;
Min[6]= -1.7342021465301514;
Min[7]= 2.598710998427123E-4;
Min[8]= -1.7271170616149902;
int NumCampos =9;
int TopeMemoria = 400002;
Double [][] Tabvotos0 = new Double[NumCampos][TopeMemoria];
Double [][] Tabvotos1 = new Double[NumCampos][TopeMemoria];
for (int i=0; i<9;i++)
{
for (int j=0;j<TopeMemoria;j++)
{
Tabvotos0[i][j]=0.0;
Tabvotos1[i][j]=0.0;
}
}
Double Maximo=0.0;
System.out.println("Start PrepareSusyWeighted_0.java");
try {
FileReader fr = new FileReader(fichero);
BufferedReader br = new BufferedReader(fr);
String linea;
// Case of considering the last 500,000 records as test
// while( ((linea = br.readLine()) != null) && (Conta < 4500000.0))
while ((linea = br.readLine()) != null)
{ // System.out.println(linea);
String lineadelTrain []=linea.split(",");
Conta++;
for(int z=1; z<9; z++)
{
Double FactorPri = 1.0;
Double MaxIndice= TopeMemoria - 2.0;
int indice =0;
Double ValorTrain =Double.parseDouble(lineadelTrain[z]);
ValorTrain = ValorTrain - Min[z];
Maximo = Max[z] - Min[z];
indice = (int) ( ( (TopeMemoria - 2.0) * ValorTrain)/ Maximo);
// THE MAXIMUM INDEX 400000, 400001 reserves the number of records
// and 400002 the overfloweds
if ( (indice > (TopeMemoria-2)) || (indice < 0))
{
System.out.println(" index overflowed=" + indice + " in the field="+z );
indice=TopeMemoria;
}
Double valor=0.0;
if (Double.parseDouble(lineadelTrain[0]) == 0.0)
{
valor= Tabvotos0[z][TopeMemoria-1];
valor++;
Tabvotos0[z][TopeMemoria-1]=valor;
valor= Tabvotos0[z][indice];
valor=valor+FactorPri;
Tabvotos0[z][indice]=valor;
}
else
{
valor= Tabvotos1[z][TopeMemoria-1];
valor++;
Tabvotos1[z][TopeMemoria-1]=valor;
valor= Tabvotos1[z][indice];
valor=valor+FactorPri;
Tabvotos1[z][indice]=valor;
} // fin if
}// fin for z
//--------------------------------------
} // fin while
fr.close();
System.out.println("Readed records from training"+ fichero + ": " + Conta);
} // fin try
catch(Exception e) {
System.out.println("Exception reading file "+ fichero + ": " + e);
}
//**************************************************************************************
Double TotAciertos=0.0;
Double TotFallos =0.0;
Double TotValoresACero=0.0;
Conta=0.0;
String ficheroTest = args[1];
try {
FileReader fr = new FileReader(ficheroTest);
BufferedReader br = new BufferedReader(fr);
FileWriter Salida = null;
PrintWriter pw = null;
Salida = new FileWriter("SusyWeighted.txt");
pw = new PrintWriter(Salida);
String linea;
// Case of considering the last 500,000 records as test
// while(((linea = br.readLine()) != null) && (Conta < 4500000.0))
while((linea = br.readLine()) != null)
{
String lineadelTest []=linea.split(",");
Conta++;
Double TotValor0=0.0;
Double TotValor1=0.0;
Double TotValores = 0.0;
for(int z=1; z<9; z++)
{
int indice=0;
Double ValorTrain = Double.parseDouble(lineadelTest[z]);
ValorTrain = ValorTrain - Min[z];
Maximo = Max[z] - Min[z];
indice = (int) ( ( (TopeMemoria - 2) * ValorTrain)/ Maximo);
if ( (indice > ( TopeMemoria - 2) )|| (indice < 0))
{
System.out.println(" Index overflowed=" + indice + " in the field="+z );
indice=TopeMemoria ;
}
Double valor=0.0;
//
//frequencies are recovered
Double valor0= Tabvotos0[z][indice];
Double valor1= Tabvotos1[z][indice];
// Priorities are assigned based on fields, which improves the hit rate
//
Double FactorPri = 1.0;
if (z>8)
FactorPri = 0.0;
if ( (z==1) )
{FactorPri = 0.8;}
if ( (z==2) )
{FactorPri = 0.9;}
if ( (z==3) )
{FactorPri = 1.0;}
if ( (z==4) )
{FactorPri = 0.0;}
if ( (z==5) )
{FactorPri =0.9;}
if ( (z==6) )
{FactorPri =0.9;}
if ( (z==7) )
{FactorPri =1.0;}
if ( (z==8) )
{FactorPri =0.95;}
if (indice < (TopeMemoria -1))
{
// In SUSY There are 2712173.0 class 0 and 2287827.0 class 1 registers,
// to compensate because there are more class 0s
valor0=valor0* 2287827.0/2712173.0;
// valor0=valor0* 2058398.0/2441602.0;
TotValor0=TotValor0+ (valor0/(valor0 + valor1))*FactorPri;
TotValor1=TotValor1+(valor1/(valor0 + valor1))*FactorPri;
TotValores = TotValores + valor1 - valor0;
}
} // fin for int z=1
if ( Double.parseDouble(lineadelTest[0] )== 0.0)
Cont0++;
else
Cont1++;
if (TotValores == 0.0) {
pw.println(linea+",1");
TotValoresACero++;}
else {
if (TotValor1 > TotValor0)
{
if ( Double.parseDouble(lineadelTest[0] )== 0.0)
{
pw.println(linea+",1");
TotFallos++;
}else {
pw.println(linea+",0");
TotAciertos++;
}
}
else
{
if (Double.parseDouble(lineadelTest[0] ) == 0.0)
{
pw.println(linea+",0");
TotAciertos++;
}else {
pw.println(linea+",1");
TotFallos++;
}
}
} // fin de else if (TotValores == 0.0)
} // fin while
System.out.println(" Total hits = " + TotAciertos);
System.out.println(" Total failures = = " + TotFallos);
System.out.println(" Assigned without foundation = " + TotValoresACero);
fr.close();
pw.close();
Salida.close();
System.out.println("Records read test file "+ ficheroTest + ": " + Conta);
Double FinalParcial =(System.nanoTime()-Inicio)/1000000000.0;
System.out.println("Total run time= " + FinalParcial );
}
catch(Exception e) {
System.out.println("Exception reading file "+ fichero + ": " + e);
}
//________________________________________________________________________________________
}// fin del main
}