/
Load.java
74 lines (72 loc) · 2.23 KB
/
Load.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
import org.shogun.*;
import org.jblas.*;
import java.io.*;
import java.util.*;
public class Load {
public static DoubleMatrix load_numbers(String filename) {
DoubleMatrix result = null;
try {
DoubleMatrix temp = DoubleMatrix.loadAsciiFile(filename);
result = temp.transpose();
} catch(java.io.IOException e) {
System.out.println("Unable to create matrix from " + filename + ": " + e.getMessage());
System.exit(-1);
}
return result;
}
public static DoubleMatrix load_labels(String filename) {
DoubleMatrix result = null;
try {
DoubleMatrix temp = DoubleMatrix.loadAsciiFile(filename);
result = temp.reshape(1, temp.getLength());
} catch(java.io.IOException e) {
System.out.println("Unable to create matrix from " + filename + ": " + e.getMessage());
System.exit(-1);
}
return result;
}
public static String[] load_dna(String filename) {
ArrayList<String> list = new ArrayList<String>();
String[] result = null;
try {
FileInputStream fstream = new FileInputStream(filename);
DataInputStream in = new DataInputStream(fstream);
BufferedReader buffer = new BufferedReader(new InputStreamReader(in));
String line;
while((line = buffer.readLine()) != null) {
list.add(line);
}
in.close();
result = new String[list.size()];
for (int i = 0; i < list.size(); i++) {
result[i] = (String)list.get(i);
}
} catch(java.io.IOException e) {
System.out.println("Unable to create matrix from " + filename + ": " + e.getMessage());
System.exit(-1);
}
return result;
}
public static String[] load_cubes(String filename) {
ArrayList<String> list = new ArrayList<String>();
String[] result = null;
try {
FileInputStream fstream = new FileInputStream(filename);
DataInputStream in = new DataInputStream(fstream);
BufferedReader buffer = new BufferedReader(new InputStreamReader(in));
String line;
while((line = buffer.readLine()) != null) {
list.add(line);
}
in.close();
result = new String[list.size()];
for (int i = 0; i < list.size(); i++) {
result[i] = (String)list.get(i);
}
} catch(java.io.IOException e) {
System.out.println("Unable to create matrix from " + filename + ": " + e.getMessage());
System.exit(-1);
}
return result;
}
}