-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTrainingExAdapter.java
More file actions
executable file
·61 lines (52 loc) · 1.7 KB
/
TrainingExAdapter.java
File metadata and controls
executable file
·61 lines (52 loc) · 1.7 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
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package bric.Image;
import bric.LogisticRegression.TrainingExample;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
/**
*
* @author BrianCarlsen
*/
public class TrainingExAdapter {
private static TrainingExample loadToTrainingEx(String in) {
String[] inputS = in.split("[,;] ");
if (inputS.length <= 2)
return null;
String ansS = inputS[inputS.length - 1];
double[] input = new double[inputS.length - 1];
int ans;
for (int i = 0; i < inputS.length - 1; ++i) {
input[i] = new Double(inputS[i]);
}
ans = new Integer(ansS);
return new TrainingExample(input, ans);
}
public static ArrayList<TrainingExample> toTrainingEx (File f) {
ArrayList<TrainingExample> tex = new ArrayList<TrainingExample>();
String s;
try {
BufferedReader reader = new BufferedReader(new FileReader(f));
while ((s = reader.readLine()) != null) {
TrainingExample t = loadToTrainingEx(s);
if (t != null)
tex.add(t);
}
}
catch (Exception e) {
e.printStackTrace();
}
return tex;
}
public static void main(String... args) {
String fp = System.getProperty("user.dir");
File f = new File(fp + "\\webotsTestFile.txt");
ArrayList<TrainingExample> t = TrainingExAdapter.toTrainingEx(f);
for (TrainingExample e : t)
e.show();
}
}