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