Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/InteractiveSymbolicRegressionSolutionSimplifierView.cs @ 17489

Last change on this file since 17489 was 17489, checked in by pfleck, 4 years ago

#3040 Added version with explicit array shapes for explicit broadcasting.

File size: 4.3 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 System.Threading;
24using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
25using HeuristicLab.MainForm;
26using HeuristicLab.Problems.DataAnalysis.Symbolic.Views;
27
28namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views {
29  public partial class InteractiveSymbolicRegressionSolutionSimplifierView : InteractiveSymbolicDataAnalysisSolutionSimplifierView {
30    public new SymbolicRegressionSolution Content {
31      get { return (SymbolicRegressionSolution)base.Content; }
32      set { base.Content = value; }
33    }
34
35    public InteractiveSymbolicRegressionSolutionSimplifierView()
36      : base(new SymbolicRegressionSolutionImpactValuesCalculator()) {
37      InitializeComponent();
38      this.Caption = "Interactive Regression Solution Simplifier";
39    }
40
41    protected override void SetEnabledStateOfControls() {
42      base.SetEnabledStateOfControls();
43
44      var tree = Content?.Model?.SymbolicExpressionTree;
45      //btnOptimizeConstants.Enabled = tree != null && NonlinearLeastSquaresConstantOptimizationEvaluator.CanOptimizeConstants(tree);
46      btnOptimizeConstants.Enabled = tree != null && TensorFlowConstantOptimizationEvaluator.CanOptimizeConstants(tree);
47    }
48
49    protected override void UpdateModel(ISymbolicExpressionTree tree) {
50      var model = new SymbolicRegressionModel(Content.ProblemData.TargetVariable, tree, Content.Model.Interpreter, Content.Model.LowerEstimationLimit, Content.Model.UpperEstimationLimit);
51      model.Scale(Content.ProblemData);
52      Content.Model = model;
53    }
54
55    protected override ISymbolicExpressionTree OptimizeConstants(ISymbolicExpressionTree tree, CancellationToken cancellationToken, IProgress progress) {
56      const int constOptIterations = 50;
57      const int maxRepetitions = 100;
58      const double minimumImprovement = 1e-10;
59      var regressionProblemData = Content.ProblemData;
60      var model = Content.Model;
61      progress.CanBeStopped = true;
62      double prevResult = 0.0, improvement = 0.0;
63      var result = 0.0;
64      int reps = 0;
65
66      do {
67        prevResult = result;
68        //tree = NonlinearLeastSquaresConstantOptimizationEvaluator.OptimizeTree(tree, regressionProblemData, regressionProblemData.TrainingIndices,
69        //  applyLinearScaling: true, maxIterations: constOptIterations, updateVariableWeights: true,
70        //  cancellationToken: cancellationToken, iterationCallback: (args, func, obj) => {
71        //    double newProgressValue = progress.ProgressValue + (1.0 / (constOptIterations + 2) / maxRepetitions); // (constOptIterations + 2) iterations are reported
72        //    progress.ProgressValue = Math.Min(newProgressValue, 1.0);
73        //  });
74        tree = TensorFlowConstantOptimizationEvaluator.OptimizeTree(tree, regressionProblemData, regressionProblemData.TrainingIndices,
75          applyLinearScaling: true, updateVariableWeights: true, maxIterations: 10, learningRate: 0.001);
76        result = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(model.Interpreter, tree,
77          model.LowerEstimationLimit, model.UpperEstimationLimit, regressionProblemData, regressionProblemData.TrainingIndices, applyLinearScaling: true);
78        reps++;
79        improvement = result - prevResult;
80      } while (improvement > minimumImprovement && reps < maxRepetitions &&
81               progress.ProgressState != ProgressState.StopRequested &&
82               progress.ProgressState != ProgressState.CancelRequested);
83      return tree;
84    }
85  }
86}
Note: See TracBrowser for help on using the repository browser.