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 |
|
---|
22 | using System;
|
---|
23 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
24 | using HeuristicLab.MainForm;
|
---|
25 | using HeuristicLab.Problems.DataAnalysis.Symbolic.Views;
|
---|
26 |
|
---|
27 | namespace 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 UpdateModel(ISymbolicExpressionTree tree) {
|
---|
41 | var model = new SymbolicRegressionModel(Content.ProblemData.TargetVariable, tree, Content.Model.Interpreter, Content.Model.LowerEstimationLimit, Content.Model.UpperEstimationLimit);
|
---|
42 | model.Scale(Content.ProblemData);
|
---|
43 | Content.Model = model;
|
---|
44 | }
|
---|
45 |
|
---|
46 | protected override ISymbolicExpressionTree OptimizeConstants(ISymbolicExpressionTree tree, IProgress progress) {
|
---|
47 | const int constOptIterations = 50;
|
---|
48 | const int maxRepetitions = 1000;
|
---|
49 | var regressionProblemData = Content.ProblemData;
|
---|
50 | var model = Content.Model;
|
---|
51 | progress.CanBeStopped = true;
|
---|
52 | var prevResult = 0.0;
|
---|
53 | var result = 0.0;
|
---|
54 | int reps = 0;
|
---|
55 |
|
---|
56 | do {
|
---|
57 | prevResult = result;
|
---|
58 | result = SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(model.Interpreter, tree, regressionProblemData, regressionProblemData.TrainingIndices,
|
---|
59 | applyLinearScaling: true, maxIterations: constOptIterations, updateVariableWeights: true, lowerEstimationLimit: model.LowerEstimationLimit, upperEstimationLimit: model.UpperEstimationLimit,
|
---|
60 | iterationCallback: (args, func, obj) => {
|
---|
61 | double newProgressValue = progress.ProgressValue + 1.0 / (constOptIterations + 2); // (maxIterations + 2) iterations are reported
|
---|
62 | progress.ProgressValue = Math.Min(newProgressValue, 1.0);
|
---|
63 | });
|
---|
64 | reps++;
|
---|
65 | } while (prevResult < result && reps < maxRepetitions &&
|
---|
66 | progress.ProgressState != ProgressState.StopRequested &&
|
---|
67 | progress.ProgressState != ProgressState.CancelRequested);
|
---|
68 | return tree;
|
---|
69 | }
|
---|
70 | }
|
---|
71 | }
|
---|