-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.dart
75 lines (56 loc) · 1.79 KB
/
main.dart
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
import 'libs/net.dart';
import 'libs/parser.dart';
import 'libs/byteio.dart';
void train(ParsedData data,{bool resume = true, bool save = true}){
Net neuralNet = new Net(data.topology);
ByteIORead btr = ByteIORead(data.inputData);
List<double> samples;
if(resume) neuralNet.loadWeights(data.weightFile);
while(btr.eof != true){
print("training");
samples = btr.getMultiple(data.topology[0]);
print("Inputs => ${samples}");
neuralNet.feedForward(samples);
samples = neuralNet.getResults();
print("Got => ${samples}");
samples = btr.getMultiple(data.topology.last);
print("Presume => ${samples}");
neuralNet.backProp(samples);
print("Error: ${neuralNet.recentAverageError}");
}
if(save) neuralNet.saveWeights(data.weightFile);
}
void run(ParsedData data){
Net neuralNet = new Net(data.topology);
ByteIORead btr = ByteIORead(data.inputData);
ByteIOWrite btw = ByteIOWrite(data.outputData);
List<double> samples;
neuralNet.loadWeights(data.weightFile);
while(btr.eof != true){
print("Running");
samples = btr.getMultiple(data.topology[0]);
print("Inputs => ${samples}");
neuralNet.feedForward(samples);
samples = neuralNet.getResults();
print("Got => ${samples}");
btw.addDoubles(samples);
}
}
void main(List<String> args) {
ParsedData data = new ParsedData(args);
if(data.isOk != true){
print("Usage:\n");
print("\tProgram train <inputData> <outPutWeights> [ topology ]");
print("\tProgram run <inputWeights> <inputData> <outputData> [ topology ]");
print("Example:\n");
print("\tProgram run weights.bin inputs.bin output.bin 2 3 4 1\n");
}
switch (data.action) {
case Action.train:
train(data);
break;
case Action.run:
run(data);
break;
}
}