Changeset 14952 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/BenchmarkSuite/BenchmarkSuitePushSolutionView.cs
- Timestamp:
- 05/10/17 11:23:05 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/BenchmarkSuite/BenchmarkSuitePushSolutionView.cs
r14908 r14952 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Problem.BenchmarkSuite { 2 2 using System; 3 using System.Collections.Generic; 4 using System.Drawing; 3 5 using System.Globalization; 4 6 using System.Linq; … … 6 8 using Core.Views; 7 9 using HeuristicLab.BenchmarkSuite; 8 using HeuristicLab.BenchmarkSuite.Problems;9 10 using HeuristicLab.BenchmarkSuite.Views; 11 using HeuristicLab.Common; 12 10 13 using Interpreter; 11 14 using MainForm; … … 18 21 19 22 private const string Separator = ", "; 20 private const string EmptySign = "-";21 23 22 24 private const string exampleSplitter = " => "; … … 26 28 private const string EstimatedOutputHeaderStringFormat = "Estimated Output {0} : {1}"; 27 29 private const string OutputHeaderStringFormat = "Output {0} : {1}"; 28 30 private static readonly Color correctExampleFontColor = Color.FromArgb(0x5cb85c); 29 31 private PooledPushInterpreter interpreter; 30 32 private PushInterpreterPool pool; … … 98 100 } 99 101 100 InitResultGrid(); 102 InitResultGrid(trainingResultsDataGrid, Evaluator.DataBounds.TrainingRange.Start, Evaluator.DataBounds.TrainingRange.End); 103 InitResultGrid(testResultsDataGrid, Evaluator.DataBounds.TestRange.Start, Evaluator.DataBounds.TestRange.End); 104 101 105 pushDebugger.Content = Content; 102 106 } 103 107 104 private void InitResultGrid( ) {105 resultsDataGrid.Columns.Clear();106 resultsDataGrid.Rows.Clear();107 108 var cellTemplate = new DataGridViewTextBoxCell ();108 private void InitResultGrid(DataGridView grid, int start, int end) { 109 grid.Columns.Clear(); 110 grid.Rows.Clear(); 111 112 var cellTemplate = new DataGridViewTextBoxCell { Style = { WrapMode = DataGridViewTriState.True } }; 109 113 var data = Evaluator.Data; 110 114 … … 114 118 HeaderText = string.Format(InputHeaderStringFormat, i + 1, headerTypeName), 115 119 AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill, 116 CellTemplate = cellTemplate 120 CellTemplate = cellTemplate, 121 DefaultCellStyle = { Alignment = DataGridViewContentAlignment.MiddleRight } 117 122 }; 118 123 119 column.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; 120 resultsDataGrid.Columns.Add(column); 124 grid.Columns.Add(column); 121 125 } 122 126 … … 139 143 outputColumn.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; 140 144 141 resultsDataGrid.Columns.Add(estimatedOutputColumn);142 resultsDataGrid.Columns.Add(outputColumn);145 grid.Columns.Add(estimatedOutputColumn); 146 grid.Columns.Add(outputColumn); 143 147 } 144 148 … … 158 162 relativeDiffColumn.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; 159 163 160 resultsDataGrid.Columns.Add(absoluteDiffColumn);161 resultsDataGrid.Columns.Add(relativeDiffColumn);164 grid.Columns.Add(absoluteDiffColumn); 165 grid.Columns.Add(relativeDiffColumn); 162 166 163 167 using (var pushInterpreter = pool.Create(Content.Random)) { 164 for (var i = 0; i < data.Examples.Length; i++) { 168 var rowIndex = 1; 169 for (var i = start; i < end; i++, rowIndex++) { 165 170 var example = data.Examples[i]; 166 var row = new DataGridViewRow(); 171 var row = new DataGridViewRow { 172 HeaderCell = { 173 Value = rowIndex.ToString(), 174 } 175 }; 176 177 row.CreateCells(grid); 178 167 179 var absoluteDiff = Evaluator.Evaluate(pushInterpreter, Content.Program, i); 168 180 var relativeDiff = absoluteDiff / Math.Abs(data.BestResult - data.WorstResult) * 100d; 169 181 170 row.HeaderCell.Value = row.Index + 1; 171 row.CreateCells(resultsDataGrid); 172 182 var inputArgumentCountDict = ViewHelper.CreateArgumentCountDict(); 173 183 for (var j = 0; j < data.InputArgumentTypes.Length; j++) { 174 row.Cells[j].Value = ViewHelper.StringifyInput(data.InputArgumentTypes[j], example, Separator); 184 var type = data.InputArgumentTypes[j]; 185 var offset = inputArgumentCountDict[type]; 186 row.Cells[j].Value = ViewHelper.StringifyInput(type, offset, example, Separator); 187 inputArgumentCountDict[type]++; 175 188 } 176 189 190 var outputArgumentCountDict = ViewHelper.CreateArgumentCountDict(); 177 191 for (var j = 0; j < data.OutputArgumentTypes.Length; j++) { 178 row.Cells[data.InputArgumentTypes.Length + j * 2].Value = ViewHelper.StringifyOutput(data.OutputArgumentTypes[j], example, Separator); 179 row.Cells[data.InputArgumentTypes.Length + j * 2 + 1].Value = StringifyResult(data.OutputArgumentTypes[j], pushInterpreter, example, Separator); 192 var type = data.OutputArgumentTypes[j]; 193 var offset = outputArgumentCountDict[type]; 194 row.Cells[data.InputArgumentTypes.Length + j * 2].Value = ViewHelper.StringifyOutput(type, offset, example, Separator); 195 row.Cells[data.InputArgumentTypes.Length + j * 2 + 1].Value = StringifyResult(type, offset, pushInterpreter, example, Separator); 196 outputArgumentCountDict[type]++; 180 197 } 181 198 182 row.Cells[data.TotalArgumentCount + 1].Value = absoluteDiff; 183 row.Cells[data.TotalArgumentCount + 2].Value = relativeDiff + "%"; 184 185 resultsDataGrid.Rows.Add(row); 199 row.Cells[data.TotalArgumentCount + 1].Value = absoluteDiff.ToString("0.####"); 200 row.Cells[data.TotalArgumentCount + 2].Value = relativeDiff.ToString("0.##") + "%"; 201 202 if (absoluteDiff.IsAlmost(data.BestResult)) { 203 for (var j = 0; j < row.Cells.Count; j++) { 204 row.Cells[j].Style.ForeColor = correctExampleFontColor; 205 } 206 } 207 208 grid.Rows.Add(row); 186 209 pushInterpreter.Reset(); 187 210 } … … 189 212 } 190 213 191 private string StringifyResult(ExampleArgumentType type, IPushInterpreter interpreter, Example example, string valueSeparator) { 214 private string StringifyResult(ExampleArgumentType type, int offset, IPushInterpreter interpreter, Example example, string valueSeparator) { 215 var emptyString = string.Empty; 216 192 217 switch (type) { 193 218 case ExampleArgumentType.Integer: 194 case ExampleArgumentType.IntegerVector: return interpreter.IntegerStack.IsEmpty ? EmptySign : string.Join(valueSeparator, interpreter.IntegerStack.Peek(GetCount(interpreter.IntegerStack, example.OutputInteger))); 219 return GetEntryAsString(offset, interpreter.IntegerStack); 220 221 case ExampleArgumentType.IntegerVector: 222 return GetVectorEntryAsString(offset, interpreter.IntegerVectorStack); 195 223 196 224 case ExampleArgumentType.Float: 197 case ExampleArgumentType.FloatVector: return interpreter.FloatStack.IsEmpty ? EmptySign : string.Join(valueSeparator, interpreter.FloatStack.Peek(GetCount(interpreter.FloatStack, example.OutputFloat)).Select(d => d.ToString(CultureInfo.CurrentUICulture))); 198 199 case ExampleArgumentType.Boolean: return interpreter.BooleanStack.IsEmpty ? EmptySign : interpreter.BooleanStack.Top.ToString(); 200 case ExampleArgumentType.Char: return interpreter.CharStack.IsEmpty ? EmptySign : interpreter.CharStack.Top.ToString(); 225 return interpreter.FloatStack.Count > offset 226 ? interpreter.FloatStack[offset].ToString(CultureInfo.CurrentUICulture) 227 : emptyString; 228 229 case ExampleArgumentType.FloatVector: 230 return GetVectorEntryAsString(offset, interpreter.FloatVectorStack); 231 232 case ExampleArgumentType.Boolean: 233 return GetEntryAsString(offset, interpreter.BooleanStack); 234 235 case ExampleArgumentType.Char: 236 return GetEntryAsString(offset, interpreter.CharStack); 237 238 case ExampleArgumentType.Print: 239 var requiredLines = example.OutputPrint.Split(new[] { Environment.NewLine }, StringSplitOptions.None).Length; 240 var count = Math.Min(requiredLines, interpreter.PrintStack.Count); 241 return string.Join(valueSeparator, string.Join(Environment.NewLine, interpreter.PrintStack.Peek(count))); 201 242 202 243 case ExampleArgumentType.String: 203 case ExampleArgumentType.StringVector: return interpreter.StringStack.IsEmpty ? EmptySign : string.Join(valueSeparator, interpreter.StringStack.Peek(GetCount(interpreter.StringStack, example.OutputString))); 244 return GetEntryAsString(offset, interpreter.StringStack); 245 246 case ExampleArgumentType.StringVector: 247 return GetVectorEntryAsString(offset, interpreter.StringVectorStack); 248 204 249 default: return string.Empty; 205 250 } 206 251 } 207 252 253 private static string GetEntryAsString<T>(int offset, IPushStack<T> stack) { 254 return stack.Count > offset 255 ? stack[offset].ToString() 256 : string.Empty; 257 } 258 259 private static string GetVectorEntryAsString<T>(int offset, IPushStack<List<T>> vectorStack) { 260 return vectorStack.Count > offset 261 ? "[" + string.Join(",", vectorStack[offset]) + "]" 262 : string.Empty; 263 } 264 208 265 private int GetCount<T>(IPushStack<T> stack, T[] data) { 266 return Math.Max(0, Math.Min(data.Length, stack.Count)); 267 } 268 269 private int GetVectorCount<T>(IPushStack<List<T>> stack, T[][] data) { 209 270 return Math.Max(0, Math.Min(data.Length, stack.Count)); 210 271 }
Note: See TracChangeset
for help on using the changeset viewer.