C# Класс Accord.Neuro.Learning.EvolutionaryLearning

Neural networks' evolutionary learning algorithm, which is based on Genetic Algorithms.

The class implements supervised neural network's learning algorithm, which is based on Genetic Algorithms. For the given neural network, it create a population of DoubleArrayChromosome chromosomes, which represent neural network's weights. Then, during the learning process, the genetic population evolves and weights, which are represented by the best chromosome, are set to the source neural network.

See Population class for additional information about genetic population and evolutionary based search.

Sample usage (training network to calculate XOR function):

// initialize input and output values double[][] input = new double[4][] { new double[] {-1, 1}, new double[] {-1, 1}, new double[] { 1, -1}, new double[] { 1, 1} }; double[][] output = new double[4][] { new double[] {-1}, new double[] { 1}, new double[] { 1}, new double[] {-1} }; // create neural network ActivationNetwork network = new ActivationNetwork( BipolarSigmoidFunction( 2 ), 2, // two inputs in the network 2, // two neurons in the first layer 1 ); // one neuron in the second layer // create teacher EvolutionaryLearning teacher = new EvolutionaryLearning( network, 100 ); // number of chromosomes in genetic population // loop while ( !needToStop ) { // run epoch of learning procedure double error = teacher.RunEpoch( input, output ); // check error value to see if we need to stop // ... }
Наследование: ISupervisedLearning
Показать файл Открыть проект

Открытые методы

Метод Описание
EvolutionaryLearning ( ActivationNetwork activationNetwork, int populationSize ) : System

Initializes a new instance of the EvolutionaryLearning class.

This version of constructor is used to create genetic population for searching optimal neural network's weight using default set of parameters, which are: Selection method - elite; Crossover rate - 0.75; Mutation rate - 0.25; Rate of injection of random chromosomes during selection - 0.20; Random numbers generator for initializing new chromosome - UniformGenerator( new Range( -1, 1 ) ); Random numbers generator used during mutation for genes' multiplication - ExponentialGenerator( 1 ); Random numbers generator used during mutation for adding random value to genes - UniformGenerator( new Range( -0.5f, 0.5f ) ).

In order to have full control over the above default parameters, it is possible to used extended version of constructor, which allows to specify all of the parameters.

EvolutionaryLearning ( ActivationNetwork activationNetwork, int populationSize, IRandomNumberGenerator chromosomeGenerator, IRandomNumberGenerator mutationMultiplierGenerator, IRandomNumberGenerator mutationAdditionGenerator, ISelectionMethod selectionMethod, double crossOverRate, double mutationRate, double randomSelectionRate ) : System

Initializes a new instance of the EvolutionaryLearning class.

Run ( double input, double output ) : double

Runs learning iteration.

The method is not implemented, since evolutionary learning algorithm is global and requires all inputs/outputs in order to run its one epoch. Use RunEpoch method instead.

RunEpoch ( double input, double output ) : double

Runs learning epoch.

While running the neural network's learning process, it is required to pass the same input and output values for each epoch. On the very first run of the method it will initialize evolutionary fitness function with the given input/output. So, changing input/output in middle of the learning process, will break it.

Приватные методы

Метод Описание
CalculateNetworkSize ( ActivationNetwork activationNetwork ) : int

Описание методов

EvolutionaryLearning() публичный Метод

Initializes a new instance of the EvolutionaryLearning class.

This version of constructor is used to create genetic population for searching optimal neural network's weight using default set of parameters, which are: Selection method - elite; Crossover rate - 0.75; Mutation rate - 0.25; Rate of injection of random chromosomes during selection - 0.20; Random numbers generator for initializing new chromosome - UniformGenerator( new Range( -1, 1 ) ); Random numbers generator used during mutation for genes' multiplication - ExponentialGenerator( 1 ); Random numbers generator used during mutation for adding random value to genes - UniformGenerator( new Range( -0.5f, 0.5f ) ).

In order to have full control over the above default parameters, it is possible to used extended version of constructor, which allows to specify all of the parameters.

public EvolutionaryLearning ( ActivationNetwork activationNetwork, int populationSize ) : System
activationNetwork ActivationNetwork Activation network to be trained.
populationSize int Size of genetic population.
Результат System

EvolutionaryLearning() публичный Метод

Initializes a new instance of the EvolutionaryLearning class.
public EvolutionaryLearning ( ActivationNetwork activationNetwork, int populationSize, IRandomNumberGenerator chromosomeGenerator, IRandomNumberGenerator mutationMultiplierGenerator, IRandomNumberGenerator mutationAdditionGenerator, ISelectionMethod selectionMethod, double crossOverRate, double mutationRate, double randomSelectionRate ) : System
activationNetwork ActivationNetwork Activation network to be trained.
populationSize int Size of genetic population.
chromosomeGenerator IRandomNumberGenerator Random numbers generator used for initialization of genetic /// population representing neural network's weights and thresholds (see ).
mutationMultiplierGenerator IRandomNumberGenerator Random numbers generator used to generate random /// factors for multiplication of network's weights and thresholds during genetic mutation /// (ses .)
mutationAdditionGenerator IRandomNumberGenerator Random numbers generator used to generate random /// values added to neural network's weights and thresholds during genetic mutation /// (see ).
selectionMethod ISelectionMethod Method of selection best chromosomes in genetic population.
crossOverRate double Crossover rate in genetic population (see /// ).
mutationRate double Mutation rate in genetic population (see /// ).
randomSelectionRate double Rate of injection of random chromosomes during selection /// in genetic population (see ).
Результат System

Run() публичный Метод

Runs learning iteration.
The method is not implemented, since evolutionary learning algorithm is global and requires all inputs/outputs in order to run its one epoch. Use RunEpoch method instead.
The method is not implemented by design.
public Run ( double input, double output ) : double
input double Input vector.
output double Desired output vector.
Результат double

RunEpoch() публичный Метод

Runs learning epoch.

While running the neural network's learning process, it is required to pass the same input and output values for each epoch. On the very first run of the method it will initialize evolutionary fitness function with the given input/output. So, changing input/output in middle of the learning process, will break it.

public RunEpoch ( double input, double output ) : double
input double Array of input vectors.
output double Array of output vectors.
Результат double