[3253] | 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;
|
---|
[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]
|
---|
[4128] | 36 | public class SymbolicRegressionProblem : SymbolicRegressionProblemBase, ISingleObjectiveProblem {
|
---|
[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]
|
---|
[4118] | 76 | protected SymbolicRegressionProblem(bool deserializing) : base(deserializing) { }
|
---|
[3253] | 77 | public SymbolicRegressionProblem()
|
---|
| 78 | : base() {
|
---|
[4341] | 79 | var evaluator = new SymbolicRegressionPearsonsRSquaredEvaluator();
|
---|
| 80 | Parameters.Add(new ValueParameter<BoolValue>("Maximization", "Set to false as the error of the regression model should be minimized.", (BoolValue)new BoolValue(true)));
|
---|
[3253] | 81 | Parameters.Add(new ValueParameter<ISymbolicRegressionEvaluator>("Evaluator", "The operator which should be used to evaluate symbolic regression solutions.", evaluator));
|
---|
[3452] | 82 | Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The minimal error value that reached by symbolic regression solutions for the problem."));
|
---|
[3253] | 83 |
|
---|
[4341] | 84 | evaluator.QualityParameter.ActualName = "TrainingPearsonR2";
|
---|
[3545] | 85 |
|
---|
[4128] | 86 | InitializeOperators();
|
---|
[3253] | 87 | ParameterizeEvaluator();
|
---|
| 88 |
|
---|
[4118] | 89 | RegisterParameterEvents();
|
---|
| 90 | RegisterParameterValueEvents();
|
---|
[3253] | 91 | }
|
---|
| 92 |
|
---|
[3452] | 93 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 94 | SymbolicRegressionProblem clone = (SymbolicRegressionProblem)base.Clone(cloner);
|
---|
[4118] | 95 | clone.RegisterParameterEvents();
|
---|
| 96 | clone.RegisterParameterValueEvents();
|
---|
[3452] | 97 | return clone;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
[3545] | 100 | private void RegisterParameterValueEvents() {
|
---|
| 101 | EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);
|
---|
[3269] | 102 | }
|
---|
| 103 |
|
---|
[4128] | 104 | private void RegisterParameterEvents() { }
|
---|
[3545] | 105 |
|
---|
| 106 | #region event handling
|
---|
| 107 | protected override void OnDataAnalysisProblemChanged(EventArgs e) {
|
---|
| 108 | base.OnDataAnalysisProblemChanged(e);
|
---|
[3800] | 109 | BestKnownQualityParameter.Value = null;
|
---|
[3545] | 110 | // paritions could be changed
|
---|
| 111 | ParameterizeEvaluator();
|
---|
[3651] | 112 | ParameterizeAnalyzers();
|
---|
[3480] | 113 | }
|
---|
[3532] | 114 |
|
---|
[4128] | 115 | protected override void OnSolutionParameterNameChanged(EventArgs e) {
|
---|
| 116 | base.OnSolutionParameterNameChanged(e);
|
---|
[3545] | 117 | ParameterizeEvaluator();
|
---|
[3651] | 118 | ParameterizeAnalyzers();
|
---|
[3294] | 119 | }
|
---|
| 120 |
|
---|
[4128] | 121 | protected override void OnEvaluatorChanged(EventArgs e) {
|
---|
| 122 | base.OnEvaluatorChanged(e);
|
---|
[3545] | 123 | ParameterizeEvaluator();
|
---|
[3651] | 124 | ParameterizeAnalyzers();
|
---|
[3545] | 125 | RaiseEvaluatorChanged(e);
|
---|
| 126 | }
|
---|
| 127 | #endregion
|
---|
[3513] | 128 |
|
---|
[3545] | 129 | #region event handlers
|
---|
| 130 | private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 131 | OnEvaluatorChanged(e);
|
---|
| 132 | }
|
---|
| 133 | #endregion
|
---|
[3253] | 134 |
|
---|
[3545] | 135 | #region Helpers
|
---|
[4098] | 136 | [StorableHook(HookType.AfterDeserialization)]
|
---|
[4118] | 137 | private void AfterDeserializationHook() {
|
---|
| 138 | // BackwardsCompatibility3.3
|
---|
| 139 | #region Backwards compatible code (remove with 3.4)
|
---|
[4128] | 140 | if (Operators == null || Operators.Count() == 0) InitializeOperators();
|
---|
[4118] | 141 | #endregion
|
---|
[3545] | 142 | RegisterParameterEvents();
|
---|
| 143 | RegisterParameterValueEvents();
|
---|
[3253] | 144 | }
|
---|
| 145 |
|
---|
| 146 | private void InitializeOperators() {
|
---|
[4128] | 147 | AddOperator(new FixedValidationBestScaledSymbolicRegressionSolutionAnalyzer());
|
---|
[3651] | 148 | ParameterizeAnalyzers();
|
---|
[3253] | 149 | }
|
---|
| 150 |
|
---|
| 151 | private void ParameterizeEvaluator() {
|
---|
[3452] | 152 | Evaluator.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
[3373] | 153 | Evaluator.RegressionProblemDataParameter.ActualName = DataAnalysisProblemDataParameter.Name;
|
---|
[3545] | 154 | Evaluator.SamplesStartParameter.Value = TrainingSamplesStart;
|
---|
| 155 | Evaluator.SamplesEndParameter.Value = TrainingSamplesEnd;
|
---|
[3253] | 156 | }
|
---|
[3545] | 157 |
|
---|
[3651] | 158 | private void ParameterizeAnalyzers() {
|
---|
| 159 | foreach (var analyzer in Analyzers) {
|
---|
| 160 | analyzer.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
[3996] | 161 | var fixedBestValidationSolutionAnalyzer = analyzer as FixedValidationBestScaledSymbolicRegressionSolutionAnalyzer;
|
---|
| 162 | if (fixedBestValidationSolutionAnalyzer != null) {
|
---|
| 163 | fixedBestValidationSolutionAnalyzer.ProblemDataParameter.ActualName = DataAnalysisProblemDataParameter.Name;
|
---|
| 164 | fixedBestValidationSolutionAnalyzer.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameter.Name;
|
---|
| 165 | fixedBestValidationSolutionAnalyzer.LowerEstimationLimitParameter.ActualName = LowerEstimationLimitParameter.Name;
|
---|
| 166 | fixedBestValidationSolutionAnalyzer.SymbolicExpressionTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
|
---|
| 167 | fixedBestValidationSolutionAnalyzer.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
| 168 | fixedBestValidationSolutionAnalyzer.ValidationSamplesStartParameter.Value = ValidationSamplesStart;
|
---|
| 169 | fixedBestValidationSolutionAnalyzer.ValidationSamplesEndParameter.Value = ValidationSamplesEnd;
|
---|
| 170 | fixedBestValidationSolutionAnalyzer.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name;
|
---|
| 171 | }
|
---|
[4127] | 172 | var bestValidationSolutionAnalyzer = analyzer as ValidationBestScaledSymbolicRegressionSolutionAnalyzer;
|
---|
[3651] | 173 | if (bestValidationSolutionAnalyzer != null) {
|
---|
| 174 | bestValidationSolutionAnalyzer.ProblemDataParameter.ActualName = DataAnalysisProblemDataParameter.Name;
|
---|
| 175 | bestValidationSolutionAnalyzer.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameter.Name;
|
---|
| 176 | bestValidationSolutionAnalyzer.LowerEstimationLimitParameter.ActualName = LowerEstimationLimitParameter.Name;
|
---|
| 177 | bestValidationSolutionAnalyzer.SymbolicExpressionTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
|
---|
| 178 | bestValidationSolutionAnalyzer.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
[3806] | 179 | bestValidationSolutionAnalyzer.ValidationSamplesStartParameter.Value = ValidationSamplesStart;
|
---|
| 180 | bestValidationSolutionAnalyzer.ValidationSamplesEndParameter.Value = ValidationSamplesEnd;
|
---|
[3791] | 181 | bestValidationSolutionAnalyzer.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name;
|
---|
[3800] | 182 | bestValidationSolutionAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
|
---|
[3651] | 183 | }
|
---|
| 184 | }
|
---|
[3253] | 185 | }
|
---|
| 186 | #endregion
|
---|
| 187 | }
|
---|
| 188 | }
|
---|