Пример #1
0
 private static List <Tree <string> > CalculateFitness(List <Tuple <List <float>, float> > data, List <Tree <string> > population, string[] terminals)
 {
     foreach (Tree <string> individual in population)
     {
         IOperand op = Evaluate(individual, terminals);
         double   totalError = 0, err = 0;
         foreach (Tuple <List <float>, float> tuple in data)
         {
             double estimate = op.Compute(tuple.Item1.Select(d => (double)d).ToArray());
             err         = Math.Abs(estimate - tuple.Item2);
             totalError += err;
         }
         if (double.IsNaN(totalError) || double.IsInfinity(totalError))
         {
             individual.Fitness = double.MaxValue;
         }
         else
         {
             individual.Fitness = totalError / data.Count;
         }
         if (totalError <= 0.1)
         {
         }
     }
     return(population.OrderBy(ind => ind.Fitness).ToList());
 }