[3253] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[5445] | 3 | * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[3253] | 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;
|
---|
[4068] | 30 | using HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Analyzers;
|
---|
[3253] | 31 |
|
---|
| 32 | namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic {
|
---|
[4128] | 33 | [Item("Symbolic Regression Problem (single objective)", "Represents a single objective symbolic regression problem.")]
|
---|
[3253] | 34 | [Creatable("Problems")]
|
---|
| 35 | [StorableClass]
|
---|
[4722] | 36 | public sealed class SymbolicRegressionProblem : SymbolicRegressionProblemBase, ISingleObjectiveDataAnalysisProblem {
|
---|
[3253] | 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 | }
|
---|
[4036] | 45 | public new ValueParameter<ISymbolicRegressionEvaluator> EvaluatorParameter {
|
---|
[3253] | 46 | get { return (ValueParameter<ISymbolicRegressionEvaluator>)Parameters["Evaluator"]; }
|
---|
| 47 | }
|
---|
| 48 | IParameter IProblem.EvaluatorParameter {
|
---|
| 49 | get { return EvaluatorParameter; }
|
---|
| 50 | }
|
---|
[3452] | 51 | public OptionalValueParameter<DoubleValue> BestKnownQualityParameter {
|
---|
| 52 | get { return (OptionalValueParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
|
---|
[3253] | 53 | }
|
---|
| 54 | IParameter ISingleObjectiveProblem.BestKnownQualityParameter {
|
---|
| 55 | get { return BestKnownQualityParameter; }
|
---|
| 56 | }
|
---|
| 57 | #endregion
|
---|
| 58 |
|
---|
| 59 | #region Properties
|
---|
[4036] | 60 | public new ISymbolicRegressionEvaluator Evaluator {
|
---|
[3253] | 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 |
|
---|
[4098] | 75 | [StorableConstructor]
|
---|
[4722] | 76 | private SymbolicRegressionProblem(bool deserializing) : base(deserializing) { }
|
---|
| 77 | private SymbolicRegressionProblem(SymbolicRegressionProblem original, Cloner cloner)
|
---|
| 78 | : base(original, cloner) {
|
---|
| 79 | RegisterParameterEvents();
|
---|
| 80 | RegisterParameterValueEvents();
|
---|
| 81 | }
|
---|
| 82 |
|
---|
[3253] | 83 | public SymbolicRegressionProblem()
|
---|
| 84 | : base() {
|
---|
[4250] | 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)));
|
---|
[3253] | 87 | Parameters.Add(new ValueParameter<ISymbolicRegressionEvaluator>("Evaluator", "The operator which should be used to evaluate symbolic regression solutions.", evaluator));
|
---|
[3452] | 88 | Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The minimal error value that reached by symbolic regression solutions for the problem."));
|
---|
[3253] | 89 |
|
---|
[4128] | 90 | InitializeOperators();
|
---|
[3253] | 91 | ParameterizeEvaluator();
|
---|
| 92 |
|
---|
[4118] | 93 | RegisterParameterEvents();
|
---|
| 94 | RegisterParameterValueEvents();
|
---|
[3253] | 95 | }
|
---|
| 96 |
|
---|
[3452] | 97 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[4722] | 98 | return new SymbolicRegressionProblem(this, cloner);
|
---|
[3452] | 99 | }
|
---|
| 100 |
|
---|
[3545] | 101 | private void RegisterParameterValueEvents() {
|
---|
| 102 | EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);
|
---|
[3269] | 103 | }
|
---|
| 104 |
|
---|
[4128] | 105 | private void RegisterParameterEvents() { }
|
---|
[3545] | 106 |
|
---|
| 107 | #region event handling
|
---|
| 108 | protected override void OnDataAnalysisProblemChanged(EventArgs e) {
|
---|
| 109 | base.OnDataAnalysisProblemChanged(e);
|
---|
[3800] | 110 | BestKnownQualityParameter.Value = null;
|
---|
[3545] | 111 | // paritions could be changed
|
---|
| 112 | ParameterizeEvaluator();
|
---|
[3651] | 113 | ParameterizeAnalyzers();
|
---|
[3480] | 114 | }
|
---|
[3532] | 115 |
|
---|
[4128] | 116 | protected override void OnSolutionParameterNameChanged(EventArgs e) {
|
---|
| 117 | base.OnSolutionParameterNameChanged(e);
|
---|
[3545] | 118 | ParameterizeEvaluator();
|
---|
[3651] | 119 | ParameterizeAnalyzers();
|
---|
[3294] | 120 | }
|
---|
| 121 |
|
---|
[4128] | 122 | protected override void OnEvaluatorChanged(EventArgs e) {
|
---|
| 123 | base.OnEvaluatorChanged(e);
|
---|
[3545] | 124 | ParameterizeEvaluator();
|
---|
[3651] | 125 | ParameterizeAnalyzers();
|
---|
[5365] | 126 | ParameterizeProblem();
|
---|
[3545] | 127 | RaiseEvaluatorChanged(e);
|
---|
| 128 | }
|
---|
| 129 | #endregion
|
---|
[3513] | 130 |
|
---|
[3545] | 131 | #region event handlers
|
---|
| 132 | private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 133 | OnEvaluatorChanged(e);
|
---|
| 134 | }
|
---|
| 135 | #endregion
|
---|
[3253] | 136 |
|
---|
[3545] | 137 | #region Helpers
|
---|
[4098] | 138 | [StorableHook(HookType.AfterDeserialization)]
|
---|
[4118] | 139 | private void AfterDeserializationHook() {
|
---|
| 140 | // BackwardsCompatibility3.3
|
---|
| 141 | #region Backwards compatible code (remove with 3.4)
|
---|
[4128] | 142 | if (Operators == null || Operators.Count() == 0) InitializeOperators();
|
---|
[4118] | 143 | #endregion
|
---|
[3545] | 144 | RegisterParameterEvents();
|
---|
| 145 | RegisterParameterValueEvents();
|
---|
[3253] | 146 | }
|
---|
| 147 |
|
---|
| 148 | private void InitializeOperators() {
|
---|
[4128] | 149 | AddOperator(new FixedValidationBestScaledSymbolicRegressionSolutionAnalyzer());
|
---|
[5260] | 150 | AddOperator(new SymbolicRegressionOverfittingAnalyzer());
|
---|
[5331] | 151 | AddOperator(new TrainingBestScaledSymbolicRegressionSolutionAnalyzer());
|
---|
[3651] | 152 | ParameterizeAnalyzers();
|
---|
[3253] | 153 | }
|
---|
| 154 |
|
---|
| 155 | private void ParameterizeEvaluator() {
|
---|
[3452] | 156 | Evaluator.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
[3373] | 157 | Evaluator.RegressionProblemDataParameter.ActualName = DataAnalysisProblemDataParameter.Name;
|
---|
[3545] | 158 | Evaluator.SamplesStartParameter.Value = TrainingSamplesStart;
|
---|
| 159 | Evaluator.SamplesEndParameter.Value = TrainingSamplesEnd;
|
---|
[3253] | 160 | }
|
---|
[3545] | 161 |
|
---|
[3651] | 162 | private void ParameterizeAnalyzers() {
|
---|
| 163 | foreach (var analyzer in Analyzers) {
|
---|
| 164 | analyzer.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
[5260] | 165 | var validationSolutionAnalyzer = analyzer as SymbolicRegressionValidationAnalyzer;
|
---|
| 166 | if (validationSolutionAnalyzer != null) {
|
---|
| 167 | validationSolutionAnalyzer.ProblemDataParameter.ActualName = DataAnalysisProblemDataParameter.Name;
|
---|
| 168 | validationSolutionAnalyzer.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameter.Name;
|
---|
| 169 | validationSolutionAnalyzer.LowerEstimationLimitParameter.ActualName = LowerEstimationLimitParameter.Name;
|
---|
| 170 | validationSolutionAnalyzer.SymbolicExpressionTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
|
---|
| 171 | validationSolutionAnalyzer.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
| 172 | validationSolutionAnalyzer.ValidationSamplesStartParameter.Value = ValidationSamplesStart;
|
---|
| 173 | validationSolutionAnalyzer.ValidationSamplesEndParameter.Value = ValidationSamplesEnd;
|
---|
| 174 | }
|
---|
| 175 |
|
---|
[3996] | 176 | var fixedBestValidationSolutionAnalyzer = analyzer as FixedValidationBestScaledSymbolicRegressionSolutionAnalyzer;
|
---|
| 177 | if (fixedBestValidationSolutionAnalyzer != null) {
|
---|
| 178 | fixedBestValidationSolutionAnalyzer.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name;
|
---|
| 179 | }
|
---|
[4468] | 180 |
|
---|
[4127] | 181 | var bestValidationSolutionAnalyzer = analyzer as ValidationBestScaledSymbolicRegressionSolutionAnalyzer;
|
---|
[3651] | 182 | if (bestValidationSolutionAnalyzer != null) {
|
---|
| 183 | bestValidationSolutionAnalyzer.ProblemDataParameter.ActualName = DataAnalysisProblemDataParameter.Name;
|
---|
| 184 | bestValidationSolutionAnalyzer.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameter.Name;
|
---|
| 185 | bestValidationSolutionAnalyzer.LowerEstimationLimitParameter.ActualName = LowerEstimationLimitParameter.Name;
|
---|
| 186 | bestValidationSolutionAnalyzer.SymbolicExpressionTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
|
---|
| 187 | bestValidationSolutionAnalyzer.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
[3806] | 188 | bestValidationSolutionAnalyzer.ValidationSamplesStartParameter.Value = ValidationSamplesStart;
|
---|
| 189 | bestValidationSolutionAnalyzer.ValidationSamplesEndParameter.Value = ValidationSamplesEnd;
|
---|
[3791] | 190 | bestValidationSolutionAnalyzer.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name;
|
---|
[3800] | 191 | bestValidationSolutionAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
|
---|
[3651] | 192 | }
|
---|
| 193 | }
|
---|
[3253] | 194 | }
|
---|
[5365] | 195 |
|
---|
| 196 | private void ParameterizeProblem() {
|
---|
| 197 | if (MaximizationParameter.Value != null) {
|
---|
| 198 | MaximizationParameter.Value.Value = Evaluator.Maximization;
|
---|
| 199 | } else {
|
---|
| 200 | MaximizationParameter.Value = new BoolValue(Evaluator.Maximization);
|
---|
| 201 | }
|
---|
| 202 | }
|
---|
[3253] | 203 | #endregion
|
---|
| 204 | }
|
---|
| 205 | }
|
---|