当前位置: 首页>>代码示例>>C#>>正文


C# IChromosome.ToString方法代码示例

本文整理汇总了C#中IChromosome.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# IChromosome.ToString方法的具体用法?C# IChromosome.ToString怎么用?C# IChromosome.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IChromosome的用法示例。


在下文中一共展示了IChromosome.ToString方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Evaluate

        /// <summary>
        /// Evaluates chromosome.
        /// </summary>
        /// 
        /// <param name="chromosome">Chromosome to evaluate.</param>
        /// 
        /// <returns>Returns chromosome's fitness value.</returns>
        ///
        /// <remarks>The method calculates fitness value of the specified
        /// chromosome.</remarks>
        ///
        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 );
        }
开发者ID:ArtemAdamenko,项目名称:ANNBuilder-Genetic,代码行数:43,代码来源:SymbolicRegressionFitness.cs

示例2: Translate

 /// <summary>
 /// Translates genotype to phenotype .
 /// </summary>
 /// 
 /// <param name="chromosome">Chromosome, which genoteype should be
 /// translated to phenotype.</param>
 ///
 /// <returns>Returns chromosome's fenotype - the actual solution
 /// encoded by the chromosome.</returns> 
 /// 
 /// <remarks>The method returns string value, which represents approximation
 /// expression written in polish postfix notation.</remarks>
 ///
 public string Translate( IChromosome chromosome )
 {
     // return polish notation for now ...
     return chromosome.ToString( );
 }
开发者ID:ArtemAdamenko,项目名称:ANNBuilder-Genetic,代码行数:18,代码来源:SymbolicRegressionFitness.cs

示例3: Evaluate

        /// <summary>
        /// Evaluates chromosome.
        /// </summary>
        /// 
        /// <param name="chromosome">Chromosome to evaluate.</param>
        /// 
        /// <returns>Returns chromosome's fitness value.</returns>
        ///
        /// <remarks>The method calculates fitness value of the specified
        /// chromosome.</remarks>
        ///
        public double Evaluate( IChromosome chromosome )
        {
            double PROBABLY_ZERO = 1.11E-15;
            double BIG_NUMBER = 1.0e15;

            // get function in polish notation
            string function = chromosome.ToString( );

            //verifica se na expressao gerada possui pelo menos um dado de entrada (x), senao retorna maior numero
            if (function.IndexOf("X", 0) >= 0)
            {

                // 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 = PolishGerExpression.Evaluate(function, variables, i);

                        // check for correct numeric value
                        if ( double.IsNaN( y ) )
                            return BIG_NUMBER; //0;

                        if (!(y < BIG_NUMBER))       // *NOT* (input.x >= BIG_NUMBER)
                            y = BIG_NUMBER;

                        else if (y < PROBABLY_ZERO)  // slightly off
                            y = 0.0;

                        // get the difference between evaluated Y and real Y
                        // and sum error
                        error += Math.Abs( y - data[i, 0] );
                    }
                    catch
                    {
                        return BIG_NUMBER; //0;
                    }
                }

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

            }
            else
            {
                return BIG_NUMBER; //0;
            }
        }
开发者ID:alexanderlimasilva,项目名称:GeradorExpressoes,代码行数:65,代码来源:SymbolicRegressionFitness.cs

示例4: Evaluate

        /// <summary>
        /// Evaluates chromosome.
        /// </summary>
        /// 
        /// <param name="chromosome">Chromosome to evaluate.</param>
        /// 
        /// <returns>Returns chromosome's fitness value.</returns>
        ///
        /// <remarks>The method calculates fitness value of the specified
        /// chromosome.</remarks>
        ///
		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.Length - windowSize - predictionSize; i < n; i++ )
			{
				// put values from current window as variables
				for ( int j = 0, b = i + windowSize - 1; j < windowSize; j++ )
				{
					variables[j] = data[b - j];
				}

				// avoid evaluation errors
				try
				{
					// evaluate the function
					double y = PolishExpression.Evaluate( function, variables );
					// check for correct numeric value
					if ( double.IsNaN( y ) )
						return 0;
					// get the difference between evaluated value and
					// next value after the window, and sum error
					error += Math.Abs( y - data[i + windowSize] );
				}
				catch
				{
					return 0;
				}
			}

			// return optimization function value
			return 100.0 / ( error + 1 );
		}
开发者ID:RevDevBev,项目名称:aforge.net,代码行数:47,代码来源:TimeSeriesPredictionFitness.cs

示例5: Translate

		/// <summary>
		/// Translate genotype to phenotype 
		/// </summary>
		public object Translate( IChromosome chromosome )
		{
			return chromosome.ToString( );
		}
开发者ID:Kenneth-Posey,项目名称:aforge-clone,代码行数:7,代码来源:TSPFitnessFunction.cs

示例6: Evaluate

        //IChromosome
        /// <summary>
        /// Evaluates chromosome.
        /// </summary>
        /// 
        /// <param name="chromosome">Chromosome to evaluate.</param>
        /// 
        /// <returns>Returns chromosome's fitness value.</returns>
        ///
        /// <remarks>The method calculates fitness value of the specified
        /// chromosome.</remarks>
        ///
        public double Evaluate(IChromosome chromosome)
        {
            double PROBABLY_ZERO = 1.11E-15;
            double BIG_NUMBER = 1.0e15;

            // get function in polish notation
            string function = chromosome.ToString( );

            //verifica se na expressao gerada possui pelo menos um dado de entrada (x), senao retorna 0
            if (function.IndexOf("X", 0) >= 0)
            {
                // go through all the data
                double error = 0.0;
                double result = 0.0;
                for (int i = 0, n = data.GetLength(0); i < n; i++)
                {
                    // put next X value to variables list
                    //variables[0] = data[i, 1];

                    // avoid evaluation errors
                    try
                    {
                        // evalue the function
                        double y = PolishGerExpression.Evaluate(function, variables, i);

                        // check for correct numeric value
                        if (double.IsNaN(y))
                           return BIG_NUMBER; //0; y = BIG_NUMBER; //0;

                        //(atual - estimado) / atual
                        result = Math.Abs(data[i, 0] - y) / (data[i, 0]);

                        if (!(result < BIG_NUMBER))  // *NOT* (input.x >= BIG_NUMBER)
                            result = BIG_NUMBER;

                        else if (result < PROBABLY_ZERO)  // slightly off
                            result = 0.0;

                        error += result;
                        //System.Console.WriteLine(i + " function: " + function + " erro: " + error);
                    }
                    catch
                    {
                        return BIG_NUMBER; //0;
                    }
                }

                // return function average value
                // System.Console.WriteLine(" Media erro: " + error / data.GetLength(0));
                return (error / data.GetLength(0));

            }
            else
            {
                return BIG_NUMBER; //0;
            }
        }
开发者ID:alexanderlimasilva,项目名称:GeradorExpressoes,代码行数:69,代码来源:MMREFitness.cs


注:本文中的IChromosome.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。