- Timestamp:
- 07/17/21 19:04:42 (3 years ago)
- Location:
- stable
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk merged: 17976,17978,18020
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Views
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Problems.DataAnalysis.Views merged: 17976,17978,18020
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Views/3.4
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Problems.DataAnalysis.Views/3.4 merged: 17976,17978,18020
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionErrorCharacteristicsCurveView.cs
r17181 r18022 29 29 using HeuristicLab.MainForm; 30 30 using HeuristicLab.Optimization; 31 using HeuristicLab.PluginInfrastructure; 31 32 32 33 namespace HeuristicLab.Problems.DataAnalysis.Views { … … 74 75 } 75 76 76 private readonly IList<IRegressionSolution> solutions = new List<IRegressionSolution>();77 private readonly List<IRegressionSolution> solutions = new List<IRegressionSolution>(); 77 78 public IEnumerable<IRegressionSolution> Solutions { 78 79 get { return solutions.AsEnumerable(); } … … 101 102 else { 102 103 // recalculate baseline solutions (for symbolic regression models the features used in the model might have changed) 103 solutions.Clear(); // remove all104 solutions.Clear(); 104 105 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 } 106 solutions.AddRange(CreateBaselineSolutions()); 109 107 UpdateChart(); 110 108 } … … 114 112 else { 115 113 // recalculate baseline solutions 116 solutions.Clear(); // remove all114 solutions.Clear(); 117 115 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 } 116 solutions.AddRange(CreateBaselineSolutions()); 122 117 UpdateChart(); 123 118 } … … 129 124 ReadOnly = Content == null; 130 125 if (Content != null) { 131 // recalculate all solutions132 126 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 } 127 solutions.AddRange(CreateBaselineSolutions()); 138 128 } 139 129 UpdateChart(); … … 175 165 UpdateSeries(residuals, solutionSeries); 176 166 177 solutionSeries.ToolTip = "Area over Curve: " + CalculateAreaOverCurve(solutionSeries);167 solutionSeries.ToolTip = "Area over curve: " + CalculateAreaOverCurve(solutionSeries); 178 168 solutionSeries.LegendToolTip = "Double-click to open model"; 179 169 chart.Series.Add(solutionSeries); … … 249 239 protected virtual List<double> GetResiduals(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues) { 250 240 switch (residualComboBox.SelectedItem.ToString()) { 251 case "Absolute error": return originalValues.Zip(estimatedValues, (x, y) => Math.Abs(x - y)) 241 case "Absolute error": 242 return originalValues.Zip(estimatedValues, (x, y) => Math.Abs(x - y)) 252 243 .Where(r => !double.IsNaN(r) && !double.IsInfinity(r)).ToList(); 253 case "Squared error": return originalValues.Zip(estimatedValues, (x, y) => (x - y) * (x - y)) 244 case "Squared error": 245 return originalValues.Zip(estimatedValues, (x, y) => (x - y) * (x - y)) 254 246 .Where(r => !double.IsNaN(r) && !double.IsInfinity(r)).ToList(); 255 247 case "Relative error": … … 289 281 290 282 protected virtual IEnumerable<IRegressionSolution> CreateBaselineSolutions() { 291 yield return CreateConstantSolution(); 292 yield return CreateLinearSolution(); 283 var constantSolution = CreateConstantSolution(); 284 if (constantSolution != null) yield return constantSolution; 285 286 var linearRegressionSolution = CreateLinearSolution(); 287 if (linearRegressionSolution != null) yield return linearRegressionSolution; 293 288 } 294 289 295 290 private IRegressionSolution CreateConstantSolution() { 291 if (!ProblemData.TrainingIndices.Any()) return null; 292 296 293 double averageTrainingTarget = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices).Average(); 297 294 var model = new ConstantModel(averageTrainingTarget, ProblemData.TargetVariable); … … 301 298 } 302 299 private IRegressionSolution CreateLinearSolution() { 303 double rmsError, cvRmsError; 304 var solution = LinearRegression.CreateLinearRegressionSolution((IRegressionProblemData)ProblemData.Clone(), out rmsError, out cvRmsError); 305 solution.Name = "Baseline (linear)"; 306 return solution; 300 try { 301 var solution = LinearRegression.CreateSolution((IRegressionProblemData)ProblemData.Clone(), out _, out _); 302 solution.Name = "Baseline (linear)"; 303 return solution; 304 } catch (NotSupportedException e) { 305 ErrorHandling.ShowErrorDialog("Could not create a linear regression solution.", e); 306 } catch (ArgumentException e) { 307 ErrorHandling.ShowErrorDialog("Could not create a linear regression solution.", e); 308 } 309 return null; 307 310 } 308 311
Note: See TracChangeset
for help on using the changeset viewer.