Repository navigation
Expand file tree
/
Copy pathDataSet.java
More file actions
64 lines (51 loc) · 1.39 KB
/
Copy pathDataSet.java
File metadata and controls
64 lines (51 loc) · 1.39 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
import edu.princeton.cs.algs4.In;
import edu.princeton.cs.algs4.Point2D;
public class DataSet {
private int n, m;
private Point2D[] locations;
private int[][] input;
private int[] labels;
public DataSet(String filename) {
In datafile = new In(filename);
n = datafile.readInt();
m = datafile.readInt();
locations = new Point2D[m];
for (int i = 0; i < m; i++) {
double x = datafile.readDouble();
double y = datafile.readDouble();
locations[i] = new Point2D(x, y);
}
labels = new int[n];
for (int i = 0; i < n; i++) {
labels[i] = datafile.readInt();
}
input = new int[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
input[i][j] = datafile.readInt();
}
}
}
public int getN() {
return n;
}
public int getM() {
return m;
}
public Point2D[] getLocations() {
return locations.clone();
}
public int[][] getInput() {
int[][] copy = new int[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
copy[i][j] = input[i][j];
}
}
return copy;
}
public int[] getLabels() {
return labels.clone();
}
public static void main(String[] args) { }
}