AForge.Genetic.SymbolicRegressionFitness.Evaluate C# (CSharp) Метод

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

Evaluates chromosome.
The method calculates fitness value of the specified chromosome.
public Evaluate ( IChromosome chromosome ) : double
chromosome IChromosome Chromosome to evaluate.
Результат double
        public double Evaluate( IChromosome chromosome )
        {
            // get function in polish notation
            string function = chromosome.ToString( );

            // go through all the data
            double error = 0.0;
            for ( int i = 0, n = data.GetLength( 0 ); i < n; i++ )
            {
                // put next X value to variables list
                variables[0] = data[i, 0];
                // avoid evaluation errors
                try
                {
                    // evalue the function
                    double y = PolishExpression.Evaluate( function, variables );
                    // check for correct numeric value
                    if ( double.IsNaN( y ) )
                        return 0;
                    // get the difference between evaluated Y and real Y
                    // and sum error
                    error += Math.Abs( y - data[i, 1] );
                }
                catch
                {
                    return 0;
                }
            }

            // return optimization function value
            return 100.0 / ( error + 1 );
        }