Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17976


Ignore:
Timestamp:
05/06/21 16:16:20 (4 years ago)
Author:
mkommend
Message:

#3125: Added error handling to ECC View and minor code improvements.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/SymbolicRegressionSolutionErrorCharacteristicsCurveView.cs

    r17180 r17976  
    2626using HeuristicLab.Algorithms.DataAnalysis;
    2727using HeuristicLab.MainForm;
     28using HeuristicLab.PluginInfrastructure;
    2829using HeuristicLab.Problems.DataAnalysis.Views;
    2930
     
    4344    private IRegressionSolution CreateLinearRegressionSolution() {
    4445      if (Content == null) throw new InvalidOperationException();
    45       double rmse, cvRmsError;
    4646      var problemData = (IRegressionProblemData)ProblemData.Clone();
    4747      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)
     
    8787      newProblemData.TestPartition.End = problemData.TestPartition.End;
    8888
    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;
    9299    }
    93100
     
    99106      if (Content.Model.SymbolicExpressionTree.IterateNodesPrefix().OfType<LaggedVariableTreeNode>().Any()) yield break;
    100107
    101       yield return CreateLinearRegressionSolution();
     108      var linearRegressionSolution = CreateLinearRegressionSolution();
     109      if (linearRegressionSolution != null) yield return linearRegressionSolution;
    102110    }
    103111  }
  • trunk/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionErrorCharacteristicsCurveView.cs

    r17180 r17976  
    2929using HeuristicLab.MainForm;
    3030using HeuristicLab.Optimization;
     31using HeuristicLab.PluginInfrastructure;
    3132
    3233namespace HeuristicLab.Problems.DataAnalysis.Views {
     
    7475    }
    7576
    76     private readonly IList<IRegressionSolution> solutions = new List<IRegressionSolution>();
     77    private readonly List<IRegressionSolution> solutions = new List<IRegressionSolution>();
    7778    public IEnumerable<IRegressionSolution> Solutions {
    7879      get { return solutions.AsEnumerable(); }
     
    101102      else {
    102103        // recalculate baseline solutions (for symbolic regression models the features used in the model might have changed)
    103         solutions.Clear(); // remove all
     104        solutions.Clear();
    104105        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        var baselineSolutions = CreateBaselineSolutions();
     107        solutions.AddRange(baselineSolutions);
    109108        UpdateChart();
    110109      }
     
    114113      else {
    115114        // recalculate baseline solutions
    116         solutions.Clear(); // remove all
     115        solutions.Clear();
    117116        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         }
     117        var baselineSolutions = CreateBaselineSolutions();
     118        solutions.AddRange(baselineSolutions);
    122119        UpdateChart();
    123120      }
     
    129126      ReadOnly = Content == null;
    130127      if (Content != null) {
    131         // recalculate all solutions
    132128        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);
    138131      }
    139132      UpdateChart();
     
    249242    protected virtual List<double> GetResiduals(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues) {
    250243      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))
    252246            .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))
    254249            .Where(r => !double.IsNaN(r) && !double.IsInfinity(r)).ToList();
    255250        case "Relative error":
     
    289284
    290285    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();
    293291    }
    294292
    295293    private IRegressionSolution CreateConstantSolution() {
     294      if (!ProblemData.TrainingIndices.Any()) return null;
     295
    296296      double averageTrainingTarget = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices).Average();
    297297      var model = new ConstantModel(averageTrainingTarget, ProblemData.TargetVariable);
     
    301301    }
    302302    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;
    307313    }
    308314
Note: See TracChangeset for help on using the changeset viewer.