[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 System.Drawing;
|
---|
| 26 | using HeuristicLab.Common;
|
---|
| 27 | using HeuristicLab.Core;
|
---|
| 28 | using HeuristicLab.Data;
|
---|
| 29 | using HeuristicLab.Optimization;
|
---|
| 30 | using HeuristicLab.Parameters;
|
---|
| 31 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 32 | using HeuristicLab.PluginInfrastructure;
|
---|
| 33 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
| 34 | using HeuristicLab.Problems.DataAnalysis.Regression;
|
---|
[3373] | 35 | using HeuristicLab.Problems.DataAnalysis.Symbolic;
|
---|
[3539] | 36 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureManipulators;
|
---|
[3462] | 37 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Manipulators;
|
---|
| 38 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Crossovers;
|
---|
| 39 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators;
|
---|
[3534] | 40 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces;
|
---|
[3651] | 41 | using HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Analyzers;
|
---|
| 42 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Analyzers;
|
---|
[3253] | 43 |
|
---|
| 44 | namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic {
|
---|
[3528] | 45 | [Item("Symbolic Regression Problem", "Represents a symbolic regression problem.")]
|
---|
[3253] | 46 | [Creatable("Problems")]
|
---|
| 47 | [StorableClass]
|
---|
[3545] | 48 | public class SymbolicRegressionProblem : DataAnalysisProblem, ISingleObjectiveProblem {
|
---|
[3253] | 49 |
|
---|
| 50 | #region Parameter Properties
|
---|
| 51 | public ValueParameter<BoolValue> MaximizationParameter {
|
---|
| 52 | get { return (ValueParameter<BoolValue>)Parameters["Maximization"]; }
|
---|
| 53 | }
|
---|
| 54 | IParameter ISingleObjectiveProblem.MaximizationParameter {
|
---|
| 55 | get { return MaximizationParameter; }
|
---|
| 56 | }
|
---|
| 57 | public ValueParameter<SymbolicExpressionTreeCreator> SolutionCreatorParameter {
|
---|
| 58 | get { return (ValueParameter<SymbolicExpressionTreeCreator>)Parameters["SolutionCreator"]; }
|
---|
| 59 | }
|
---|
| 60 | IParameter IProblem.SolutionCreatorParameter {
|
---|
| 61 | get { return SolutionCreatorParameter; }
|
---|
| 62 | }
|
---|
[3513] | 63 | public ValueParameter<DoubleValue> LowerEstimationLimitParameter {
|
---|
| 64 | get { return (ValueParameter<DoubleValue>)Parameters["LowerEstimationLimit"]; }
|
---|
| 65 | }
|
---|
| 66 | public ValueParameter<DoubleValue> UpperEstimationLimitParameter {
|
---|
| 67 | get { return (ValueParameter<DoubleValue>)Parameters["UpperEstimationLimit"]; }
|
---|
| 68 | }
|
---|
| 69 | public ValueParameter<ISymbolicExpressionTreeInterpreter> SymbolicExpressionTreeInterpreterParameter {
|
---|
| 70 | get { return (ValueParameter<ISymbolicExpressionTreeInterpreter>)Parameters["SymbolicExpressionTreeInterpreter"]; }
|
---|
| 71 | }
|
---|
[3253] | 72 | public ValueParameter<ISymbolicRegressionEvaluator> EvaluatorParameter {
|
---|
| 73 | get { return (ValueParameter<ISymbolicRegressionEvaluator>)Parameters["Evaluator"]; }
|
---|
| 74 | }
|
---|
| 75 | IParameter IProblem.EvaluatorParameter {
|
---|
| 76 | get { return EvaluatorParameter; }
|
---|
| 77 | }
|
---|
| 78 | public ValueParameter<ISymbolicExpressionGrammar> FunctionTreeGrammarParameter {
|
---|
| 79 | get { return (ValueParameter<ISymbolicExpressionGrammar>)Parameters["FunctionTreeGrammar"]; }
|
---|
| 80 | }
|
---|
| 81 | public ValueParameter<IntValue> MaxExpressionLengthParameter {
|
---|
| 82 | get { return (ValueParameter<IntValue>)Parameters["MaxExpressionLength"]; }
|
---|
| 83 | }
|
---|
| 84 | public ValueParameter<IntValue> MaxExpressionDepthParameter {
|
---|
| 85 | get { return (ValueParameter<IntValue>)Parameters["MaxExpressionDepth"]; }
|
---|
| 86 | }
|
---|
[3294] | 87 | public ValueParameter<IntValue> MaxFunctionDefiningBranchesParameter {
|
---|
| 88 | get { return (ValueParameter<IntValue>)Parameters["MaxFunctionDefiningBranches"]; }
|
---|
| 89 | }
|
---|
| 90 | public ValueParameter<IntValue> MaxFunctionArgumentsParameter {
|
---|
| 91 | get { return (ValueParameter<IntValue>)Parameters["MaxFunctionArguments"]; }
|
---|
| 92 | }
|
---|
[3452] | 93 | public OptionalValueParameter<DoubleValue> BestKnownQualityParameter {
|
---|
| 94 | get { return (OptionalValueParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
|
---|
[3253] | 95 | }
|
---|
| 96 | IParameter ISingleObjectiveProblem.BestKnownQualityParameter {
|
---|
| 97 | get { return BestKnownQualityParameter; }
|
---|
| 98 | }
|
---|
| 99 | #endregion
|
---|
| 100 |
|
---|
| 101 | #region Properties
|
---|
| 102 | public IntValue MaxExpressionLength {
|
---|
| 103 | get { return MaxExpressionLengthParameter.Value; }
|
---|
| 104 | set { MaxExpressionLengthParameter.Value = value; }
|
---|
| 105 | }
|
---|
| 106 | public IntValue MaxExpressionDepth {
|
---|
| 107 | get { return MaxExpressionDepthParameter.Value; }
|
---|
| 108 | set { MaxExpressionDepthParameter.Value = value; }
|
---|
| 109 | }
|
---|
[3532] | 110 | public IntValue MaxFunctionDefiningBranches {
|
---|
| 111 | get { return MaxFunctionDefiningBranchesParameter.Value; }
|
---|
| 112 | set { MaxFunctionDefiningBranchesParameter.Value = value; }
|
---|
| 113 | }
|
---|
| 114 | public IntValue MaxFunctionArguments {
|
---|
| 115 | get { return MaxFunctionArgumentsParameter.Value; }
|
---|
| 116 | set { MaxFunctionArgumentsParameter.Value = value; }
|
---|
| 117 | }
|
---|
[3253] | 118 | public SymbolicExpressionTreeCreator SolutionCreator {
|
---|
| 119 | get { return SolutionCreatorParameter.Value; }
|
---|
| 120 | set { SolutionCreatorParameter.Value = value; }
|
---|
| 121 | }
|
---|
| 122 | ISolutionCreator IProblem.SolutionCreator {
|
---|
| 123 | get { return SolutionCreatorParameter.Value; }
|
---|
| 124 | }
|
---|
[3513] | 125 | public ISymbolicExpressionTreeInterpreter SymbolicExpressionTreeInterpreter {
|
---|
| 126 | get { return SymbolicExpressionTreeInterpreterParameter.Value; }
|
---|
| 127 | set { SymbolicExpressionTreeInterpreterParameter.Value = value; }
|
---|
| 128 | }
|
---|
| 129 | public DoubleValue LowerEstimationLimit {
|
---|
| 130 | get { return LowerEstimationLimitParameter.Value; }
|
---|
| 131 | set { LowerEstimationLimitParameter.Value = value; }
|
---|
| 132 | }
|
---|
| 133 | public DoubleValue UpperEstimationLimit {
|
---|
| 134 | get { return UpperEstimationLimitParameter.Value; }
|
---|
| 135 | set { UpperEstimationLimitParameter.Value = value; }
|
---|
| 136 | }
|
---|
| 137 |
|
---|
[3253] | 138 | public ISymbolicRegressionEvaluator Evaluator {
|
---|
| 139 | get { return EvaluatorParameter.Value; }
|
---|
| 140 | set { EvaluatorParameter.Value = value; }
|
---|
| 141 | }
|
---|
| 142 | ISingleObjectiveEvaluator ISingleObjectiveProblem.Evaluator {
|
---|
| 143 | get { return EvaluatorParameter.Value; }
|
---|
| 144 | }
|
---|
| 145 | IEvaluator IProblem.Evaluator {
|
---|
| 146 | get { return EvaluatorParameter.Value; }
|
---|
| 147 | }
|
---|
[3442] | 148 | public ISymbolicExpressionGrammar FunctionTreeGrammar {
|
---|
| 149 | get { return (ISymbolicExpressionGrammar)FunctionTreeGrammarParameter.Value; }
|
---|
[3253] | 150 | }
|
---|
| 151 | public DoubleValue BestKnownQuality {
|
---|
| 152 | get { return BestKnownQualityParameter.Value; }
|
---|
| 153 | }
|
---|
[3651] | 154 | private List<IOperator> operators;
|
---|
[3253] | 155 | public IEnumerable<IOperator> Operators {
|
---|
[3651] | 156 | get { return operators; }
|
---|
[3253] | 157 | }
|
---|
[3681] | 158 | public IEnumerable<ISymbolicRegressionAnalyzer> Analyzers {
|
---|
| 159 | get { return operators.OfType<ISymbolicRegressionAnalyzer>(); }
|
---|
[3651] | 160 | }
|
---|
[3513] | 161 | public DoubleValue PunishmentFactor {
|
---|
| 162 | get { return new DoubleValue(10.0); }
|
---|
| 163 | }
|
---|
[3545] | 164 | public IntValue TrainingSamplesStart {
|
---|
| 165 | get { return new IntValue(DataAnalysisProblemData.TrainingSamplesStart.Value); }
|
---|
| 166 | }
|
---|
| 167 | public IntValue TrainingSamplesEnd {
|
---|
| 168 | get {
|
---|
| 169 | return new IntValue((DataAnalysisProblemData.TrainingSamplesStart.Value +
|
---|
| 170 | DataAnalysisProblemData.TrainingSamplesEnd.Value) / 2);
|
---|
| 171 | }
|
---|
| 172 | }
|
---|
| 173 | public IntValue ValidationSamplesStart {
|
---|
| 174 | get { return TrainingSamplesEnd; }
|
---|
| 175 | }
|
---|
| 176 | public IntValue ValidationSamplesEnd {
|
---|
| 177 | get { return new IntValue(DataAnalysisProblemData.TrainingSamplesEnd.Value); }
|
---|
| 178 | }
|
---|
[3666] | 179 | public IntValue TestSamplesStart {
|
---|
| 180 | get { return DataAnalysisProblemData.TestSamplesStart; }
|
---|
| 181 | }
|
---|
| 182 | public IntValue TestSamplesEnd {
|
---|
| 183 | get { return DataAnalysisProblemData.TestSamplesEnd; }
|
---|
| 184 | }
|
---|
[3253] | 185 | #endregion
|
---|
| 186 |
|
---|
| 187 | public SymbolicRegressionProblem()
|
---|
| 188 | : base() {
|
---|
| 189 | SymbolicExpressionTreeCreator creator = new ProbabilisticTreeCreator();
|
---|
[3532] | 190 | var evaluator = new SymbolicRegressionScaledMeanSquaredErrorEvaluator();
|
---|
[3442] | 191 | var grammar = new ArithmeticExpressionGrammar();
|
---|
| 192 | var globalGrammar = new GlobalSymbolicExpressionGrammar(grammar);
|
---|
[3462] | 193 | var interpreter = new SimpleArithmeticExpressionInterpreter();
|
---|
[3545] | 194 | 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] | 195 | Parameters.Add(new ValueParameter<SymbolicExpressionTreeCreator>("SolutionCreator", "The operator which should be used to create new symbolic regression solutions.", creator));
|
---|
[3462] | 196 | Parameters.Add(new ValueParameter<ISymbolicExpressionTreeInterpreter>("SymbolicExpressionTreeInterpreter", "The interpreter that should be used to evaluate the symbolic expression tree.", interpreter));
|
---|
[3253] | 197 | Parameters.Add(new ValueParameter<ISymbolicRegressionEvaluator>("Evaluator", "The operator which should be used to evaluate symbolic regression solutions.", evaluator));
|
---|
[3513] | 198 | Parameters.Add(new ValueParameter<DoubleValue>("LowerEstimationLimit", "The lower limit for the estimated value that can be returned by the symbolic regression model.", new DoubleValue(double.NegativeInfinity)));
|
---|
| 199 | Parameters.Add(new ValueParameter<DoubleValue>("UpperEstimationLimit", "The upper limit for the estimated value that can be returned by the symbolic regression model.", new DoubleValue(double.PositiveInfinity)));
|
---|
[3452] | 200 | Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The minimal error value that reached by symbolic regression solutions for the problem."));
|
---|
[3442] | 201 | Parameters.Add(new ValueParameter<ISymbolicExpressionGrammar>("FunctionTreeGrammar", "The grammar that should be used for symbolic regression models.", globalGrammar));
|
---|
[3253] | 202 | Parameters.Add(new ValueParameter<IntValue>("MaxExpressionLength", "Maximal length of the symbolic expression.", new IntValue(100)));
|
---|
| 203 | Parameters.Add(new ValueParameter<IntValue>("MaxExpressionDepth", "Maximal depth of the symbolic expression.", new IntValue(10)));
|
---|
[3545] | 204 | Parameters.Add(new ValueParameter<IntValue>("MaxFunctionDefiningBranches", "Maximal number of automatically defined functions.", (IntValue)new IntValue(0).AsReadOnly()));
|
---|
| 205 | Parameters.Add(new ValueParameter<IntValue>("MaxFunctionArguments", "Maximal number of arguments of automatically defined functions.", (IntValue)new IntValue(0).AsReadOnly()));
|
---|
[3253] | 206 |
|
---|
| 207 | creator.SymbolicExpressionTreeParameter.ActualName = "SymbolicRegressionModel";
|
---|
[3545] | 208 | evaluator.QualityParameter.ActualName = "TrainingMeanSquaredError";
|
---|
| 209 |
|
---|
[3253] | 210 | ParameterizeSolutionCreator();
|
---|
| 211 | ParameterizeEvaluator();
|
---|
| 212 |
|
---|
[3545] | 213 | UpdateGrammar();
|
---|
| 214 | UpdateEstimationLimits();
|
---|
[3253] | 215 | Initialize();
|
---|
| 216 | }
|
---|
| 217 |
|
---|
[3452] | 218 | [StorableConstructor]
|
---|
| 219 | private SymbolicRegressionProblem(bool deserializing) : base() { }
|
---|
| 220 |
|
---|
[3545] | 221 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 222 | private void AfterDeserializationHook() {
|
---|
| 223 | Initialize();
|
---|
| 224 | }
|
---|
| 225 |
|
---|
[3452] | 226 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 227 | SymbolicRegressionProblem clone = (SymbolicRegressionProblem)base.Clone(cloner);
|
---|
| 228 | clone.Initialize();
|
---|
| 229 | return clone;
|
---|
| 230 | }
|
---|
| 231 |
|
---|
[3545] | 232 | private void RegisterParameterValueEvents() {
|
---|
| 233 | MaxFunctionArgumentsParameter.ValueChanged += new EventHandler(ArchitectureParameter_ValueChanged);
|
---|
| 234 | MaxFunctionDefiningBranchesParameter.ValueChanged += new EventHandler(ArchitectureParameter_ValueChanged);
|
---|
| 235 | SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged);
|
---|
| 236 | EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);
|
---|
[3269] | 237 | }
|
---|
| 238 |
|
---|
[3545] | 239 | private void RegisterParameterEvents() {
|
---|
| 240 | MaxFunctionArgumentsParameter.Value.ValueChanged += new EventHandler(ArchitectureParameter_ValueChanged);
|
---|
| 241 | MaxFunctionDefiningBranchesParameter.Value.ValueChanged += new EventHandler(ArchitectureParameter_ValueChanged);
|
---|
| 242 | SolutionCreator.SymbolicExpressionTreeParameter.ActualNameChanged += new EventHandler(SolutionCreator_SymbolicExpressionTreeParameter_ActualNameChanged);
|
---|
| 243 | Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
| 244 | }
|
---|
| 245 |
|
---|
| 246 | #region event handling
|
---|
| 247 | protected override void OnDataAnalysisProblemChanged(EventArgs e) {
|
---|
| 248 | base.OnDataAnalysisProblemChanged(e);
|
---|
| 249 | // paritions could be changed
|
---|
| 250 | ParameterizeEvaluator();
|
---|
[3651] | 251 | ParameterizeAnalyzers();
|
---|
[3545] | 252 | // input variables could have been changed
|
---|
[3480] | 253 | UpdateGrammar();
|
---|
[3545] | 254 | // estimation limits have to be recalculated
|
---|
| 255 | UpdateEstimationLimits();
|
---|
[3480] | 256 | }
|
---|
[3545] | 257 | protected virtual void OnArchitectureParameterChanged(EventArgs e) {
|
---|
[3559] | 258 | UpdateGrammar();
|
---|
[3532] | 259 | }
|
---|
[3545] | 260 | protected virtual void OnGrammarChanged(EventArgs e) { }
|
---|
| 261 | protected virtual void OnOperatorsChanged(EventArgs e) { RaiseOperatorsChanged(e); }
|
---|
| 262 | protected virtual void OnSolutionCreatorChanged(EventArgs e) {
|
---|
| 263 | SolutionCreator.SymbolicExpressionTreeParameter.ActualNameChanged += new EventHandler(SolutionCreator_SymbolicExpressionTreeParameter_ActualNameChanged);
|
---|
| 264 | ParameterizeSolutionCreator();
|
---|
| 265 | OnSolutionParameterNameChanged(e);
|
---|
| 266 | RaiseSolutionCreatorChanged(e);
|
---|
| 267 | }
|
---|
[3532] | 268 |
|
---|
[3545] | 269 | protected virtual void OnSolutionParameterNameChanged(EventArgs e) {
|
---|
| 270 | ParameterizeEvaluator();
|
---|
[3651] | 271 | ParameterizeAnalyzers();
|
---|
[3545] | 272 | ParameterizeOperators();
|
---|
[3294] | 273 | }
|
---|
| 274 |
|
---|
[3545] | 275 | protected virtual void OnEvaluatorChanged(EventArgs e) {
|
---|
| 276 | Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
| 277 | ParameterizeEvaluator();
|
---|
[3651] | 278 | ParameterizeAnalyzers();
|
---|
[3545] | 279 | RaiseEvaluatorChanged(e);
|
---|
| 280 | }
|
---|
| 281 | protected virtual void OnQualityParameterNameChanged(EventArgs e) {
|
---|
[3651] | 282 | ParameterizeAnalyzers();
|
---|
[3545] | 283 | }
|
---|
| 284 | #endregion
|
---|
[3513] | 285 |
|
---|
[3545] | 286 | #region event handlers
|
---|
| 287 | private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 288 | OnSolutionCreatorChanged(e);
|
---|
[3253] | 289 | }
|
---|
[3545] | 290 | private void SolutionCreator_SymbolicExpressionTreeParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
| 291 | OnSolutionParameterNameChanged(e);
|
---|
| 292 | }
|
---|
| 293 | private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 294 | OnEvaluatorChanged(e);
|
---|
| 295 | }
|
---|
| 296 | private void ArchitectureParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 297 | OnArchitectureParameterChanged(e);
|
---|
| 298 | }
|
---|
| 299 | private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
| 300 | OnQualityParameterNameChanged(e);
|
---|
| 301 | }
|
---|
| 302 | #endregion
|
---|
[3253] | 303 |
|
---|
[3545] | 304 | #region events
|
---|
[3253] | 305 | public event EventHandler SolutionCreatorChanged;
|
---|
[3545] | 306 | private void RaiseSolutionCreatorChanged(EventArgs e) {
|
---|
[3253] | 307 | var changed = SolutionCreatorChanged;
|
---|
| 308 | if (changed != null)
|
---|
[3545] | 309 | changed(this, e);
|
---|
[3253] | 310 | }
|
---|
| 311 | public event EventHandler EvaluatorChanged;
|
---|
[3545] | 312 | private void RaiseEvaluatorChanged(EventArgs e) {
|
---|
[3253] | 313 | var changed = EvaluatorChanged;
|
---|
| 314 | if (changed != null)
|
---|
[3545] | 315 | changed(this, e);
|
---|
[3253] | 316 | }
|
---|
| 317 |
|
---|
| 318 | public event EventHandler OperatorsChanged;
|
---|
[3545] | 319 | private void RaiseOperatorsChanged(EventArgs e) {
|
---|
[3253] | 320 | var changed = OperatorsChanged;
|
---|
| 321 | if (changed != null)
|
---|
[3545] | 322 | changed(this, e);
|
---|
[3253] | 323 | }
|
---|
[3739] | 324 | public event EventHandler Reset;
|
---|
| 325 | private void RaiseReset(EventArgs e) {
|
---|
| 326 | var changed = Reset;
|
---|
| 327 | if (changed != null)
|
---|
| 328 | changed(this, e);
|
---|
| 329 | }
|
---|
[3545] | 330 | #endregion
|
---|
[3253] | 331 |
|
---|
[3545] | 332 | #region Helpers
|
---|
| 333 | private void Initialize() {
|
---|
| 334 | InitializeOperators();
|
---|
| 335 | RegisterParameterEvents();
|
---|
| 336 | RegisterParameterValueEvents();
|
---|
[3253] | 337 | }
|
---|
| 338 |
|
---|
[3545] | 339 | private void UpdateGrammar() {
|
---|
| 340 | foreach (var varSymbol in FunctionTreeGrammar.Symbols.OfType<HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols.Variable>()) {
|
---|
[3599] | 341 | varSymbol.VariableNames = DataAnalysisProblemData.InputVariables.CheckedItems.Select(x => x.Value.Value);
|
---|
[3545] | 342 | }
|
---|
[3559] | 343 | var globalGrammar = FunctionTreeGrammar as GlobalSymbolicExpressionGrammar;
|
---|
| 344 | if (globalGrammar != null) {
|
---|
| 345 | globalGrammar.MaxFunctionArguments = MaxFunctionArguments.Value;
|
---|
| 346 | globalGrammar.MaxFunctionDefinitions = MaxFunctionDefiningBranches.Value;
|
---|
| 347 | }
|
---|
[3253] | 348 | }
|
---|
| 349 |
|
---|
[3545] | 350 | private void UpdateEstimationLimits() {
|
---|
| 351 | if (TrainingSamplesStart.Value < TrainingSamplesEnd.Value &&
|
---|
| 352 | DataAnalysisProblemData.Dataset.VariableNames.Contains(DataAnalysisProblemData.TargetVariable.Value)) {
|
---|
| 353 | var targetValues = DataAnalysisProblemData.Dataset.GetVariableValues(DataAnalysisProblemData.TargetVariable.Value, TrainingSamplesStart.Value, TrainingSamplesEnd.Value);
|
---|
| 354 | var mean = targetValues.Average();
|
---|
| 355 | var range = targetValues.Max() - targetValues.Min();
|
---|
| 356 | UpperEstimationLimit = new DoubleValue(mean + PunishmentFactor.Value * range);
|
---|
| 357 | LowerEstimationLimit = new DoubleValue(mean - PunishmentFactor.Value * range);
|
---|
| 358 | }
|
---|
[3253] | 359 | }
|
---|
| 360 |
|
---|
| 361 | private void InitializeOperators() {
|
---|
[3651] | 362 | operators = new List<IOperator>();
|
---|
| 363 | operators.AddRange(ApplicationManager.Manager.GetInstances<ISymbolicExpressionTreeOperator>().OfType<IOperator>());
|
---|
[3681] | 364 | operators.Add(new ValidationBestScaledSymbolicRegressionSolutionAnalyzer());
|
---|
| 365 | operators.Add(new MinAvgMaxSymbolicExpressionTreeSizeAnalyzer());
|
---|
| 366 | operators.Add(new SymbolicRegressionVariableFrequencyAnalyzer());
|
---|
| 367 | operators.Add(new SymbolicRegressionModelQualityAnalyzer());
|
---|
[3253] | 368 | ParameterizeOperators();
|
---|
[3651] | 369 | ParameterizeAnalyzers();
|
---|
[3253] | 370 | }
|
---|
| 371 |
|
---|
| 372 | private void ParameterizeSolutionCreator() {
|
---|
| 373 | SolutionCreator.SymbolicExpressionGrammarParameter.ActualName = FunctionTreeGrammarParameter.Name;
|
---|
| 374 | SolutionCreator.MaxTreeHeightParameter.ActualName = MaxExpressionDepthParameter.Name;
|
---|
| 375 | SolutionCreator.MaxTreeSizeParameter.ActualName = MaxExpressionLengthParameter.Name;
|
---|
[3545] | 376 | SolutionCreator.MaxFunctionArgumentsParameter.ActualName = MaxFunctionArgumentsParameter.Name;
|
---|
| 377 | SolutionCreator.MaxFunctionDefinitionsParameter.ActualName = MaxFunctionDefiningBranchesParameter.Name;
|
---|
[3253] | 378 | }
|
---|
[3545] | 379 |
|
---|
[3253] | 380 | private void ParameterizeEvaluator() {
|
---|
[3452] | 381 | Evaluator.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
[3373] | 382 | Evaluator.RegressionProblemDataParameter.ActualName = DataAnalysisProblemDataParameter.Name;
|
---|
[3545] | 383 | Evaluator.SamplesStartParameter.Value = TrainingSamplesStart;
|
---|
| 384 | Evaluator.SamplesEndParameter.Value = TrainingSamplesEnd;
|
---|
[3253] | 385 | }
|
---|
[3545] | 386 |
|
---|
[3651] | 387 | private void ParameterizeAnalyzers() {
|
---|
| 388 | foreach (var analyzer in Analyzers) {
|
---|
| 389 | analyzer.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
[3681] | 390 | var bestValidationSolutionAnalyzer = analyzer as ValidationBestScaledSymbolicRegressionSolutionAnalyzer;
|
---|
[3651] | 391 | if (bestValidationSolutionAnalyzer != null) {
|
---|
| 392 | bestValidationSolutionAnalyzer.ProblemDataParameter.ActualName = DataAnalysisProblemDataParameter.Name;
|
---|
| 393 | bestValidationSolutionAnalyzer.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameter.Name;
|
---|
| 394 | bestValidationSolutionAnalyzer.LowerEstimationLimitParameter.ActualName = LowerEstimationLimitParameter.Name;
|
---|
| 395 | bestValidationSolutionAnalyzer.SymbolicExpressionTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
|
---|
| 396 | bestValidationSolutionAnalyzer.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
| 397 | bestValidationSolutionAnalyzer.SamplesStartParameter.Value = ValidationSamplesStart;
|
---|
| 398 | bestValidationSolutionAnalyzer.SamplesEndParameter.Value = ValidationSamplesEnd;
|
---|
| 399 | }
|
---|
[3681] | 400 | var varFreqAnalyzer = analyzer as SymbolicRegressionVariableFrequencyAnalyzer;
|
---|
[3651] | 401 | if (varFreqAnalyzer != null) {
|
---|
| 402 | varFreqAnalyzer.ProblemDataParameter.ActualName = DataAnalysisProblemDataParameter.Name;
|
---|
| 403 | }
|
---|
[3681] | 404 | var modelQualityAnalyzer = analyzer as SymbolicRegressionModelQualityAnalyzer;
|
---|
[3652] | 405 | if (modelQualityAnalyzer != null) {
|
---|
| 406 | modelQualityAnalyzer.ProblemDataParameter.ActualName = DataAnalysisProblemDataParameter.Name;
|
---|
| 407 | modelQualityAnalyzer.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
| 408 | modelQualityAnalyzer.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameter.Name;
|
---|
| 409 | modelQualityAnalyzer.LowerEstimationLimitParameter.ActualName = LowerEstimationLimitParameter.Name;
|
---|
| 410 | modelQualityAnalyzer.SymbolicExpressionTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
|
---|
[3666] | 411 | modelQualityAnalyzer.TrainingSamplesStartParameter.Value = TrainingSamplesStart;
|
---|
| 412 | modelQualityAnalyzer.TrainingSamplesEndParameter.Value = ValidationSamplesEnd;
|
---|
| 413 | modelQualityAnalyzer.TestSamplesStartParameter.Value = TestSamplesStart;
|
---|
| 414 | modelQualityAnalyzer.TestSamplesEndParameter.Value = TestSamplesEnd;
|
---|
[3652] | 415 | }
|
---|
[3651] | 416 | }
|
---|
[3681] | 417 | foreach (ISymbolicExpressionTreeAnalyzer analyzer in Operators.OfType<ISymbolicExpressionTreeAnalyzer>()) {
|
---|
[3651] | 418 | analyzer.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
| 419 | }
|
---|
[3253] | 420 | }
|
---|
| 421 |
|
---|
| 422 | private void ParameterizeOperators() {
|
---|
| 423 | foreach (ISymbolicExpressionTreeOperator op in Operators.OfType<ISymbolicExpressionTreeOperator>()) {
|
---|
| 424 | op.MaxTreeHeightParameter.ActualName = MaxExpressionDepthParameter.Name;
|
---|
| 425 | op.MaxTreeSizeParameter.ActualName = MaxExpressionLengthParameter.Name;
|
---|
| 426 | op.SymbolicExpressionGrammarParameter.ActualName = FunctionTreeGrammarParameter.Name;
|
---|
| 427 | }
|
---|
[3534] | 428 | foreach (ISymbolicExpressionTreeCrossover op in Operators.OfType<ISymbolicExpressionTreeCrossover>()) {
|
---|
[3253] | 429 | op.ParentsParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
| 430 | op.ChildParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
| 431 | }
|
---|
[3534] | 432 | foreach (ISymbolicExpressionTreeManipulator op in Operators.OfType<ISymbolicExpressionTreeManipulator>()) {
|
---|
[3294] | 433 | op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
| 434 | }
|
---|
[3534] | 435 | foreach (ISymbolicExpressionTreeArchitectureManipulator op in Operators.OfType<ISymbolicExpressionTreeArchitectureManipulator>()) {
|
---|
| 436 | op.MaxFunctionArgumentsParameter.ActualName = MaxFunctionArgumentsParameter.Name;
|
---|
| 437 | op.MaxFunctionDefinitionsParameter.ActualName = MaxFunctionDefiningBranchesParameter.Name;
|
---|
[3294] | 438 | }
|
---|
[3253] | 439 | }
|
---|
| 440 | #endregion
|
---|
| 441 | }
|
---|
| 442 | }
|
---|