-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeights.java
More file actions
107 lines (94 loc) · 2.05 KB
/
Copy pathWeights.java
File metadata and controls
107 lines (94 loc) · 2.05 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
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
import java.io.*;
public class Weights
{
private double[] weights;
private String path;
public Weights()
{
this("weights.txt");
}
public Weights(String filePath)
{
File file = new File(filePath);
path = filePath;
BufferedReader reader = null;
double[] tempWeights = new double[1000];
int i = 0;
try {
reader = new BufferedReader(new FileReader(file));
String text = null;
// repeat until all lines is read
while ((text = reader.readLine()) != null)
{
tempWeights[i] = Double.parseDouble(text);
i++;
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (reader != null) {
reader.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
weights = new double[i];
for(int x = 0; x < i; x++)
{
weights[x] = tempWeights[x];
}
}
public void printWeights()
{
System.out.println("Weights:");
System.out.println(toString());
}
public double[] getWeights()
{
return weights;
}
@Override
public String toString()
{
String s = "";
int l = weights.length;
for(int i = 0; i < l; i++)
{
if(i == l-1)
s+=weights[i];
else
s+=weights[i]+"\n";
}
return s;
}
public void setWeights(double[] newWeights)
{
weights = newWeights;
}
public void saveWeights()
{
try {
Writer output = new BufferedWriter(new FileWriter(path));
output.write( toString() );
output.close();
}
catch(Exception e) {}
}
/*public static void main(String args[])
{
Weights w = new Weights();
w.printWeights();
double[] d = w.getWeights();
for(int x = 0; x < d.length; x++)
{
d[x]*=2;
}
w.setWeights(d);
w.saveWeights();
w.printWeights();
}*/
}