-
Notifications
You must be signed in to change notification settings - Fork 0
/
Reader.java
70 lines (61 loc) · 2.26 KB
/
Reader.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
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class Reader {
public Amostra[] readDataSet() {
Amostra amostras[] = new Amostra[272];
double input[] = new double[5];
double output[] = new double[1];
try {
FileReader file = new FileReader("ecoli.data");
BufferedReader fr = new BufferedReader(file);
String line;
int amostra = 0;
while ((line = fr.readLine()) != null) {
String[] s = line.split("\\s+");
for(int i=1; i<s.length; i++){
if(i==(s.length-1)){
switch(s[i]){
case "cp":
output[0] = 0;
break;
case "im":
output[0] = 1;
break;
case "pp":
output[0] = 2;
break;
}
}else{
input[i-1] = Double.parseDouble(s[i]);
}
}
amostras[amostra] = new Amostra(input, output);
amostra++;
}
file.close();
} catch (IOException e) {
System.err.printf("Erro na abertura do arquivo: %s.\n", e.getMessage());
}
return amostras;
}
/*
private void normalizer(Amostra[] amostras) {
for(int x=0; x<amostras[0].input.length; x++){
int imax=0, imin=0;
for(int i=1; i<amostras.length; i++){
if(amostras[imax].input[x]<amostras[i].input[x]) imax = i;
if(amostras[imin].input[x]>amostras[i].input[x]) imin = i;
}
float xmin = (float)amostras[imin].input[x];
float xmax = (float)amostras[imax].input[x];
if(xmin != xmax){
if(xmin == 0) xmin = 0.005f;
for(int i=0; i<amostras.length; i++){
amostras[i].input[x] = (amostras[i].input[x]-xmin)/(xmax-xmin);
}
}
}
}
*/
}