Changeset 15189 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem
- Timestamp:
- 07/10/17 21:36:03 (8 years ago)
- 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 53 53 var example = Evaluator.Data.Examples[exampleComboBox.SelectedIndex]; 54 54 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()); 64 74 } 65 75 … … 198 208 var type = data.OutputArgumentTypes[j]; 199 209 var offset = outputArgumentCountDict[type]; 210 211 // estimated 200 212 row.Cells[data.InputArgumentTypes.Length + j * 2].Value = ViewHelper.StringifyOutput(type, offset, Content.Config.FloatStringFormat, example, Separator); 213 214 // output 201 215 row.Cells[data.InputArgumentTypes.Length + j * 2 + 1].Value = StringifyResult(type, offset, pushInterpreter, example, Separator); 216 202 217 outputArgumentCountDict[type]++; 203 218 } … … 243 258 244 259 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))); 246 261 247 262 case ExampleArgumentType.String: -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/BenchmarkSuite/PushBenchmarkSuiteEvaluator.cs
r15017 r15189 2 2 using System; 3 3 using System.Collections.Generic; 4 using System.Globalization; 4 5 using System.Linq; 5 6 … … 130 131 var example = Data.Examples[exampleIndex]; 131 132 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); 140 151 141 152 interpreter.Run(program); 142 153 143 154 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) { 157 163 var result = GetDiff(example.OutputInteger, interpreter.IntegerStack, Data.WorstResult, IntegerDiffer) 158 159 160 161 162 163 164 165 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)); 166 172 167 173 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; 168 199 } 169 200 … … 217 248 } 218 249 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 219 256 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)); 221 258 var distance = LevenshteinDistance(estimated, printResult); 222 259 … … 234 271 var count = Math.Min(estimated.Count, resultStack.Count); 235 272 var result = resultStack.Peek(count); 236 comparableLength = Math.Min(estimated.Count, result. Length);273 comparableLength = Math.Min(estimated.Count, result.Count); 237 274 238 275 for (var i = 0; i < comparableLength; i++) { … … 259 296 var count = Math.Min(estimated.Count, resultStack.Count); 260 297 var result = resultStack.Peek(count); 261 comparableLength = Math.Min(estimated.Count, result. Length);298 comparableLength = Math.Min(estimated.Count, result.Count); 262 299 263 300 for (var i = 0; i < comparableLength; i++) { -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/BenchmarkSuite/PushBenchmarkSuiteProblem.cs
r15032 r15189 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Problem.BenchmarkSuite { 2 2 3 using Common; 3 4 using Configuration; … … 7 8 using HeuristicLab.BenchmarkSuite.Problems; 8 9 using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions; 10 using HeuristicLab.Problems.ProgramSynthesis.Push.Extensions; 9 11 10 12 using Instances; … … 53 55 54 56 config.SetEnabledStacks((StackTypes)data.EnabledDataTypes); 57 data.InitInExpressions(config); 55 58 56 59 Encoding.Bounds[0, 0] = 0; -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/PushProblem.cs
r15032 r15189 12 12 using HeuristicLab.Problems.ProgramSynthesis.Push.Analyzer; 13 13 using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions; 14 using HeuristicLab.Problems.ProgramSynthesis.Push.Individual; 14 15 using HeuristicLab.Problems.ProgramSynthesis.Push.Problem.BenchmarkSuite; 15 16 … … 125 126 // clear pools and free reserved memory 126 127 pool.Clear(); 128 IndividualMapper.Clear(); 127 129 } 128 130 … … 158 160 159 161 public override void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) { 162 IndividualMapper.Reset(); 163 160 164 var bestQuality = Maximization ? qualities.Max() : qualities.Min(); 161 165 var bestIdx = Array.IndexOf(qualities, bestQuality); … … 165 169 rand.Reset(seed); 166 170 167 var program = vector.ToPushProgram(config, rand);171 var program = (PushProgram)vector.ToPushProgram(config, rand).Clone(); 168 172 var isIndividualBetter = AnalyzeBestTrainingSolution(program, bestQuality, results, rand); 169 173
Note: See TracChangeset
for help on using the changeset viewer.