comparison trunk/backprop_test.d @ 7:b9fe92a2d8ad default tip

Removed old code.
author revcompgeek
date Tue, 06 May 2008 22:20:26 -0600
parents ff92c77006c7
children
comparison
equal deleted inserted replaced
6:ff92c77006c7 7:b9fe92a2d8ad
7 import std.random; 7 import std.random;
8 import std.conv; 8 import std.conv;
9 import std.string; 9 import std.string;
10 import std.stream; 10 import std.stream;
11 11
12 //double[][] trainingInputs, trainingOutputs;
13 //uint numInputs;
14 uint[] outputsArray; 12 uint[] outputsArray;
15 13
16 struct TrainingExample { 14 struct TrainingExample {
17 char[] name; 15 char[] name;
18 uint numInputs,numOutputs; 16 uint numInputs,numOutputs;
102 } 100 }
103 101
104 return e; 102 return e;
105 } 103 }
106 104
107 /*void initTrainingExample(int example) {
108 if(example == 0) {
109 numInputs = 3;
110 outputsArray = [2,1];
111 trainingInputs = [[0, 0, 0],
112 [0, 0, 1],
113 [0, 1, 0],
114 [0, 1, 1],
115 [1, 0, 0],
116 [1, 0, 1],
117 [1, 1, 0],
118 [1, 1, 1]];
119
120 trainingOutputs = [[0.1],
121 [0.9],
122 [0.9],
123 [0.1],
124 [0.9],
125 [0.1],
126 [0.1],
127 [0.9]];
128 } else if(example == 1) {
129 numInputs = 2;
130 outputsArray = [2,1];
131 trainingInputs = [[0, 0],
132 [1, 0],
133 [0, 1],
134 [1, 1]];
135
136 trainingOutputs = [[0.9],
137 [0.1],
138 [0.1],
139 [0.9]];
140 } else if(example == 2) {
141 numInputs = 8;
142 outputsArray = [3,8];
143 trainingInputs = [
144 [0.9, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1],
145 [0.1, 0.9, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1],
146 [0.1, 0.1, 0.9, 0.1, 0.1, 0.1, 0.1, 0.1],
147 [0.1, 0.1, 0.1, 0.9, 0.1, 0.1, 0.1, 0.1],
148 [0.1, 0.1, 0.1, 0.1, 0.9, 0.1, 0.1, 0.1],
149 [0.1, 0.1, 0.1, 0.1, 0.1, 0.9, 0.1, 0.1],
150 [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.9, 0.1],
151 [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.9]];
152
153 trainingOutputs = trainingInputs;
154 }
155 }*/
156
157 void main(char[][] args) { 105 void main(char[][] args) {
158 double learningRate = 0.2, momentum = 0.3, randomSize = 0.1, errorMin = 0.05; 106 double learningRate = 0.2, momentum = 0.3, randomSize = 0.1, errorMin = 0.05;
159 int /*trainingExample = 0,*/ maxIters = 10000; // 0 to 2 107 int /*trainingExample = 0,*/ maxIters = 10000; // 0 to 2
160 bool quiet,printFull,printWeights; 108 bool quiet,printFull,printWeights;
161 int printEvery = 500; // output every ~ times 109 int printEvery = 500; // output every ~ times
183 break; 131 break;
184 case "-e": 132 case "-e":
185 case "--error-min": 133 case "--error-min":
186 errorMin = toDouble(args[++i]); 134 errorMin = toDouble(args[++i]);
187 break; 135 break;
188 /*case "-n":
189 case "--example-number":
190 trainingExample = toInt(args[++i]);
191 if(trainingExample > 2 || trainingExample < 0)
192 throw new Error("example number must be between 0 and 2");
193 case "-x":
194 case "--example":
195 switch(args[++i]) {
196 case "parity":
197 trainingExample = 0;
198 break;
199 case "xor":
200 trainingExample = 1;
201 break;
202 case "identity":
203 trainingExample = 2;
204 break;
205 default:
206 throw new Error("Wrong example name. Must be parity, xor or identity");
207 }
208 break;*/
209 case "-q": 136 case "-q":
210 case "--quiet": 137 case "--quiet":
211 quiet = true; 138 quiet = true;
212 break; 139 break;
213 case "-p": 140 case "-p":
230 break; 157 break;
231 default: 158 default:
232 throw new Error("Unknown switch: " ~ args[i]); 159 throw new Error("Unknown switch: " ~ args[i]);
233 } 160 }
234 } 161 }
235 //} catch(ArrayBoundsError) { 162
236 // throw new Error("Wrong number of paramaters");
237 //}
238
239 //initTrainingExample(trainingExample);
240
241 writefln("Starting training with: " ~ example.name); 163 writefln("Starting training with: " ~ example.name);
242 164
243 OutputFunctionPtr[] functions; 165 OutputFunctionPtr[] functions;
244 functions.length = example.numHidden.length + 1; 166 functions.length = example.numHidden.length + 1;
245 for(int i = 0; i<functions.length; i++){ 167 for(int i = 0; i<functions.length; i++){