Changeset 13062 for stable/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionErrorCharacteristicsCurveView.cs
- Timestamp:
- 10/26/15 18:26:57 (9 years ago)
- Location:
- stable
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 13002-13004
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Views
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Problems.DataAnalysis.Views merged: 13002-13004
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionErrorCharacteristicsCurveView.cs
r12668 r13062 25 25 using System.Windows.Forms; 26 26 using System.Windows.Forms.DataVisualization.Charting; 27 using HeuristicLab.Algorithms.DataAnalysis; 27 28 using HeuristicLab.Common; 28 29 using HeuristicLab.MainForm; 30 using HeuristicLab.Optimization; 29 31 30 32 namespace HeuristicLab.Problems.DataAnalysis.Views { … … 62 64 } 63 65 66 // the view holds one regression solution as content but also contains several other regression solutions for comparison 67 // the following invariants must hold 68 // (Solutions.IsEmpty && Content == null) || 69 // (Solutions[0] == Content && Solutions.All(s => s.ProblemData.TargetVariable == Content.TargetVariable)) 70 64 71 public new IRegressionSolution Content { 65 72 get { return (IRegressionSolution)base.Content; } 66 73 set { base.Content = value; } 67 74 } 75 76 private readonly IList<IRegressionSolution> solutions = new List<IRegressionSolution>(); 77 public IEnumerable<IRegressionSolution> Solutions { 78 get { return solutions.AsEnumerable(); } 79 } 80 68 81 public IRegressionProblemData ProblemData { 69 82 get { … … 86 99 protected virtual void Content_ModelChanged(object sender, EventArgs e) { 87 100 if (InvokeRequired) Invoke((Action<object, EventArgs>)Content_ModelChanged, sender, e); 88 else UpdateChart(); 101 else { 102 // recalculate baseline solutions (for symbolic regression models the features used in the model might have changed) 103 solutions.Clear(); // remove all 104 solutions.Add(Content); // re-add the first solution 105 // and recalculate all other solutions 106 foreach (var sol in CreateBaselineSolutions()) { 107 solutions.Add(sol); 108 } 109 UpdateChart(); 110 } 89 111 } 90 112 protected virtual void Content_ProblemDataChanged(object sender, EventArgs e) { 91 113 if (InvokeRequired) Invoke((Action<object, EventArgs>)Content_ProblemDataChanged, sender, e); 92 114 else { 115 // recalculate baseline solutions 116 solutions.Clear(); // remove all 117 solutions.Add(Content); // re-add the first solution 118 // and recalculate all other solutions 119 foreach (var sol in CreateBaselineSolutions()) { 120 solutions.Add(sol); 121 } 93 122 UpdateChart(); 94 123 } … … 96 125 protected override void OnContentChanged() { 97 126 base.OnContentChanged(); 127 // the content object is always stored as the first element in solutions 128 solutions.Clear(); 129 ReadOnly = Content == null; 130 if (Content != null) { 131 // recalculate all solutions 132 solutions.Add(Content); 133 if (ProblemData.TrainingIndices.Any()) { 134 foreach (var sol in CreateBaselineSolutions()) 135 solutions.Add(sol); 136 // more solutions can be added by drag&drop 137 } 138 } 98 139 UpdateChart(); 99 140 } … … 109 150 if (cmbSamples.SelectedItem.ToString() == TestSamples && !ProblemData.TestIndices.Any()) return; 110 151 111 if (Content.ProblemData.TrainingIndices.Any()) { 112 AddRegressionSolution(CreateConstantSolution()); 113 } 114 115 AddRegressionSolution(Content); 152 foreach (var sol in Solutions) { 153 AddSeries(sol); 154 } 116 155 117 156 chart.ChartAreas[0].AxisX.Title = residualComboBox.SelectedItem.ToString(); 118 157 } 119 158 120 protected void Add RegressionSolution(IRegressionSolution solution) {159 protected void AddSeries(IRegressionSolution solution) { 121 160 if (chart.Series.Any(s => s.Name == solution.Name)) return; 122 161 … … 239 278 } 240 279 241 #region Baseline242 280 private void Chart_MouseDoubleClick(object sender, MouseEventArgs e) { 243 281 HitTestResult result = chart.HitTest(e.X, e.Y); … … 247 285 } 248 286 249 private ConstantRegressionSolution CreateConstantSolution() { 287 protected virtual IEnumerable<IRegressionSolution> CreateBaselineSolutions() { 288 yield return CreateConstantSolution(); 289 yield return CreateLinearSolution(); 290 } 291 292 private IRegressionSolution CreateConstantSolution() { 250 293 double averageTrainingTarget = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices).Average(); 251 294 var model = new ConstantRegressionModel(averageTrainingTarget); 252 295 var solution = new ConstantRegressionSolution(model, (IRegressionProblemData)ProblemData.Clone()); 253 solution.Name = "Baseline ";296 solution.Name = "Baseline (constant)"; 254 297 return solution; 255 298 } 256 #endregion 299 private IRegressionSolution CreateLinearSolution() { 300 double rmsError, cvRmsError; 301 var solution = LinearRegression.CreateLinearRegressionSolution((IRegressionProblemData)ProblemData.Clone(), out rmsError, out cvRmsError); 302 solution.Name = "Baseline (linear)"; 303 return solution; 304 } 257 305 258 306 private void chart_MouseMove(object sender, MouseEventArgs e) { … … 265 313 } 266 314 315 private void chart_DragDrop(object sender, DragEventArgs e) { 316 if (e.Data.GetDataPresent(HeuristicLab.Common.Constants.DragDropDataFormat)) { 317 318 var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat); 319 var dataAsRegressionSolution = data as IRegressionSolution; 320 var dataAsResult = data as IResult; 321 322 if (dataAsRegressionSolution != null) { 323 solutions.Add((IRegressionSolution)dataAsRegressionSolution.Clone()); 324 } else if (dataAsResult != null && dataAsResult.Value is IRegressionSolution) { 325 solutions.Add((IRegressionSolution)dataAsResult.Value.Clone()); 326 } 327 328 UpdateChart(); 329 } 330 } 331 332 private void chart_DragEnter(object sender, DragEventArgs e) { 333 e.Effect = DragDropEffects.None; 334 if (!e.Data.GetDataPresent(HeuristicLab.Common.Constants.DragDropDataFormat)) return; 335 336 var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat); 337 var dataAsRegressionSolution = data as IRegressionSolution; 338 var dataAsResult = data as IResult; 339 340 if (!ReadOnly && 341 (dataAsRegressionSolution != null || (dataAsResult != null && dataAsResult.Value is IRegressionSolution))) { 342 e.Effect = DragDropEffects.Copy; 343 } 344 } 345 267 346 private void residualComboBox_SelectedIndexChanged(object sender, EventArgs e) { 268 347 UpdateChart();
Note: See TracChangeset
for help on using the changeset viewer.