# HG changeset patch # User revcompgeek # Date 1210131835 21600 # Node ID ff92c77006c76e82957b20d50f32027fd3a6672d # Parent 810d58835f86aa54885acba177c2bd09505273eb Added support for reading training examples from files. diff -r 810d58835f86 -r ff92c77006c7 trunk/aid/astar.d --- a/trunk/aid/astar.d Tue Apr 15 14:39:49 2008 -0600 +++ b/trunk/aid/astar.d Tue May 06 21:43:55 2008 -0600 @@ -7,6 +7,7 @@ import mintl.arrayheap; import mintl.arraylist; +import xenon.font; class Node(DATA) { int xloc; diff -r 810d58835f86 -r ff92c77006c7 trunk/aid/nn/multilayer/backprop.d --- a/trunk/aid/nn/multilayer/backprop.d Tue Apr 15 14:39:49 2008 -0600 +++ b/trunk/aid/nn/multilayer/backprop.d Tue May 06 21:43:55 2008 -0600 @@ -1,3 +1,7 @@ +/** + * backprop.d + * Holds the backpropagation neural network. + */ module aid.nn.multilevel.backprop; diff -r 810d58835f86 -r ff92c77006c7 trunk/aid/nn/outputFunctions.d --- a/trunk/aid/nn/outputFunctions.d Tue Apr 15 14:39:49 2008 -0600 +++ b/trunk/aid/nn/outputFunctions.d Tue May 06 21:43:55 2008 -0600 @@ -1,3 +1,8 @@ +/** + * outputFunctions.d + * Holds all of the output functions used by the neural networks. + */ + module aid.nn.outputFunctions; import aid.nn.outputFunctions; diff -r 810d58835f86 -r ff92c77006c7 trunk/aid/nn/perceptron.d --- a/trunk/aid/nn/perceptron.d Tue Apr 15 14:39:49 2008 -0600 +++ b/trunk/aid/nn/perceptron.d Tue May 06 21:43:55 2008 -0600 @@ -1,3 +1,8 @@ +/** + * perceptron.d + * Holds the simple perceptron class. + */ + module aid.nn.perceptron; import aid.nn.outputFunctions; diff -r 810d58835f86 -r ff92c77006c7 trunk/backprop_test.d --- a/trunk/backprop_test.d Tue Apr 15 14:39:49 2008 -0600 +++ b/trunk/backprop_test.d Tue May 06 21:43:55 2008 -0600 @@ -1,19 +1,110 @@ - module backprop_test; - import aid.nn.multilayer.backprop; import aid.nn.outputFunctions; import aid.misc; import std.stdio; import std.random; import std.conv; +import std.string; +import std.stream; -double[][] trainingInputs, trainingOutputs; -uint numInputs; +//double[][] trainingInputs, trainingOutputs; +//uint numInputs; uint[] outputsArray; -void initTrainingExample(int example) { +struct TrainingExample { + char[] name; + uint numInputs,numOutputs; + uint[] numHidden; + double[][] inputs,outputs; +} + +/// Reads the training example from a file +TrainingExample readTrainingExample(InputStream f){ + TrainingExample e; + char[][] temp,trnInputs,trnOutputs; + char[] line; + bool gotInputs,gotOutputs,gotHidden; + + int i; + + line = f.readLine(); + temp = split(line); + if(tolower(temp[0]) != "name:") throw new Error("Expecting \"Name:\" on first line."); + e.name = join(temp[1..$]," "); + + bool stop = false; + while(!stop){ + if(f.eof) throw new Error("Unexpected end of file."); + line = strip(tolower(f.readLine())); + temp = split(line); + if(temp.length == 0) continue; + switch(temp[0]){ + case "inputs:": + if(gotInputs) throw new Error("Only one inputs line allowed."); + e.numInputs = toInt(temp[1]); + if(e.numInputs < 1) throw new Error("Inputs cannot be less than 1."); + gotInputs = true; + break; + case "outputs:": + if(gotOutputs) throw new Error("Only one outputs line allowed."); + e.numOutputs = toInt(temp[1]); + if(e.numOutputs < 1) throw new Error("Outputs cannot be less than 1."); + gotOutputs = true; + break; + case "hidden:": + if(gotHidden) throw new Error("Only one hidden line allowed."); + if(temp.length == 1) break; + temp = split(join(temp[1..$],""),","); + e.numHidden.length = temp.length; + for(i = 0; i