Changeset 17996
 Timestamp:
 06/27/21 15:26:06 (3 years ago)
 Location:
 branches/3087_Ceres_Integration
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/SymbolicRegressionSolutionErrorCharacteristicsCurveView.cs
r17991 r17996 26 26 using HeuristicLab.Algorithms.DataAnalysis; 27 27 using HeuristicLab.MainForm; 28 using HeuristicLab.PluginInfrastructure;29 28 using HeuristicLab.Problems.DataAnalysis.Views; 30 29 … … 44 43 private IRegressionSolution CreateLinearRegressionSolution() { 45 44 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 try { 90 var solution = LinearRegression.CreateSolution(newProblemData, out _, 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; 89 var solution = LinearRegression.CreateLinearRegressionSolution(newProblemData, out rmse, out cvRmsError); 90 solution.Name = "Baseline (linear subset)"; 91 return solution; 99 92 } 100 93 … … 106 99 if (Content.Model.SymbolicExpressionTree.IterateNodesPrefix().OfType<LaggedVariableTreeNode>().Any()) yield break; 107 100 108 var linearRegressionSolution = CreateLinearRegressionSolution(); 109 if (linearRegressionSolution != null) yield return linearRegressionSolution; 101 yield return CreateLinearRegressionSolution(); 110 102 } 111 103 } 
branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionErrorCharacteristicsCurveView.cs
r17991 r17996 29 29 using HeuristicLab.MainForm; 30 30 using HeuristicLab.Optimization; 31 using HeuristicLab.PluginInfrastructure;32 31 33 32 namespace HeuristicLab.Problems.DataAnalysis.Views { … … 75 74 } 76 75 77 private readonly List<IRegressionSolution> solutions = new List<IRegressionSolution>();76 private readonly IList<IRegressionSolution> solutions = new List<IRegressionSolution>(); 78 77 public IEnumerable<IRegressionSolution> Solutions { 79 78 get { return solutions.AsEnumerable(); } … … 104 103 solutions.Clear(); // remove all 105 104 solutions.Add(Content); // readd the first solution 106 solutions.AddRange(CreateBaselineSolutions()); 105 // and recalculate all other solutions 106 foreach (var sol in CreateBaselineSolutions()) { 107 solutions.Add(sol); 108 } 107 109 UpdateChart(); 108 110 } … … 114 116 solutions.Clear(); // remove all 115 117 solutions.Add(Content); // readd the first solution 116 solutions.AddRange(CreateBaselineSolutions()); 118 // and recalculate all other solutions 119 foreach (var sol in CreateBaselineSolutions()) { 120 solutions.Add(sol); 121 } 117 122 UpdateChart(); 118 123 } … … 244 249 protected virtual List<double> GetResiduals(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues) { 245 250 switch (residualComboBox.SelectedItem.ToString()) { 246 case "Absolute error": 247 return originalValues.Zip(estimatedValues, (x, y) => Math.Abs(x  y)) 251 case "Absolute error": return originalValues.Zip(estimatedValues, (x, y) => Math.Abs(x  y)) 248 252 .Where(r => !double.IsNaN(r) && !double.IsInfinity(r)).ToList(); 249 case "Squared error": 250 return originalValues.Zip(estimatedValues, (x, y) => (x  y) * (x  y)) 253 case "Squared error": return originalValues.Zip(estimatedValues, (x, y) => (x  y) * (x  y)) 251 254 .Where(r => !double.IsNaN(r) && !double.IsInfinity(r)).ToList(); 252 255 case "Relative error": … … 286 289 287 290 protected virtual IEnumerable<IRegressionSolution> CreateBaselineSolutions() { 288 var constantSolution = CreateConstantSolution(); 289 if (constantSolution != null) yield return CreateConstantSolution(); 290 291 var linearRegressionSolution = CreateLinearSolution(); 292 if (linearRegressionSolution != null) yield return CreateLinearSolution(); 291 yield return CreateConstantSolution(); 292 yield return CreateLinearSolution(); 293 293 } 294 294 295 295 private IRegressionSolution CreateConstantSolution() { 296 if (!ProblemData.TrainingIndices.Any()) return null;297 298 296 double averageTrainingTarget = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices).Average(); 299 297 var model = new ConstantModel(averageTrainingTarget, ProblemData.TargetVariable); … … 303 301 } 304 302 private IRegressionSolution CreateLinearSolution() { 305 try { 306 var solution = LinearRegression.CreateSolution((IRegressionProblemData)ProblemData.Clone(), out _, out _, out _); 307 solution.Name = "Baseline (linear)"; 308 return solution; 309 } catch (NotSupportedException e) { 310 ErrorHandling.ShowErrorDialog("Could not create a linear regression solution.", e); 311 } catch (ArgumentException e) { 312 ErrorHandling.ShowErrorDialog("Could not create a linear regression solution.", e); 313 } 314 return null; 303 double rmsError, cvRmsError; 304 var solution = LinearRegression.CreateLinearRegressionSolution((IRegressionProblemData)ProblemData.Clone(), out rmsError, out cvRmsError); 305 solution.Name = "Baseline (linear)"; 306 return solution; 315 307 } 316 308
Note: See TracChangeset
for help on using the changeset viewer.