Changeset 17976
Legend:
 Unmodified
 Added
 Removed

trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/SymbolicRegressionSolutionErrorCharacteristicsCurveView.cs
r17180 r17976 26 26 using HeuristicLab.Algorithms.DataAnalysis; 27 27 using HeuristicLab.MainForm; 28 using HeuristicLab.PluginInfrastructure; 28 29 using HeuristicLab.Problems.DataAnalysis.Views; 29 30 … … 43 44 private IRegressionSolution CreateLinearRegressionSolution() { 44 45 if (Content == null) throw new InvalidOperationException(); 45 double rmse, cvRmsError;46 46 var problemData = (IRegressionProblemData)ProblemData.Clone(); 47 47 if (!problemData.TrainingIndices.Any()) return null; // don't create an LR model if the problem does not have a training set (e.g. loaded into an existing model) … … 87 87 newProblemData.TestPartition.End = problemData.TestPartition.End; 88 88 89 var solution = LinearRegression.CreateLinearRegressionSolution(newProblemData, out rmse, out cvRmsError); 90 solution.Name = "Baseline (linear subset)"; 91 return solution; 89 try { 90 var solution = LinearRegression.CreateSolution(newProblemData, out _, out _); 91 solution.Name = "Baseline (linear subset)"; 92 return solution; 93 } catch (NotSupportedException e) { 94 ErrorHandling.ShowErrorDialog("Could not create a linear regression solution.", e); 95 } catch (ArgumentException e) { 96 ErrorHandling.ShowErrorDialog("Could not create a linear regression solution.", e); 97 } 98 return null; 92 99 } 93 100 … … 99 106 if (Content.Model.SymbolicExpressionTree.IterateNodesPrefix().OfType<LaggedVariableTreeNode>().Any()) yield break; 100 107 101 yield return CreateLinearRegressionSolution(); 108 var linearRegressionSolution = CreateLinearRegressionSolution(); 109 if (linearRegressionSolution != null) yield return linearRegressionSolution; 102 110 } 103 111 } 
trunk/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionErrorCharacteristicsCurveView.cs
r17180 r17976 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); // readd the first solution 105 // and recalculate all other solutions 106 foreach (var sol in CreateBaselineSolutions()) { 107 solutions.Add(sol); 108 } 106 var baselineSolutions = CreateBaselineSolutions(); 107 solutions.AddRange(baselineSolutions); 109 108 UpdateChart(); 110 109 } … … 114 113 else { 115 114 // recalculate baseline solutions 116 solutions.Clear(); // remove all115 solutions.Clear(); 117 116 solutions.Add(Content); // readd the first solution 118 // and recalculate all other solutions 119 foreach (var sol in CreateBaselineSolutions()) { 120 solutions.Add(sol); 121 } 117 var baselineSolutions = CreateBaselineSolutions(); 118 solutions.AddRange(baselineSolutions); 122 119 UpdateChart(); 123 120 } … … 129 126 ReadOnly = Content == null; 130 127 if (Content != null) { 131 // recalculate all solutions132 128 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 } 129 var baselineSolutions = CreateBaselineSolutions(); 130 solutions.AddRange(baselineSolutions); 138 131 } 139 132 UpdateChart(); … … 249 242 protected virtual List<double> GetResiduals(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues) { 250 243 switch (residualComboBox.SelectedItem.ToString()) { 251 case "Absolute error": return originalValues.Zip(estimatedValues, (x, y) => Math.Abs(x  y)) 244 case "Absolute error": 245 return originalValues.Zip(estimatedValues, (x, y) => Math.Abs(x  y)) 252 246 .Where(r => !double.IsNaN(r) && !double.IsInfinity(r)).ToList(); 253 case "Squared error": return originalValues.Zip(estimatedValues, (x, y) => (x  y) * (x  y)) 247 case "Squared error": 248 return originalValues.Zip(estimatedValues, (x, y) => (x  y) * (x  y)) 254 249 .Where(r => !double.IsNaN(r) && !double.IsInfinity(r)).ToList(); 255 250 case "Relative error": … … 289 284 290 285 protected virtual IEnumerable<IRegressionSolution> CreateBaselineSolutions() { 291 yield return CreateConstantSolution(); 292 yield return CreateLinearSolution(); 286 var constantSolution = CreateConstantSolution(); 287 if (constantSolution != null) yield return CreateConstantSolution(); 288 289 var linearRegressionSolution = CreateLinearSolution(); 290 if (linearRegressionSolution != null) yield return CreateLinearSolution(); 293 291 } 294 292 295 293 private IRegressionSolution CreateConstantSolution() { 294 if (!ProblemData.TrainingIndices.Any()) return null; 295 296 296 double averageTrainingTarget = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices).Average(); 297 297 var model = new ConstantModel(averageTrainingTarget, ProblemData.TargetVariable); … … 301 301 } 302 302 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; 303 try { 304 var solution = LinearRegression.CreateSolution((IRegressionProblemData)ProblemData.Clone(), out _, out _); 305 solution.Name = "Baseline (linear)"; 306 return solution; 307 } catch (NotSupportedException e) { 308 ErrorHandling.ShowErrorDialog("Could not create a linear regression solution.", e); 309 } catch (ArgumentException e) { 310 ErrorHandling.ShowErrorDialog("Could not create a linear regression solution.", e); 311 } 312 return null; 307 313 } 308 314
Note: See TracChangeset
for help on using the changeset viewer.