1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2010 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 System.Linq;
|
---|
24 | using HeuristicLab.Common;
|
---|
25 | using HeuristicLab.Core;
|
---|
26 | using HeuristicLab.Data;
|
---|
27 | using HeuristicLab.Optimization;
|
---|
28 | using HeuristicLab.Parameters;
|
---|
29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
30 | using HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Analyzers;
|
---|
31 |
|
---|
32 | namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic {
|
---|
33 | [Item("Symbolic Regression Problem (single objective)", "Represents a single objective symbolic regression problem.")]
|
---|
34 | [Creatable("Problems")]
|
---|
35 | [StorableClass]
|
---|
36 | public sealed class SymbolicRegressionProblem : SymbolicRegressionProblemBase, ISingleObjectiveDataAnalysisProblem {
|
---|
37 |
|
---|
38 | #region Parameter Properties
|
---|
39 | public ValueParameter<BoolValue> MaximizationParameter {
|
---|
40 | get { return (ValueParameter<BoolValue>)Parameters["Maximization"]; }
|
---|
41 | }
|
---|
42 | IParameter ISingleObjectiveProblem.MaximizationParameter {
|
---|
43 | get { return MaximizationParameter; }
|
---|
44 | }
|
---|
45 | public new ValueParameter<ISymbolicRegressionEvaluator> EvaluatorParameter {
|
---|
46 | get { return (ValueParameter<ISymbolicRegressionEvaluator>)Parameters["Evaluator"]; }
|
---|
47 | }
|
---|
48 | IParameter IProblem.EvaluatorParameter {
|
---|
49 | get { return EvaluatorParameter; }
|
---|
50 | }
|
---|
51 | public OptionalValueParameter<DoubleValue> BestKnownQualityParameter {
|
---|
52 | get { return (OptionalValueParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
|
---|
53 | }
|
---|
54 | IParameter ISingleObjectiveProblem.BestKnownQualityParameter {
|
---|
55 | get { return BestKnownQualityParameter; }
|
---|
56 | }
|
---|
57 | #endregion
|
---|
58 |
|
---|
59 | #region Properties
|
---|
60 | public new ISymbolicRegressionEvaluator Evaluator {
|
---|
61 | get { return EvaluatorParameter.Value; }
|
---|
62 | set { EvaluatorParameter.Value = value; }
|
---|
63 | }
|
---|
64 | ISingleObjectiveEvaluator ISingleObjectiveProblem.Evaluator {
|
---|
65 | get { return EvaluatorParameter.Value; }
|
---|
66 | }
|
---|
67 | IEvaluator IProblem.Evaluator {
|
---|
68 | get { return EvaluatorParameter.Value; }
|
---|
69 | }
|
---|
70 | public DoubleValue BestKnownQuality {
|
---|
71 | get { return BestKnownQualityParameter.Value; }
|
---|
72 | }
|
---|
73 | #endregion
|
---|
74 |
|
---|
75 | [StorableConstructor]
|
---|
76 | private SymbolicRegressionProblem(bool deserializing) : base(deserializing) { }
|
---|
77 | private SymbolicRegressionProblem(SymbolicRegressionProblem original, Cloner cloner)
|
---|
78 | : base(original, cloner) {
|
---|
79 | RegisterParameterEvents();
|
---|
80 | RegisterParameterValueEvents();
|
---|
81 | }
|
---|
82 |
|
---|
83 | public SymbolicRegressionProblem()
|
---|
84 | : base() {
|
---|
85 | var evaluator = new SymbolicRegressionPearsonsRSquaredEvaluator();
|
---|
86 | Parameters.Add(new ValueParameter<BoolValue>("Maximization", "Set to false as the error of the regression model should be minimized.", (BoolValue)new BoolValue(true)));
|
---|
87 | Parameters.Add(new ValueParameter<ISymbolicRegressionEvaluator>("Evaluator", "The operator which should be used to evaluate symbolic regression solutions.", evaluator));
|
---|
88 | Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The minimal error value that reached by symbolic regression solutions for the problem."));
|
---|
89 |
|
---|
90 | evaluator.QualityParameter.ActualName = "TrainingPearsonR2";
|
---|
91 |
|
---|
92 | InitializeOperators();
|
---|
93 | ParameterizeEvaluator();
|
---|
94 |
|
---|
95 | RegisterParameterEvents();
|
---|
96 | RegisterParameterValueEvents();
|
---|
97 | }
|
---|
98 |
|
---|
99 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
100 | return new SymbolicRegressionProblem(this, cloner);
|
---|
101 | }
|
---|
102 |
|
---|
103 | private void RegisterParameterValueEvents() {
|
---|
104 | EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);
|
---|
105 | }
|
---|
106 |
|
---|
107 | private void RegisterParameterEvents() { }
|
---|
108 |
|
---|
109 | #region event handling
|
---|
110 | protected override void OnDataAnalysisProblemChanged(EventArgs e) {
|
---|
111 | base.OnDataAnalysisProblemChanged(e);
|
---|
112 | BestKnownQualityParameter.Value = null;
|
---|
113 | // paritions could be changed
|
---|
114 | ParameterizeEvaluator();
|
---|
115 | ParameterizeAnalyzers();
|
---|
116 | }
|
---|
117 |
|
---|
118 | protected override void OnSolutionParameterNameChanged(EventArgs e) {
|
---|
119 | base.OnSolutionParameterNameChanged(e);
|
---|
120 | ParameterizeEvaluator();
|
---|
121 | ParameterizeAnalyzers();
|
---|
122 | }
|
---|
123 |
|
---|
124 | protected override void OnEvaluatorChanged(EventArgs e) {
|
---|
125 | base.OnEvaluatorChanged(e);
|
---|
126 | ParameterizeEvaluator();
|
---|
127 | ParameterizeAnalyzers();
|
---|
128 | RaiseEvaluatorChanged(e);
|
---|
129 | }
|
---|
130 | #endregion
|
---|
131 |
|
---|
132 | #region event handlers
|
---|
133 | private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) {
|
---|
134 | OnEvaluatorChanged(e);
|
---|
135 | }
|
---|
136 | #endregion
|
---|
137 |
|
---|
138 | #region Helpers
|
---|
139 | [StorableHook(HookType.AfterDeserialization)]
|
---|
140 | private void AfterDeserializationHook() {
|
---|
141 | // BackwardsCompatibility3.3
|
---|
142 | #region Backwards compatible code (remove with 3.4)
|
---|
143 | if (Operators == null || Operators.Count() == 0) InitializeOperators();
|
---|
144 | #endregion
|
---|
145 | RegisterParameterEvents();
|
---|
146 | RegisterParameterValueEvents();
|
---|
147 | }
|
---|
148 |
|
---|
149 | private void InitializeOperators() {
|
---|
150 | AddOperator(new FixedValidationBestScaledSymbolicRegressionSolutionAnalyzer());
|
---|
151 | ParameterizeAnalyzers();
|
---|
152 | }
|
---|
153 |
|
---|
154 | private void ParameterizeEvaluator() {
|
---|
155 | Evaluator.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
156 | Evaluator.RegressionProblemDataParameter.ActualName = DataAnalysisProblemDataParameter.Name;
|
---|
157 | Evaluator.SamplesStartParameter.Value = TrainingSamplesStart;
|
---|
158 | Evaluator.SamplesEndParameter.Value = TrainingSamplesEnd;
|
---|
159 | }
|
---|
160 |
|
---|
161 | private void ParameterizeAnalyzers() {
|
---|
162 | foreach (var analyzer in Analyzers) {
|
---|
163 | analyzer.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
164 | var fixedBestValidationSolutionAnalyzer = analyzer as FixedValidationBestScaledSymbolicRegressionSolutionAnalyzer;
|
---|
165 | if (fixedBestValidationSolutionAnalyzer != null) {
|
---|
166 | fixedBestValidationSolutionAnalyzer.ProblemDataParameter.ActualName = DataAnalysisProblemDataParameter.Name;
|
---|
167 | fixedBestValidationSolutionAnalyzer.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameter.Name;
|
---|
168 | fixedBestValidationSolutionAnalyzer.LowerEstimationLimitParameter.ActualName = LowerEstimationLimitParameter.Name;
|
---|
169 | fixedBestValidationSolutionAnalyzer.SymbolicExpressionTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
|
---|
170 | fixedBestValidationSolutionAnalyzer.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
171 | fixedBestValidationSolutionAnalyzer.ValidationSamplesStartParameter.Value = ValidationSamplesStart;
|
---|
172 | fixedBestValidationSolutionAnalyzer.ValidationSamplesEndParameter.Value = ValidationSamplesEnd;
|
---|
173 | fixedBestValidationSolutionAnalyzer.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name;
|
---|
174 | }
|
---|
175 |
|
---|
176 | var bestValidationSolutionAnalyzer = analyzer as ValidationBestScaledSymbolicRegressionSolutionAnalyzer;
|
---|
177 | if (bestValidationSolutionAnalyzer != null) {
|
---|
178 | bestValidationSolutionAnalyzer.ProblemDataParameter.ActualName = DataAnalysisProblemDataParameter.Name;
|
---|
179 | bestValidationSolutionAnalyzer.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameter.Name;
|
---|
180 | bestValidationSolutionAnalyzer.LowerEstimationLimitParameter.ActualName = LowerEstimationLimitParameter.Name;
|
---|
181 | bestValidationSolutionAnalyzer.SymbolicExpressionTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
|
---|
182 | bestValidationSolutionAnalyzer.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
183 | bestValidationSolutionAnalyzer.ValidationSamplesStartParameter.Value = ValidationSamplesStart;
|
---|
184 | bestValidationSolutionAnalyzer.ValidationSamplesEndParameter.Value = ValidationSamplesEnd;
|
---|
185 | bestValidationSolutionAnalyzer.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name;
|
---|
186 | bestValidationSolutionAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
|
---|
187 | }
|
---|
188 | }
|
---|
189 | }
|
---|
190 | #endregion
|
---|
191 | }
|
---|
192 | }
|
---|