Created
February 2, 2013 13:37
-
-
Save yangboz/4697424 to your computer and use it in GitHub Desktop.
AS3 Artificial Neuron Network test code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package | |
{ | |
import com.lookbackon.AI.ANN.NeuralNetWork; | |
import flash.display.Sprite; | |
public class NeuronNetWorkTest extends Sprite | |
{ | |
private var inputDataArray:Array; | |
private var outputDataArray:Array; | |
/// Executes a Neural Network MultiLayer FeedForward BackPropagation | |
/// Algorithm for Learning or Classification | |
public function NeuronNetWorkTest() | |
{ | |
//a two-dimensional array of 14 samples and 6 input Neurons | |
//14 samples with 6 inputs | |
inputDataArray = new Array( | |
[ | |
[1, 0, 0, 0.85, 0.85, 0], [1, 0, 0, 0.80, 0.90, 1], [0, 1, 0, 0.83, 0.86, 0], [0, 0, 1, 0.70, 0.96, 0], | |
[0, 0, 1, 0.68, 0.80, 0], [0, 0, 1, 0.65, 0.70, 1], [0, 1, 0, 0.64, 0.65, 1], [1, 0, 0, 0.72, 0.95, 0], | |
[1, 0, 0, 0.69, 0.70, 0], [0, 0, 1, 0.75, 0.80, 0], [1, 0, 0, 0.75, 0.70, 1], [0, 1, 0, 0.72, 0.90, 1], | |
[0, 1, 0, 0.81, 0.75, 0], [0, 0, 1, 0.71, 0.91, 1] | |
]); | |
//a two-dimensional array of 14 samples and 1 output Neuron | |
//14 samples with 1 target output | |
outputDataArray = new Array( | |
[ | |
[0], [0], [1], [1], [1], [0], [1], [0], [1], [1], [1], [1], [1], [0] | |
] | |
); | |
var net:NeuralNetWork = new NeuralNetWork(); | |
var recordCount:int = inputDataArray.length; | |
// int recordCount = inputDataArray.GetUpperBound(0) + 1; | |
if(recordCount !=(outputDataArray.length)) | |
{ | |
throw new Error("number of samples in input data is not equal to number of samples in output data!!"); | |
} | |
/*if (recordCount != (outputDataArray.GetUpperBound(0) + 1)) | |
{ | |
throw new System.ArgumentOutOfRangeException("number of samples in input data is not equal to number of samples in output data"); | |
}*/ | |
net.initialize(inputDataArray,outputDataArray,4); | |
for(var count:int=0;count<NeuralNetWork.iterations;count++) | |
{ | |
for(var sample:int=0;sample<recordCount;sample++) | |
{ | |
net.feedForward(sample); | |
net.backPropagate(); | |
trace("Count:", count.toFixed(4) , " Output : " , net.outputNeurons.getItemAt(0).output.toFixed(4) , " OutputTraining : " , net.outputNeurons.getItemAt(0).outputTraning.toFixed(4) , " Learning Rate : " , net.learning_rate); | |
} | |
//adjust the learning rate after every training sample iteration | |
net.learning_rate = Number(1 / (Number(count) + 1)); | |
trace("After adjust Count: : " + count.toFixed(4) + " Output : " + net.outputNeurons.getItemAt(0).output.toFixed(4) + " OutputTraining : " + net.outputNeurons.getItemAt(0).outputTraning.toFixed(4) + " Learning Rate : " + net.learning_rate); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment