AForge.NET

Testimonials
Features
Samples
Tools
Documentation
License
Downloads
Sources
Discussions
Partners
Projects
Members
Donate

AForge.NET Framework
2.2.5 version is available!

Artificial Neural Networks

AForge.NET framework provides neural networks library, which contains set of classes aimed for creating different type of artificial neural networks and training them to solve certain tasks, like recognition, approximation, prediction, etc.

The library mainly allows to create two categories of artificial neural networks:

  • Feed forward neural networks with activation function. This type of networks is represented as by one layer, as by multi layer networks, which don't have recurrent connections - information flaws in these networks from inputs to outputs passing all layers of neural network only one time without doing loops. Neurons of such networks calculate their output by calculating weighted sum of their inputs and passing it to activation function, which value becomes an output of neuron. With the ability to set activation function to use in neural network and configure it size, it is possible to creates different type of networks for different tasks starting from simple perceptron (neuron with threshold activation function), which does classification of linearly separable data into two classes, and ending with complex multi layer networks, which are aimed for recognition, prediction, etc.
  • One layer distance networks. Neurons of this type of networks calculate their output as distance value between neuron's inputs and its weight - sum of absolute differences. Such type of neurons' output calculation makes these networks usable as Kohonen Self Organizing Networks, for example.

As an example, below is small sample code of training artificial neural network to calculate XOR function. Since XOR function represent a none linearly separable function, the sample use 2 layers network to calculate it. The network is trained using Back Propagation learning algorithm.

// 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 Kohonen Self Organizing Map.

// 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: