- Timestamp:
- 08/28/17 09:03:34 (7 years ago)
- 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 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Configuration { 2 2 3 using Base.Erc; 3 4 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Configuration/PushConfiguration.cs
r15334 r15341 96 96 MIN_PROGRAM_LENGTH, 97 97 MIN_PROGRAM_LENGTH_PARAMETER_DESCRIPTION, 98 new IntValue(0)) { Hidden = true });98 new IntValue(0)) { Hidden = false }); 99 99 100 100 if (!Parameters.ContainsKey(MAX_CLOSE_PARAMETER_NAME)) -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Encoding/PlushEncoding.cs
r15334 r15341 25 25 26 26 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(); 42 28 43 29 SolutionCreator = new PlushCreator(); … … 46 32 } 47 33 34 [StorableConstructor] 48 35 public PlushEncoding(bool deserializing) 49 36 : base(deserializing) { … … 54 41 minLengthParameter = cloner.Clone(original.minLengthParameter); 55 42 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(); 56 50 } 57 51 58 52 [StorableHook(HookType.AfterDeserialization)] 59 53 private void AfterDeserialization() { 54 InitParameters(); 60 55 RegisterParameterEvents(); 61 56 DiscoverOperators(); … … 64 59 public override IDeepCloneable Clone(Cloner cloner) { 65 60 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 } 66 98 } 67 99 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Evaluator/PushBenchmarkSuiteEvaluator.cs
r15334 r15341 156 156 157 157 // 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)); 159 159 160 160 // integer error … … 184 184 private double Default(IPushInterpreter interpreter, Example example) { 185 185 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)); 187 187 var booleanDiff = GetDiff(example.OutputBoolean, interpreter.BooleanStack, Data.WorstResult, BooleanDiffer); 188 188 var stringDiff = GetDiff(example.OutputString, interpreter.StringStack, Data.WorstResult, StringDiffer); … … 190 190 var printDiff = GetPrintDiffer(example.OutputPrint, interpreter.PrintStack, Data.WorstResult); 191 191 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))); 193 193 var stringVectorDiff = GetVectorDiff(example.OutputStringVector, interpreter.StringVectorStack, Data.WorstResult, (a, b) => VectorDiffer(a, b, StringDiffer)); 194 194 … … 315 315 return Data.WorstResult; 316 316 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)); 318 318 var expectedStr = example.OutputFloat[0].ToString(Data.FloatStringFormat, CultureInfo.CurrentCulture); 319 319 var resultStr = interpreter.FloatStack.TopOrDefault.ToString(Data.FloatStringFormat, CultureInfo.CurrentCulture); … … 480 480 } 481 481 482 private static double FloatDiffer(double a, double b, int digits ) {482 private static double FloatDiffer(double a, double b, int digits, double worst) { 483 483 var result = Math.Round(a, digits) - Math.Round(b, digits); 484 484 485 485 // 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; 492 490 493 491 return Math.Abs(result); … … 545 543 where T : IComparable { 546 544 if (estimated.Count == 0) return 0d; 545 if (resultStack.IsEmpty && estimated.Count > 0) return worstResult; 547 546 548 547 var diff = 0d; … … 551 550 if (!resultStack.IsEmpty) { 552 551 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]); 555 554 } 556 555 } 557 556 558 557 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++) { 560 559 diff += differ(estimated[i], emptyTArray); 561 560 } … … 567 566 where T : IComparable { 568 567 if (estimated.Count == 0) return 0d; 568 if (resultStack.IsEmpty && estimated.Count > 0) return worstResult; 569 569 570 570 var diff = 0d; … … 572 572 573 573 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]); 576 576 } 577 577 } 578 578 579 for (var i = comparableLength; i < estimated.Count - comparableLength ; i++) {579 for (var i = comparableLength; i < estimated.Count - comparableLength && diff < worstResult; i++) { 580 580 diff += differ(estimated[i], default(T)); 581 581 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/ExpressionTable.cs
r15334 r15341 175 175 176 176 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); 178 184 } 179 185 180 186 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 183 193 throw new NotSupportedException("Expression not supported: " + name); 184 194 } 185 195 186 196 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)) { 188 199 expression = null; 189 200 return false; 190 201 } 191 202 192 expression = StatelessExpressionTable[NameToTypeTable[name]];193 203 return true; 194 204 } … … 199 209 200 210 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(); 207 216 } 208 217 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/FloatExpressions.cs
r15334 r15341 449 449 return interpreter.StringStack.IsEmpty || 450 450 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); 452 456 } 453 457 454 458 public override void Eval(IInternalPushInterpreter interpreter) { 455 459 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); 457 461 458 462 interpreter.FloatStack.Push(value); -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/PushInterpreter.cs
r15334 r15341 17 17 public class PushInterpreter : IInternalPushInterpreter, IDisposable { 18 18 private Task currentTask; 19 private Expression currentProgram;19 private int evalPushLimit; 20 20 21 21 /// <summary> … … 30 30 Configuration = config ?? new PushConfiguration(); 31 31 32 // setting the capacity of the Stacks to max points ensures that there will be enough memory at runtime33 32 ExecStack = new PushStack<Expression>(Configuration.MaxProgramLength); 34 33 CodeStack = new PushStack<Expression>(); … … 66 65 PoolContainer = poolContainer ?? new InterpreterPoolContainer(); 67 66 67 InitEvalPushLimit(); 68 68 ConfigureStacks(); 69 69 } … … 92 92 !IsPaused && 93 93 !IsAborted && 94 (ExecCounter < Configuration.EvalPushLimit);94 (ExecCounter < evalPushLimit); 95 95 } 96 96 } … … 261 261 public void Run(Expression expression, bool stepwise = false) { 262 262 IsPaused = stepwise; 263 currentProgram = expression;264 263 265 264 /* Push top expression so the loop is able to enter … … 347 346 Random = (IRandom)randomOrigin.Clone(); 348 347 348 InitEvalPushLimit(); 349 349 350 ExecCounter = 0; 350 351 IsAborted = false; 351 352 IsPaused = false; 352 353 currentTask = null; 353 currentProgram = null;354 354 355 355 inputExpressions.Clear(); 356 356 ClearStacks(); 357 357 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; 358 367 } 359 368 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/PushInterpreterPool.cs
r15334 r15341 33 33 34 34 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); 40 37 41 38 return interpreter; -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/IntegerVectorPushProblem.cs
r15334 r15341 59 59 Encoding.Bounds[0, 0] = 0; 60 60 Encoding.Bounds[0, 1] = Config.EnabledExpressions.Count; 61 Encoding.Length = Config.MaxProgramLength;62 61 } 63 62 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/PlushPushProblem.cs
r15334 r15341 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Problem { 2 using System.Diagnostics; 2 3 using System.Linq; 3 4 … … 29 30 Encoding.ErcOptionsParameter = Config.ErcOptionsParameter; 30 31 Encoding.InstructionsParameter = Config.InstructionsParameter; 31 Encoding.MinLengthParameter = Config.MinProgramLengthParameter;32 Encoding.MaxLengthParameter = Config.MaxProgramLengthParameter;33 32 Encoding.MaxCloseParameter = Config.MaxCloseParameter; 34 33 Encoding.CloseBiasLevelParameter = Config.CloseBiasLevelParameter; … … 49 48 var program = plushVector.PushProgram; 50 49 50 if (program == null) 51 Debugger.Break(); 52 51 53 return program; 52 54 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Stack/PrintStack.cs
r15334 r15341 36 36 get 37 37 { 38 if (stringBuilder.Length == length) return lines; 38 if (lines != null && stringBuilder.Length == length) 39 return lines; 40 39 41 length = stringBuilder.Length; 40 42 lines = stringBuilder.ToString().Split(PushEnvironment.NewLine);
Note: See TracChangeset
for help on using the changeset viewer.