Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/10/17 00:27:31 (7 years ago)
Author:
pkimmesw
Message:

#2665 LexicaseSelector, Performance improvements, UI Fixes, Debugger only shows used stacks, fixed Debugger stepping, Added vector expressions, ERCOptions,

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/PushEvaluator.cs

    r14777 r14834  
    66  using HeuristicLab.BenchmarkSuite.Problems;
    77  using HeuristicLab.Core;
    8   using HeuristicLab.Optimization;
    98  using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions;
    109  using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter;
     
    1918      interpreter.Run(program);
    2019
    21       return GetDiff(example.OutputInt, interpreter.IntegerStack, worstResult, LongDiffer)
    22            + GetDiff(example.OutputFloat, interpreter.FloatStack, worstResult, DoubleDiffer)
    23            + GetDiff(example.OutputBoolean, interpreter.BooleanStack, worstResult, BooleanDiffer);
     20      var result = GetDiff(example.OutputInt, interpreter.IntegerStack, worstResult, LongDiffer)
     21                 + GetDiff(example.OutputFloat, interpreter.FloatStack, worstResult, DoubleDiffer)
     22                 + GetDiff(example.OutputBoolean, interpreter.BooleanStack, worstResult, BooleanDiffer);
     23
     24      return result;
    2425    }
    2526
    26     public static double Evaluate(PushProgram program, PushInterpreterPool pool, IRandom random, Data data, int startIndex, int endIndex) {
    27       if (endIndex - startIndex <= 0) return default(double);
    28       var result = 0d;
     27    public static EvaluationResult Evaluate(PushProgram program, PushInterpreterPool pool, IRandom random, Data data, int startIndex, int endIndex) {
     28      var length = endIndex - startIndex;
     29      if (length <= 0) return null;
     30
     31      var evaluationResult = new EvaluationResult(length);
    2932
    3033      using (var interpreter = pool.Create(random)) {
    3134        for (var i = startIndex; i < endIndex; i++) {
    32           result += Evaluate(interpreter, program, data.Examples[i], data.WorstResult);
    33           interpreter.Clear();
     35          var result = Evaluate(interpreter, program, data.Examples[i], data.WorstResult);
     36          evaluationResult.ExampleQualities[i - startIndex] = result;
     37          evaluationResult.TotalQuality += result;
     38          interpreter.Reset();
    3439        }
    3540      }
    3641
    37       return result / (endIndex - startIndex);
     42      evaluationResult.TotalQuality /= length;
     43
     44      return evaluationResult;
    3845    }
    3946
    40     public static double Evaluate(Individual individual, PushInterpreterPool pool, IRandom random, Data data, int startIndex, int endIndex) {
    41       var program = individual.PushProgram(pool.PushGpConfiguration.EnabledExpressions as IReadOnlyList<string>);
    42       return Evaluate(program, pool, random, data, startIndex, endIndex);
    43     }
     47    //public static EvaluationResult Evaluate(Individual individual, PushInterpreterPool pool, IRandom random, Data data, int startIndex, int endIndex) {
     48    //  var program = individual.ToPushProgram(pool.PushGpConfiguration);
     49    //  return Evaluate(program, pool, random, data, startIndex, endIndex);
     50    //}
    4451
    4552    private static double DoubleDiffer(double a, double b) {
    4653      var result = a - b;
    4754
    48       return result == double.MinValue ? double.MaxValue : Math.Abs(result);
     55      if (result == double.MinValue || double.IsPositiveInfinity(result) || double.IsNaN(result))
     56        return double.MaxValue;
     57
     58      if (result == double.MaxValue || double.IsNegativeInfinity(result))
     59        return double.MinValue;
     60
     61      return Math.Abs(result);
    4962    }
    5063
     
    5972    }
    6073
    61     private static double GetDiff<T>(IReadOnlyList<T> estimated, IStack<T> resultStack, double worstResult, Func<T, T, double> differ)
     74    private static double GetDiff<T>(IReadOnlyList<T> estimated, IPushStack<T> resultStack, double worstResult, Func<T, T, double> differ)
    6275      where T : IComparable {
     76      if (estimated.Count == 0) return 0d;
    6377
    64       var count = Math.Min(estimated.Count, resultStack.Count);
    65       var result = resultStack.Peek(count);
    66       var comparableLength = Math.Min(estimated.Count, result.Length);
    6778      var diff = 0d;
     79      var comparableLength = 0;
    6880
    69       for (var i = 0; i < comparableLength; i++) {
    70         diff += Math.Min(differ(estimated[i], result[0]), worstResult);
     81      if (!resultStack.IsEmpty) {
     82        var count = Math.Min(estimated.Count, resultStack.Count);
     83        var result = resultStack.Peek(count);
     84        comparableLength = Math.Min(estimated.Count, result.Length);
     85
     86        for (var i = 0; i < comparableLength; i++) {
     87          diff += Math.Min(differ(estimated[i], result[i]), worstResult);
     88        }
    7189      }
    7290
    73       if (estimated.Count > result.Length) {
    74         diff += worstResult * (estimated.Count - comparableLength);
     91      for (var i = comparableLength; i < estimated.Count - comparableLength; i++) {
     92        diff += differ(estimated[i], default(T));
    7593      }
    7694
Note: See TracChangeset for help on using the changeset viewer.