Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/17/21 19:04:42 (3 years ago)
Author:
gkronber
Message:

#3125: merged r17976,r17978,r18020 from trunk to stable

Location:
stable
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Problems.DataAnalysis.Views

  • stable/HeuristicLab.Problems.DataAnalysis.Views/3.4

  • stable/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionErrorCharacteristicsCurveView.cs

    r17181 r18022  
    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        solutions.AddRange(CreateBaselineSolutions());
    109107        UpdateChart();
    110108      }
     
    114112      else {
    115113        // recalculate baseline solutions
    116         solutions.Clear(); // remove all
     114        solutions.Clear();
    117115        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());
    122117        UpdateChart();
    123118      }
     
    129124      ReadOnly = Content == null;
    130125      if (Content != null) {
    131         // recalculate all solutions
    132126        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());
    138128      }
    139129      UpdateChart();
     
    175165      UpdateSeries(residuals, solutionSeries);
    176166
    177       solutionSeries.ToolTip = "Area over Curve: " + CalculateAreaOverCurve(solutionSeries);
     167      solutionSeries.ToolTip = "Area over curve: " + CalculateAreaOverCurve(solutionSeries);
    178168      solutionSeries.LegendToolTip = "Double-click to open model";
    179169      chart.Series.Add(solutionSeries);
     
    249239    protected virtual List<double> GetResiduals(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues) {
    250240      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))
    252243            .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))
    254246            .Where(r => !double.IsNaN(r) && !double.IsInfinity(r)).ToList();
    255247        case "Relative error":
     
    289281
    290282    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;
    293288    }
    294289
    295290    private IRegressionSolution CreateConstantSolution() {
     291      if (!ProblemData.TrainingIndices.Any()) return null;
     292
    296293      double averageTrainingTarget = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices).Average();
    297294      var model = new ConstantModel(averageTrainingTarget, ProblemData.TargetVariable);
     
    301298    }
    302299    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;
    307310    }
    308311
Note: See TracChangeset for help on using the changeset viewer.