C# Class Accord.Genetic.OptimizationFunction1D

Base class for one dimensional function optimizations.

The class is aimed to be used for one dimensional function optimization problems. It implements all methods of IFitnessFunction interface and requires overriding only one method - OptimizationFunction, which represents the function to optimize.

The optimization function should be greater than 0 on the specified optimization range.

The class works only with binary chromosomes (BinaryChromosome).

Sample usage:

// define optimization function public class UserFunction : OptimizationFunction1D { public UserFunction( ) : base( new Range( 0, 255 ) ) { } public override double OptimizationFunction( double x ) { return Math.Cos( x / 23 ) * Math.Sin( x / 50 ) + 2; } } ... // create genetic population Population population = new Population( 40, new BinaryChromosome( 32 ), new UserFunction( ), new EliteSelection( ) ); while ( true ) { // run one epoch of the population population.RunEpoch( ); // ... }
Inheritance: IFitnessFunction
Show file Open project: accord-net/framework

Public Methods

Method Description
Evaluate ( IChromosome chromosome ) : double

Evaluates chromosome.

The method calculates fitness value of the specified chromosome.

OptimizationFunction ( double x ) : double

Function to optimize.

The method should be overloaded by inherited class to specify the optimization function.

OptimizationFunction1D ( Range range ) : System

Initializes a new instance of the OptimizationFunction1D class.

Translate ( IChromosome chromosome ) : double

Translates genotype to phenotype.

The method returns double value, which represents function's input point encoded by the specified chromosome.

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

OptimizationFunction() public abstract method

Function to optimize.
The method should be overloaded by inherited class to specify the optimization function.
public abstract OptimizationFunction ( double x ) : double
x double Function's input value.
return double

OptimizationFunction1D() public method

Initializes a new instance of the OptimizationFunction1D class.
public OptimizationFunction1D ( Range range ) : System
range AForge.Range Specifies range for optimization.
return System

Translate() public method

Translates genotype to phenotype.
The method returns double value, which represents function's input point encoded by the specified chromosome.
public Translate ( IChromosome chromosome ) : double
chromosome IChromosome Chromosome, which genoteype should be /// translated to phenotype.
return double