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

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

Legend:

Unmodified
Added
Removed
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Configuration/IReadonlyPushConfiguration.cs

    r15334 r15341  
    11namespace HeuristicLab.Problems.ProgramSynthesis.Push.Configuration {
     2
    23  using Base.Erc;
    34
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Configuration/PushConfiguration.cs

    r15334 r15341  
    9696          MIN_PROGRAM_LENGTH,
    9797          MIN_PROGRAM_LENGTH_PARAMETER_DESCRIPTION,
    98           new IntValue(0)) { Hidden = true });
     98          new IntValue(0)) { Hidden = false });
    9999
    100100      if (!Parameters.ContainsKey(MAX_CLOSE_PARAMETER_NAME))
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Encoding/PlushEncoding.cs

    r15334 r15341  
    2525
    2626    public PlushEncoding(string name) : base(name) {
    27       minLengthParameter = new FixedValueParameter<IntValue>(Name + ".MinLength", new IntValue(25));
    28       maxLengthParameter = new FixedValueParameter<IntValue>(Name + ".MaxLength", new IntValue(100));
    29       maxCloseParameter = new FixedValueParameter<IntValue>(Name + ".MaxClose", new IntValue(3));
    30       closeBiasLevelParameter = new FixedValueParameter<DoubleValue>(Name + ".CloseBiasLevel", new DoubleValue(3d));
    31       instructionsParameter = new ValueParameter<IExpressionsConfiguration>(Name + ".Instructions");
    32       ercOptionsParameter = new ValueParameter<ErcOptions>(Name + ".ErcOptions");
    33       inInstructionProbabilityParameter = new FixedValueParameter<PercentValue>(Name + ".InInstructionProbability", new PercentValue(0.1));
    34 
    35       Parameters.Add(minLengthParameter);
    36       Parameters.Add(maxLengthParameter);
    37       Parameters.Add(maxCloseParameter);
    38       Parameters.Add(closeBiasLevelParameter);
    39       Parameters.Add(instructionsParameter);
    40       Parameters.Add(ercOptionsParameter);
    41       Parameters.Add(inInstructionProbabilityParameter);
     27      InitParameters();
    4228
    4329      SolutionCreator = new PlushCreator();
     
    4632    }
    4733
     34    [StorableConstructor]
    4835    public PlushEncoding(bool deserializing)
    4936      : base(deserializing) {
     
    5441      minLengthParameter = cloner.Clone(original.minLengthParameter);
    5542      maxLengthParameter = cloner.Clone(original.maxLengthParameter);
     43      maxCloseParameter = cloner.Clone(original.maxCloseParameter);
     44      closeBiasLevelParameter = cloner.Clone(original.closeBiasLevelParameter);
     45      instructionsParameter = cloner.Clone(original.instructionsParameter);
     46      ercOptionsParameter = cloner.Clone(original.ercOptionsParameter);
     47      inInstructionProbabilityParameter = cloner.Clone(original.inInstructionProbabilityParameter);
     48
     49      RegisterParameterEvents();
    5650    }
    5751
    5852    [StorableHook(HookType.AfterDeserialization)]
    5953    private void AfterDeserialization() {
     54      InitParameters();
    6055      RegisterParameterEvents();
    6156      DiscoverOperators();
     
    6459    public override IDeepCloneable Clone(Cloner cloner) {
    6560      return new PlushEncoding(this, cloner);
     61    }
     62
     63    private void InitParameters() {
     64      if (!Parameters.ContainsKey(Name + ".MinLength")) {
     65        minLengthParameter = new FixedValueParameter<IntValue>(Name + ".MinLength", new IntValue(0));
     66        Parameters.Add(minLengthParameter);
     67      }
     68
     69      if (!Parameters.ContainsKey(Name + ".MaxLength")) {
     70        maxLengthParameter = new FixedValueParameter<IntValue>(Name + ".MaxLength", new IntValue(100));
     71        Parameters.Add(maxLengthParameter);
     72      }
     73
     74      if (!Parameters.ContainsKey(Name + ".MaxClose")) {
     75        maxCloseParameter = new FixedValueParameter<IntValue>(Name + ".MaxClose", new IntValue(3));
     76        Parameters.Add(maxCloseParameter);
     77      }
     78
     79      if (!Parameters.ContainsKey(Name + ".CloseBiasLevel")) {
     80        closeBiasLevelParameter = new FixedValueParameter<DoubleValue>(Name + ".CloseBiasLevel", new DoubleValue(3d));
     81        Parameters.Add(closeBiasLevelParameter);
     82      }
     83
     84      if (!Parameters.ContainsKey(Name + ".Instructions")) {
     85        instructionsParameter = new ValueParameter<IExpressionsConfiguration>(Name + ".Instructions");
     86        Parameters.Add(instructionsParameter);
     87      }
     88
     89      if (!Parameters.ContainsKey(Name + ".ErcOptions")) {
     90        ercOptionsParameter = new ValueParameter<ErcOptions>(Name + ".ErcOptions");
     91        Parameters.Add(ercOptionsParameter);
     92      }
     93
     94      if (!Parameters.ContainsKey(Name + ".InInstructionProbability")) {
     95        inInstructionProbabilityParameter = new FixedValueParameter<PercentValue>(Name + ".InInstructionProbability", new PercentValue(0.1));
     96        Parameters.Add(inInstructionProbabilityParameter);
     97      }
    6698    }
    6799
  • 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      }
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/ExpressionTable.cs

    r15334 r15341  
    175175
    176176    public static Expression GetStatelessExpression<T>() where T : StatelessExpression {
    177       return GetStatelessExpression(typeToNameTable[typeof(T)]);
     177      Expression expression;
     178      var type = typeof(T);
     179
     180      if (StatelessExpressionTable.TryGetValue(type, out expression))
     181        return expression;
     182
     183      throw new NotSupportedException("Expression not supported: " + type.Name);
    178184    }
    179185
    180186    public static Expression GetStatelessExpression(string name) {
    181       if (NameToTypeTable.ContainsKey(name) && StatelessExpressionTable.ContainsKey(NameToTypeTable[name]))
    182         return StatelessExpressionTable[NameToTypeTable[name]];
     187      Type type;
     188      Expression expression;
     189
     190      if (NameToTypeTable.TryGetValue(name, out type) && StatelessExpressionTable.TryGetValue(type, out expression))
     191        return expression;
     192
    183193      throw new NotSupportedException("Expression not supported: " + name);
    184194    }
    185195
    186196    public static bool TryGetStatelessExpression(string name, out Expression expression) {
    187       if (!NameToTypeTable.ContainsKey(name) || !StatelessExpressionTable.ContainsKey(NameToTypeTable[name])) {
     197      Type type;
     198      if (!NameToTypeTable.TryGetValue(name, out type) || !StatelessExpressionTable.TryGetValue(type, out expression)) {
    188199        expression = null;
    189200        return false;
    190201      }
    191202
    192       expression = StatelessExpressionTable[NameToTypeTable[name]];
    193203      return true;
    194204    }
     
    199209
    200210    public static Expression GetStatefulExpression(string name) {
    201       if (NameToTypeTable.ContainsKey(name)) {
    202         Func<Expression> creator;
    203         var type = NameToTypeTable[name];
    204 
    205         if (StatefulExpressionFactory.TryGetValue(type, out creator))
    206           return creator();
     211      Type type;
     212      Func<Expression> creator;
     213
     214      if (NameToTypeTable.TryGetValue(name, out type) && StatefulExpressionFactory.TryGetValue(type, out creator)) {
     215        return creator();
    207216      }
    208217
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/FloatExpressions.cs

    r15334 r15341  
    449449      return interpreter.StringStack.IsEmpty ||
    450450             interpreter.StringStack.Top.Length == 0 ||
    451              !double.TryParse(interpreter.StringStack.Top, out tmp);
     451             !double.TryParse(
     452               interpreter.StringStack.Top,
     453               NumberStyles.AllowDecimalPoint | NumberStyles.Float,
     454               CultureInfo.InvariantCulture,
     455               out tmp);
    452456    }
    453457
    454458    public override void Eval(IInternalPushInterpreter interpreter) {
    455459      var str = interpreter.StringStack.Pop();
    456       var value = double.Parse(str, CultureInfo.InvariantCulture);
     460      var value = double.Parse(str, NumberStyles.AllowDecimalPoint | NumberStyles.Float, CultureInfo.InvariantCulture);
    457461
    458462      interpreter.FloatStack.Push(value);
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/PushInterpreter.cs

    r15334 r15341  
    1717  public class PushInterpreter : IInternalPushInterpreter, IDisposable {
    1818    private Task currentTask;
    19     private Expression currentProgram;
     19    private int evalPushLimit;
    2020
    2121    /// <summary>
     
    3030      Configuration = config ?? new PushConfiguration();
    3131
    32       // setting the capacity of the Stacks to max points ensures that there will be enough memory at runtime
    3332      ExecStack = new PushStack<Expression>(Configuration.MaxProgramLength);
    3433      CodeStack = new PushStack<Expression>();
     
    6665      PoolContainer = poolContainer ?? new InterpreterPoolContainer();
    6766
     67      InitEvalPushLimit();
    6868      ConfigureStacks();
    6969    }
     
    9292               !IsPaused &&
    9393               !IsAborted &&
    94                (ExecCounter < Configuration.EvalPushLimit);
     94               (ExecCounter < evalPushLimit);
    9595      }
    9696    }
     
    261261    public void Run(Expression expression, bool stepwise = false) {
    262262      IsPaused = stepwise;
    263       currentProgram = expression;
    264263
    265264      /* Push top expression so the loop is able to enter
     
    347346      Random = (IRandom)randomOrigin.Clone();
    348347
     348      InitEvalPushLimit();
     349
    349350      ExecCounter = 0;
    350351      IsAborted = false;
    351352      IsPaused = false;
    352353      currentTask = null;
    353       currentProgram = null;
    354354
    355355      inputExpressions.Clear();
    356356      ClearStacks();
    357357      ConfigureStacks();
     358    }
     359
     360    private void InitEvalPushLimit() {
     361      // evalPushLimit is accessed very often and using the getter of the configuration object is rather expensive as the values is capsuled within a parameter
     362      evalPushLimit = Configuration.EvalPushLimit;
     363    }
     364
     365    private void EvalPushLimitChanged(object sender, EventArgs e) {
     366      this.evalPushLimit = Configuration.EvalPushLimit;
    358367    }
    359368
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/PushInterpreterPool.cs

    r15334 r15341  
    3333
    3434    public PooledPushInterpreter Create(IRandom random = null) {
    35       //var interpreter = pool.Allocate();
    36       //interpreter.Reset(random);
    37 
    38       var poolContainer = new InterpreterPoolContainer(PushProgramPoolProvider, ExpressionListPoolProvider);
    39       var interpreter = new PooledPushInterpreter(this, PushConfiguration, poolContainer, random);
     35      var interpreter = pool.Allocate();
     36      interpreter.Reset(random);
    4037
    4138      return interpreter;
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/IntegerVectorPushProblem.cs

    r15334 r15341  
    5959      Encoding.Bounds[0, 0] = 0;
    6060      Encoding.Bounds[0, 1] = Config.EnabledExpressions.Count;
    61       Encoding.Length = Config.MaxProgramLength;
    6261    }
    6362
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/PlushPushProblem.cs

    r15334 r15341  
    11namespace HeuristicLab.Problems.ProgramSynthesis.Push.Problem {
     2  using System.Diagnostics;
    23  using System.Linq;
    34
     
    2930      Encoding.ErcOptionsParameter = Config.ErcOptionsParameter;
    3031      Encoding.InstructionsParameter = Config.InstructionsParameter;
    31       Encoding.MinLengthParameter = Config.MinProgramLengthParameter;
    32       Encoding.MaxLengthParameter = Config.MaxProgramLengthParameter;
    3332      Encoding.MaxCloseParameter = Config.MaxCloseParameter;
    3433      Encoding.CloseBiasLevelParameter = Config.CloseBiasLevelParameter;
     
    4948      var program = plushVector.PushProgram;
    5049
     50      if (program == null)
     51        Debugger.Break();
     52
    5153      return program;
    5254    }
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Stack/PrintStack.cs

    r15334 r15341  
    3636      get
    3737      {
    38         if (stringBuilder.Length == length) return lines;
     38        if (lines != null && stringBuilder.Length == length)
     39          return lines;
     40
    3941        length = stringBuilder.Length;
    4042        lines = stringBuilder.ToString().Split(PushEnvironment.NewLine);
Note: See TracChangeset for help on using the changeset viewer.