C# Class Accord.Genetic.TimeSeriesPredictionFitness

Fitness function for times series prediction problem

The fitness function calculates fitness value of GP and GEP chromosomes with the aim of solving times series prediction problem using sliding window method. The fitness function's value is computed as: 100.0 / ( error + 1 ) where error equals to the sum of absolute differences between predicted value and actual future value.

Sample usage:

// number of points from the past used to predict new one int windowSize = 5; // time series to predict double[] data = new double[13] { 1, 2, 4, 7, 11, 16, 22, 29, 37, 46, 56, 67, 79 }; // constants double[] constants = new double[10] { 1, 2, 3, 5, 7, 11, 13, 17, 19, 23 }; // create population Population population = new Population( 100, new GPTreeChromosome( new SimpleGeneFunction( windowSize + constants.Length ) ), new TimeSeriesPredictionFitness( data, windowSize, 1, constants ), new EliteSelection( ) ); // run one epoch of the population population.RunEpoch( );
Inheritance: IFitnessFunction
Datei anzeigen Open project: accord-net/framework Class Usage Examples

Public Methods

Method Description
Evaluate ( IChromosome chromosome ) : double

Evaluates chromosome.

The method calculates fitness value of the specified chromosome.

TimeSeriesPredictionFitness ( double data, int windowSize, int predictionSize, double constants ) : System

Initializes a new instance of the TimeSeriesPredictionFitness class.

The data parameter is a one dimensional array, which defines times series to predict. The amount of learning samples is equal to the number of samples in the provided time series, minus window size, minus prediction size.

The predictionSize parameter specifies the amount of samples, which should be excluded from training set. This set of samples may be used for future verification of the prediction model.

The constants parameter is an array of constants, which can be used as additional variables for a genetic expression. The actual amount of variables for genetic expression equals to the amount of constants plus the window size.

Translate ( IChromosome chromosome ) : string

Translates genotype to phenotype.

The method returns string value, which represents prediction expression written in polish postfix notation.

The interpretation of the prediction expression is very simple. For example, let's take a look at sample expression, which was received with window size equal to 5: $0 $1 - $5 / $2 * The above expression in postfix polish notation should be interpreted as a next expression: ( ( x[t - 1] - x[t - 2] ) / const1 ) * x[t - 3]

Method Details

Evaluate() public method

Evaluates chromosome.
The method calculates fitness value of the specified chromosome.
public Evaluate ( IChromosome chromosome ) : double
chromosome IChromosome Chromosome to evaluate.
return double

TimeSeriesPredictionFitness() public method

Initializes a new instance of the TimeSeriesPredictionFitness class.

The data parameter is a one dimensional array, which defines times series to predict. The amount of learning samples is equal to the number of samples in the provided time series, minus window size, minus prediction size.

The predictionSize parameter specifies the amount of samples, which should be excluded from training set. This set of samples may be used for future verification of the prediction model.

The constants parameter is an array of constants, which can be used as additional variables for a genetic expression. The actual amount of variables for genetic expression equals to the amount of constants plus the window size.

public TimeSeriesPredictionFitness ( double data, int windowSize, int predictionSize, double constants ) : System
data double Time series to be predicted.
windowSize int Window size - number of past samples used /// to predict future value.
predictionSize int Prediction size - number of values to be predicted. These /// values are excluded from training set.
constants double Array of constants to be used as additional /// paramters for genetic expression.
return System

Translate() public method

Translates genotype to phenotype.

The method returns string value, which represents prediction expression written in polish postfix notation.

The interpretation of the prediction expression is very simple. For example, let's take a look at sample expression, which was received with window size equal to 5: $0 $1 - $5 / $2 * The above expression in postfix polish notation should be interpreted as a next expression: ( ( x[t - 1] - x[t - 2] ) / const1 ) * x[t - 3]

public Translate ( IChromosome chromosome ) : string
chromosome IChromosome Chromosome, which genoteype should be /// translated to phenotype.
return string