Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/10/17 21:36:03 (8 years ago)
Author:
pkimmesw
Message:

#2665 Fixed small issues, testet benchmark suite, added INX Expressions

Location:
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem
Files:
4 edited

Legend:

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

    r15032 r15189  
    5353      var example = Evaluator.Data.Examples[exampleComboBox.SelectedIndex];
    5454
    55       interpreter.BooleanStack.Push(example.InputBoolean);
    56       interpreter.IntegerStack.Push(example.InputInteger);
    57       interpreter.FloatStack.Push(example.InputFloat);
    58       interpreter.CharStack.Push(example.InputChar);
    59       interpreter.StringStack.Push(example.InputString);
    60       interpreter.IntegerVectorStack.Push(example.InputIntegerVector.Select(x => x.ToList()).ToArray());
    61       interpreter.FloatVectorStack.Push(example.InputFloatVector.Select(x => x.ToList()).ToArray());
    62       interpreter.StringVectorStack.Push(example.InputStringVector.Select(x => x.ToList()).ToArray());
    63       interpreter.BooleanVectorStack.Push(example.InputBooleanVector.Select(x => x.ToList()).ToArray());
     55      interpreter.SetInput(
     56        integers: example.InputInteger,
     57        floats: example.InputFloat,
     58        booleans: example.InputBoolean,
     59        chars: example.InputChar,
     60        strings: example.InputString,
     61        integerVectors: example.InputIntegerVector,
     62        floatVectors: example.InputFloatVector,
     63        stringVectors: example.InputStringVector);
     64
     65      //interpreter.BooleanStack.Push(example.InputBoolean);
     66      //interpreter.IntegerStack.Push(example.InputInteger);
     67      //interpreter.FloatStack.Push(example.InputFloat);
     68      //interpreter.CharStack.Push(example.InputChar);
     69      //interpreter.StringStack.Push(example.InputString);
     70      //interpreter.IntegerVectorStack.Push(example.InputIntegerVector.Select(x => x.ToList()).ToList());
     71      //interpreter.FloatVectorStack.Push(example.InputFloatVector.Select(x => x.ToList()).ToList());
     72      //interpreter.StringVectorStack.Push(example.InputStringVector.Select(x => x.ToList()).ToList());
     73      //interpreter.BooleanVectorStack.Push(example.InputBooleanVector.Select(x => x.ToList()).ToList());
    6474    }
    6575
     
    198208            var type = data.OutputArgumentTypes[j];
    199209            var offset = outputArgumentCountDict[type];
     210
     211            // estimated
    200212            row.Cells[data.InputArgumentTypes.Length + j * 2].Value = ViewHelper.StringifyOutput(type, offset, Content.Config.FloatStringFormat, example, Separator);
     213
     214            // output
    201215            row.Cells[data.InputArgumentTypes.Length + j * 2 + 1].Value = StringifyResult(type, offset, pushInterpreter, example, Separator);
     216
    202217            outputArgumentCountDict[type]++;
    203218          }
     
    243258
    244259        case ExampleArgumentType.Print:
    245           return string.Join(valueSeparator, string.Join(PushEnvironment.NewLine, interpreter.PrintStack.Take(example.OutputPrintLineCount)));
     260          return string.Join(valueSeparator, string.Join(PushEnvironment.NewLine, interpreter.PrintStack.AsStrings().Take(example.OutputPrintLineCount)));
    246261
    247262        case ExampleArgumentType.String:
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/BenchmarkSuite/PushBenchmarkSuiteEvaluator.cs

    r15017 r15189  
    22  using System;
    33  using System.Collections.Generic;
     4  using System.Globalization;
    45  using System.Linq;
    56
     
    130131      var example = Data.Examples[exampleIndex];
    131132
    132       interpreter.BooleanStack.Push(example.InputBoolean);
    133       interpreter.IntegerStack.Push(example.InputInteger);
    134       interpreter.FloatStack.Push(example.InputFloat);
    135       interpreter.CharStack.Push(example.InputChar);
    136       interpreter.StringStack.Push(example.InputString);
    137       interpreter.StringVectorStack.Push(example.InputStringVector);
    138       interpreter.IntegerVectorStack.Push(example.InputIntegerVector);
    139       interpreter.FloatVectorStack.Push(example.InputFloatVector);
     133      //interpreter.BooleanStack.Push(example.InputBoolean);
     134      //interpreter.IntegerStack.Push(example.InputInteger);
     135      //interpreter.FloatStack.Push(example.InputFloat);
     136      //interpreter.CharStack.Push(example.InputChar);
     137      //interpreter.StringStack.Push(example.InputString);
     138      //interpreter.StringVectorStack.Push(example.InputStringVector);
     139      //interpreter.IntegerVectorStack.Push(example.InputIntegerVector);
     140      //interpreter.FloatVectorStack.Push(example.InputFloatVector);
     141
     142      interpreter.SetInput(
     143        integers: example.InputInteger,
     144        floats: example.InputFloat,
     145        booleans: example.InputBoolean,
     146        chars: example.InputChar,
     147        strings: example.InputString,
     148        integerVectors: example.InputIntegerVector,
     149        floatVectors: example.InputFloatVector,
     150        stringVectors: example.InputStringVector);
    140151
    141152      interpreter.Run(program);
    142153
    143154      switch (Data.ProblemType) {
    144         //case ProblemType.NumberIO:
    145         //  if (interpreter.PrintStack.IsEmpty)
    146         //    return Data.WorstResult;
    147 
    148         //  double value;
    149         //  var levenshteinDistance = GetPrintDiffer(example.OutputPrint, interpreter.PrintStack, example.OutputPrintLineCount, Data.WorstResult);
    150         //  return levenshteinDistance + (double.TryParse(interpreter.PrintStack.Top, out value)
    151         //    ? FloatDiffer(value, example.OutputFloat[0], example.OutputFloatPrecision)
    152         //    : Data.WorstResult / 2);
    153 
    154         case ProblemType.Median: return interpreter.PrintStack.IsEmpty ? 1 : interpreter.PrintStack.Top.Equals(example.OutputPrint) ? 0 : 1;
    155       }
    156 
     155        case ProblemType.NumberIO: return NumberIo(interpreter, example);
     156        case ProblemType.Median: return Median(interpreter, example);
     157      }
     158
     159      return Default(interpreter, example);
     160    }
     161
     162    private double Default(IPushInterpreter interpreter, Example example) {
    157163      var result = GetDiff(example.OutputInteger, interpreter.IntegerStack, Data.WorstResult, IntegerDiffer)
    158                  + GetDiff(example.OutputFloat, interpreter.FloatStack, Data.WorstResult, (a, b) => FloatDiffer(a, b, example.OutputFloatPrecision))
    159                  + GetDiff(example.OutputBoolean, interpreter.BooleanStack, Data.WorstResult, BooleanDiffer)
    160                  + GetDiff(example.OutputString, interpreter.StringStack, Data.WorstResult, StringDiffer)
    161                  + GetDiff(example.OutputChar, interpreter.CharStack, Data.WorstResult, CharDiffer)
    162                  + GetPrintDiffer(example.OutputPrint, interpreter.PrintStack, example.OutputPrintLineCount, Data.WorstResult)
    163                  + GetVectorDiff(example.OutputIntegerVector, interpreter.IntegerVectorStack, Data.WorstResult, (a, b) => VectorDiffer(a, b, IntegerDiffer))
    164                  + GetVectorDiff(example.OutputFloatVector, interpreter.FloatVectorStack, Data.WorstResult, (a, b) => VectorDiffer(a, b, (x, y) => FloatDiffer(x, y, example.OutputFloatVectorPrecision)))
    165                  + GetVectorDiff(example.OutputStringVector, interpreter.StringVectorStack, Data.WorstResult, (a, b) => VectorDiffer(a, b, StringDiffer));
     164             + GetDiff(example.OutputFloat, interpreter.FloatStack, Data.WorstResult, (a, b) => FloatDiffer(a, b, example.OutputFloatPrecision))
     165             + GetDiff(example.OutputBoolean, interpreter.BooleanStack, Data.WorstResult, BooleanDiffer)
     166             + GetDiff(example.OutputString, interpreter.StringStack, Data.WorstResult, StringDiffer)
     167             + GetDiff(example.OutputChar, interpreter.CharStack, Data.WorstResult, CharDiffer)
     168             + GetPrintDiffer(example.OutputPrint, interpreter.PrintStack, example.OutputPrintLineCount, Data.WorstResult)
     169             + GetVectorDiff(example.OutputIntegerVector, interpreter.IntegerVectorStack, Data.WorstResult, (a, b) => VectorDiffer(a, b, IntegerDiffer))
     170             + GetVectorDiff(example.OutputFloatVector, interpreter.FloatVectorStack, Data.WorstResult, (a, b) => VectorDiffer(a, b, (x, y) => FloatDiffer(x, y, example.OutputFloatVectorPrecision)))
     171             + GetVectorDiff(example.OutputStringVector, interpreter.StringVectorStack, Data.WorstResult, (a, b) => VectorDiffer(a, b, StringDiffer));
    166172
    167173      return result;
     174    }
     175
     176    private double Median(IPushInterpreter interpreter, Example example) {
     177      return interpreter.PrintStack.IsEmpty || !interpreter.PrintStack.Top.Equals(example.OutputPrint) ? 1 : 0;
     178    }
     179
     180    private double NumberIo(IPushInterpreter interpreter, Example example) {
     181      if (interpreter.PrintStack.IsEmpty)
     182        return Data.WorstResult;
     183
     184      double value;
     185      if (double.TryParse(interpreter.PrintStack.Top, NumberStyles.Number | NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out value)) {
     186        var diff = Math.Abs(example.OutputFloat[0] - value);
     187        var result = Math.Min(diff, Data.WorstResult);
     188
     189        return result;
     190      }
     191
     192      var penaltyError = Data.WorstResult / 4.0d;
     193      var levenshteinDistance = GetPrintDiffer(
     194        example.OutputPrint,
     195        interpreter.PrintStack.Top,
     196        Data.WorstResult);
     197
     198      return levenshteinDistance + penaltyError;
    168199    }
    169200
     
    217248    }
    218249
     250    private static double GetPrintDiffer(string estimated, string printResult, double worstResult) {
     251      var distance = LevenshteinDistance(estimated, printResult);
     252
     253      return Math.Min(distance, worstResult);
     254    }
     255
    219256    private static double GetPrintDiffer(string estimated, IPushStack<string> printStack, int estimatedCount, double worstResult) {
    220       var printResult = string.Join(PushEnvironment.NewLine, printStack.Take(estimatedCount));
     257      var printResult = string.Join(PushEnvironment.NewLine, printStack.AsStrings().Take(estimatedCount));
    221258      var distance = LevenshteinDistance(estimated, printResult);
    222259
     
    234271        var count = Math.Min(estimated.Count, resultStack.Count);
    235272        var result = resultStack.Peek(count);
    236         comparableLength = Math.Min(estimated.Count, result.Length);
     273        comparableLength = Math.Min(estimated.Count, result.Count);
    237274
    238275        for (var i = 0; i < comparableLength; i++) {
     
    259296        var count = Math.Min(estimated.Count, resultStack.Count);
    260297        var result = resultStack.Peek(count);
    261         comparableLength = Math.Min(estimated.Count, result.Length);
     298        comparableLength = Math.Min(estimated.Count, result.Count);
    262299
    263300        for (var i = 0; i < comparableLength; i++) {
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/BenchmarkSuite/PushBenchmarkSuiteProblem.cs

    r15032 r15189  
    11namespace HeuristicLab.Problems.ProgramSynthesis.Push.Problem.BenchmarkSuite {
     2
    23  using Common;
    34  using Configuration;
     
    78  using HeuristicLab.BenchmarkSuite.Problems;
    89  using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions;
     10  using HeuristicLab.Problems.ProgramSynthesis.Push.Extensions;
    911
    1012  using Instances;
     
    5355
    5456      config.SetEnabledStacks((StackTypes)data.EnabledDataTypes);
     57      data.InitInExpressions(config);
    5558
    5659      Encoding.Bounds[0, 0] = 0;
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/PushProblem.cs

    r15032 r15189  
    1212  using HeuristicLab.Problems.ProgramSynthesis.Push.Analyzer;
    1313  using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions;
     14  using HeuristicLab.Problems.ProgramSynthesis.Push.Individual;
    1415  using HeuristicLab.Problems.ProgramSynthesis.Push.Problem.BenchmarkSuite;
    1516
     
    125126      // clear pools and free reserved memory
    126127      pool.Clear();
     128      IndividualMapper.Clear();
    127129    }
    128130
     
    158160
    159161    public override void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) {
     162      IndividualMapper.Reset();
     163
    160164      var bestQuality = Maximization ? qualities.Max() : qualities.Min();
    161165      var bestIdx = Array.IndexOf(qualities, bestQuality);
     
    165169      rand.Reset(seed);
    166170
    167       var program = vector.ToPushProgram(config, rand);
     171      var program = (PushProgram)vector.ToPushProgram(config, rand).Clone();
    168172      var isIndividualBetter = AnalyzeBestTrainingSolution(program, bestQuality, results, rand);
    169173
Note: See TracChangeset for help on using the changeset viewer.