![]()
Artificial Neural NetworksAForge.NET framework provides neural networks library, which contains set of classes The library mainly allows to create two categories of artificial neural networks:
As an example, below is small sample code of training artificial neural network to calculate XOR function.
// initialize input and output values
double[][] input = new double[4][] {
new double[] {0, 0}, new double[] {0, 1},
new double[] {1, 0}, new double[] {1, 1}
};
double[][] output = new double[4][] {
new double[] {0}, new double[] {1},
new double[] {1}, new double[] {0}
};
// create neural network
ActivationNetwork network = new ActivationNetwork(
SigmoidFunction( 2 ),
2, // two inputs in the network
2, // two neurons in the first layer
1 ); // one neuron in the second layer
// create teacher
BackPropagationLearning teacher =
new BackPropagationLearning( network );
// loop
while ( !needToStop )
{
// run epoch of learning procedure
double error = teacher.RunEpoch( input, output );
// check error value to see if we need to stop
// ...
}
Another example demonstrates unsupervised learning on the sample of clustering RGB colors with
// set range for randomization neurons' weights
Neuron.RandRange = new DoubleRange( 0, 255 );
// create network
DistanceNetwork network = new DistanceNetwork(
3, // thress inputs in the network
100 * 100 ); // 10000 neurons
// create learning algorithm
SOMLearning trainer = new SOMLearning( network );
// network's input
double[] input = new double[3];
// loop
while ( !needToStop )
{
input[0] = rand.Next( 256 );
input[1] = rand.Next( 256 );
input[2] = rand.Next( 256 );
trainer.Run( input );
// ...
// update learning rate and radius continuously,
// so networks may come steady state
}
For additional information check neural networks’ samples provided with AForge.NET framework:
|
|||||||