Changeset 15189 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/BenchmarkSuite/PushBenchmarkSuiteEvaluator.cs
- Timestamp:
- 07/10/17 21:36:03 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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++) {
Note: See TracChangeset
for help on using the changeset viewer.