Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/16/21 21:35:37 (4 years ago)
Author:
gkronber
Message:

#3128: first dump of exploratory work-in-progress code to make sure the working copy is not lost.

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

    r17180 r17991  
    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 _, 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  }
  • branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionErrorCharacteristicsCurveView.cs

    r17180 r17991  
    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(); }
     
    103104        solutions.Clear(); // remove all
    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      }
     
    116114        solutions.Clear(); // remove all
    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      }
     
    249244    protected virtual List<double> GetResiduals(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues) {
    250245      switch (residualComboBox.SelectedItem.ToString()) {
    251         case "Absolute error": return originalValues.Zip(estimatedValues, (x, y) => Math.Abs(x - y))
     246        case "Absolute error":
     247          return originalValues.Zip(estimatedValues, (x, y) => Math.Abs(x - y))
    252248            .Where(r => !double.IsNaN(r) && !double.IsInfinity(r)).ToList();
    253         case "Squared error": return originalValues.Zip(estimatedValues, (x, y) => (x - y) * (x - y))
     249        case "Squared error":
     250          return originalValues.Zip(estimatedValues, (x, y) => (x - y) * (x - y))
    254251            .Where(r => !double.IsNaN(r) && !double.IsInfinity(r)).ToList();
    255252        case "Relative error":
     
    289286
    290287    protected virtual IEnumerable<IRegressionSolution> CreateBaselineSolutions() {
    291       yield return CreateConstantSolution();
    292       yield return CreateLinearSolution();
     288      var constantSolution = CreateConstantSolution();
     289      if (constantSolution != null) yield return CreateConstantSolution();
     290
     291      var linearRegressionSolution = CreateLinearSolution();
     292      if (linearRegressionSolution != null) yield return CreateLinearSolution();
    293293    }
    294294
    295295    private IRegressionSolution CreateConstantSolution() {
     296      if (!ProblemData.TrainingIndices.Any()) return null;
     297
    296298      double averageTrainingTarget = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices).Average();
    297299      var model = new ConstantModel(averageTrainingTarget, ProblemData.TargetVariable);
     
    301303    }
    302304    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;
     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;
    307315    }
    308316
Note: See TracChangeset for help on using the changeset viewer.