Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3116_GAM_Interactions/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/InteractiveSymbolicRegressionSolutionSimplifierView.cs @ 18182

Last change on this file since 18182 was 17430, checked in by pfleck, 5 years ago

#2973

  • Fixed progress calculation for InteractiveSymbolicDataAnalysisSolutionSimplifierView.
  • Added a minimum improvement (of 1E-10) to stop constant opt.
  • Added tooltips for Simplify and Optimize.
File size: 3.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
24using HeuristicLab.MainForm;
25using HeuristicLab.Problems.DataAnalysis.Symbolic.Views;
26
27namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views {
28  public partial class InteractiveSymbolicRegressionSolutionSimplifierView : InteractiveSymbolicDataAnalysisSolutionSimplifierView {
29    public new SymbolicRegressionSolution Content {
30      get { return (SymbolicRegressionSolution)base.Content; }
31      set { base.Content = value; }
32    }
33
34    public InteractiveSymbolicRegressionSolutionSimplifierView()
35      : base(new SymbolicRegressionSolutionImpactValuesCalculator()) {
36      InitializeComponent();
37      this.Caption = "Interactive Regression Solution Simplifier";
38    }
39
40    protected override void SetEnabledStateOfControls() {
41      base.SetEnabledStateOfControls();
42
43      var tree = Content?.Model?.SymbolicExpressionTree;
44      btnOptimizeConstants.Enabled = tree != null && SymbolicRegressionConstantOptimizationEvaluator.CanOptimizeConstants(tree);
45    }
46
47    protected override void UpdateModel(ISymbolicExpressionTree tree) {
48      var model = new SymbolicRegressionModel(Content.ProblemData.TargetVariable, tree, Content.Model.Interpreter, Content.Model.LowerEstimationLimit, Content.Model.UpperEstimationLimit);
49      model.Scale(Content.ProblemData);
50      Content.Model = model;
51    }
52
53    protected override ISymbolicExpressionTree OptimizeConstants(ISymbolicExpressionTree tree, IProgress progress) {
54      const int constOptIterations = 50;
55      const int maxRepetitions = 100;
56      const double minimumImprovement = 1e-10;
57      var regressionProblemData = Content.ProblemData;
58      var model = Content.Model;
59      progress.CanBeStopped = true;
60      double prevResult = 0.0, improvement = 0.0;
61      var result = 0.0;
62      int reps = 0;
63
64      do {
65        prevResult = result;
66        result = SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(model.Interpreter, tree, regressionProblemData, regressionProblemData.TrainingIndices,
67          applyLinearScaling: true, maxIterations: constOptIterations, updateVariableWeights: true, lowerEstimationLimit: model.LowerEstimationLimit, upperEstimationLimit: model.UpperEstimationLimit,
68          iterationCallback: (args, func, obj) => {
69            double newProgressValue = progress.ProgressValue + (1.0 / (constOptIterations + 2) / maxRepetitions); // (constOptIterations + 2) iterations are reported
70            progress.ProgressValue = Math.Min(newProgressValue, 1.0);
71          });
72        reps++;
73        improvement = result - prevResult;
74      } while (improvement > minimumImprovement && reps < maxRepetitions &&
75               progress.ProgressState != ProgressState.StopRequested &&
76               progress.ProgressState != ProgressState.CancelRequested);
77      return tree;
78    }
79  }
80}
Note: See TracBrowser for help on using the repository browser.