Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/28/17 09:03:34 (7 years ago)
Author:
pkimmesw
Message:

#2665 Testet Problems, Improved Performance

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Evaluator/PushBenchmarkSuiteEvaluator.cs

    r15334 r15341  
    156156
    157157        // float error
    158         case ProblemType.VectorAverage: return GetDiff(example.OutputFloat, interpreter.FloatStack, Data.WorstResult, (a, b) => FloatDiffer(a, b, example.OutputFloatPrecision));
     158        case ProblemType.VectorAverage: return GetDiff(example.OutputFloat, interpreter.FloatStack, Data.WorstResult, (a, b) => FloatDiffer(a, b, example.OutputFloatPrecision, Data.WorstResult));
    159159
    160160        // integer error
     
    184184    private double Default(IPushInterpreter interpreter, Example example) {
    185185      var integerDiff = GetDiff(example.OutputInteger, interpreter.IntegerStack, Data.WorstResult, IntegerDiffer);
    186       var floatDiff = GetDiff(example.OutputFloat, interpreter.FloatStack, Data.WorstResult, (a, b) => FloatDiffer(a, b, example.OutputFloatPrecision));
     186      var floatDiff = GetDiff(example.OutputFloat, interpreter.FloatStack, Data.WorstResult, (a, b) => FloatDiffer(a, b, example.OutputFloatPrecision, Data.WorstResult));
    187187      var booleanDiff = GetDiff(example.OutputBoolean, interpreter.BooleanStack, Data.WorstResult, BooleanDiffer);
    188188      var stringDiff = GetDiff(example.OutputString, interpreter.StringStack, Data.WorstResult, StringDiffer);
     
    190190      var printDiff = GetPrintDiffer(example.OutputPrint, interpreter.PrintStack, Data.WorstResult);
    191191      var integerVectorDiff = GetVectorDiff(example.OutputIntegerVector, interpreter.IntegerVectorStack, Data.WorstResult, (a, b) => VectorDiffer(a, b, IntegerDiffer));
    192       var floatVectorDiff = GetVectorDiff(example.OutputFloatVector, interpreter.FloatVectorStack, Data.WorstResult, (a, b) => VectorDiffer(a, b, (x, y) => FloatDiffer(x, y, example.OutputFloatVectorPrecision)));
     192      var floatVectorDiff = GetVectorDiff(example.OutputFloatVector, interpreter.FloatVectorStack, Data.WorstResult, (a, b) => VectorDiffer(a, b, (x, y) => FloatDiffer(x, y, example.OutputFloatVectorPrecision, Data.WorstResult)));
    193193      var stringVectorDiff = GetVectorDiff(example.OutputStringVector, interpreter.StringVectorStack, Data.WorstResult, (a, b) => VectorDiffer(a, b, StringDiffer));
    194194
     
    315315        return Data.WorstResult;
    316316
    317       var floatDiff = GetDiff(example.OutputFloat, interpreter.FloatStack, Data.WorstResult, (a, b) => FloatDiffer(a, b, example.OutputFloatPrecision));
     317      var floatDiff = GetDiff(example.OutputFloat, interpreter.FloatStack, Data.WorstResult, (a, b) => FloatDiffer(a, b, example.OutputFloatPrecision, Data.WorstResult));
    318318      var expectedStr = example.OutputFloat[0].ToString(Data.FloatStringFormat, CultureInfo.CurrentCulture);
    319319      var resultStr = interpreter.FloatStack.TopOrDefault.ToString(Data.FloatStringFormat, CultureInfo.CurrentCulture);
     
    480480    }
    481481
    482     private static double FloatDiffer(double a, double b, int digits) {
     482    private static double FloatDiffer(double a, double b, int digits, double worst) {
    483483      var result = Math.Round(a, digits) - Math.Round(b, digits);
    484484
    485485      // ReSharper disable once CompareOfFloatsByEqualityOperator
    486       if (result == double.MinValue || double.IsPositiveInfinity(result) || double.IsNaN(result))
    487         return double.MaxValue;
    488 
    489       // ReSharper disable once CompareOfFloatsByEqualityOperator
    490       if (result == double.MaxValue || double.IsNegativeInfinity(result))
    491         return double.MinValue;
     486      if (result == double.MinValue || double.IsPositiveInfinity(result) ||
     487          double.IsNaN(result) ||
     488          result == double.MaxValue || double.IsNegativeInfinity(result))
     489        return worst;
    492490
    493491      return Math.Abs(result);
     
    545543      where T : IComparable {
    546544      if (estimated.Count == 0) return 0d;
     545      if (resultStack.IsEmpty && estimated.Count > 0) return worstResult;
    547546
    548547      var diff = 0d;
     
    551550      if (!resultStack.IsEmpty) {
    552551
    553         for (var i = 0; i < comparableLength; i++) {
    554           diff += Math.Min(differ(estimated[i], resultStack[i]), worstResult);
     552        for (var i = 0; i < comparableLength && diff < worstResult; i++) {
     553          diff += differ(estimated[i], resultStack[i]);
    555554        }
    556555      }
    557556
    558557      var emptyTArray = new T[0];
    559       for (var i = comparableLength; i < estimated.Count - comparableLength; i++) {
     558      for (var i = comparableLength; i < estimated.Count - comparableLength && diff < worstResult; i++) {
    560559        diff += differ(estimated[i], emptyTArray);
    561560      }
     
    567566      where T : IComparable {
    568567      if (estimated.Count == 0) return 0d;
     568      if (resultStack.IsEmpty && estimated.Count > 0) return worstResult;
    569569
    570570      var diff = 0d;
     
    572572
    573573      if (!resultStack.IsEmpty) {
    574         for (var i = 0; i < comparableLength; i++) {
    575           diff += Math.Min(differ(estimated[i], resultStack[i]), worstResult);
     574        for (var i = 0; i < comparableLength && diff < worstResult; i++) {
     575          diff += differ(estimated[i], resultStack[i]);
    576576        }
    577577      }
    578578
    579       for (var i = comparableLength; i < estimated.Count - comparableLength; i++) {
     579      for (var i = comparableLength; i < estimated.Count - comparableLength && diff < worstResult; i++) {
    580580        diff += differ(estimated[i], default(T));
    581581      }
Note: See TracChangeset for help on using the changeset viewer.