# HG changeset patch # User revcompgeek # Date 1207959175 21600 # Node ID 314d68bafefff1624509a3f422cddc4890affd90 # Parent 9655c8362b254a579b85f0c98e409b90de8dc724 Backprop and backprop_test added (no testing). diff -r 9655c8362b25 -r 314d68bafeff trunk/aid/misc.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/aid/misc.d Fri Apr 11 18:12:55 2008 -0600 @@ -0,0 +1,13 @@ +module aid.misc; + +import std.random; + +class InputException : Exception { + this(char[] message){ + super(message); + } +} + +double rnd(){ // The function that should be included in every math library! + return (cast(double)rand())/uint.max; +} \ No newline at end of file diff -r 9655c8362b25 -r 314d68bafeff trunk/aid/nn/multilayer/backprop.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/aid/nn/multilayer/backprop.d Fri Apr 11 18:12:55 2008 -0600 @@ -0,0 +1,170 @@ +module aid.nn.multilevel.backprop; + +import aid.nn.outputFunctions; +import aid.misc; +import std.random; +import std.stream; + +class Backprop { + private uint numInputs; + private float[][][] units; // Includes the output units. units[layer][unit][inputWeight] + private OutputFunctionPtr[] functions; + public float learningRate; + + ///Constructor + public this(uint numInputs,uint[] numUnits,OutputFunctionPtr[] functions,float value=0.05,bool randomize=true){ + if(numUnits.length == 0) throw new InputException("numUnits must be greater than 0"); + if(numUnits.length != functions.length) throw new InputException("numUnits and functions must be the same length"); + this.numInputs = numInputs; + this.functions = functions; + initUnitLayer(0,numUnits[0],numInputs,value,randomize); + for(int i=1; i