Fitness function for symbolic regression (function approximation) problem
Namespace:
AForge.GeneticAssembly: AForge.Genetic (in AForge.Genetic.dll) Version: 2.2.4.0 (2.2.4.0)
Syntax
| C# |
|---|
public class SymbolicRegressionFitness : IFitnessFunction |
Remarks
The fitness function calculates fitness value of
GP and GEP
chromosomes with the aim of solving symbolic regression problem. The fitness function’s
value is computed as:
CopyC#
where error equals to the sum of absolute differences between function values (computed using
the function encoded by chromosome) and input values (function to be approximated).100.0 / ( error + 1 )
Sample usage:
// constants double[] constants = new double[5] { 1, 2, 3, 5, 7 }; // function to be approximated double[,] data = new double[5, 2] { {1, 1}, {2, 3}, {3, 6}, {4, 10}, {5, 15} }; // create population Population population = new Population( 100, new GPTreeChromosome( new SimpleGeneFunction( 1 + constants.Length ) ), new SymbolicRegressionFitness( data, constants ), new EliteSelection( ) ); // run one epoch of the population population.RunEpoch( );