[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 | }
|
---|
[4033] | 57 | public override ValueParameter<SymbolicExpressionTreeCreator> SolutionCreatorParameter {
|
---|
[3253] | 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 | }
|
---|
[4033] | 72 | public override ValueParameter<ISymbolicRegressionEvaluator> EvaluatorParameter {
|
---|
[3253] | 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 | }
|
---|
[4033] | 118 | public override SymbolicExpressionTreeCreator SolutionCreator {
|
---|
[3253] | 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 |
|
---|
[4033] | 138 | public override ISymbolicRegressionEvaluator Evaluator {
|
---|
[3253] | 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;
|
---|
[3877] | 155 | public override 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();
|
---|
[3841] | 191 | var grammar = new FullFunctionalExpressionGrammar();
|
---|
[3442] | 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() {
|
---|
[3756] | 240 | MaxFunctionArgumentsParameter.Value.ValueChanged += new EventHandler(ArchitectureParameterValue_ValueChanged);
|
---|
| 241 | MaxFunctionDefiningBranchesParameter.Value.ValueChanged += new EventHandler(ArchitectureParameterValue_ValueChanged);
|
---|
[3545] | 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);
|
---|
[3800] | 249 | BestKnownQualityParameter.Value = null;
|
---|
[3545] | 250 | // paritions could be changed
|
---|
| 251 | ParameterizeEvaluator();
|
---|
[3651] | 252 | ParameterizeAnalyzers();
|
---|
[3545] | 253 | // input variables could have been changed
|
---|
[3480] | 254 | UpdateGrammar();
|
---|
[3545] | 255 | // estimation limits have to be recalculated
|
---|
| 256 | UpdateEstimationLimits();
|
---|
[3480] | 257 | }
|
---|
[3545] | 258 | protected virtual void OnArchitectureParameterChanged(EventArgs e) {
|
---|
[3559] | 259 | UpdateGrammar();
|
---|
[3532] | 260 | }
|
---|
[3545] | 261 | protected virtual void OnGrammarChanged(EventArgs e) { }
|
---|
| 262 | protected virtual void OnOperatorsChanged(EventArgs e) { RaiseOperatorsChanged(e); }
|
---|
| 263 | protected virtual void OnSolutionCreatorChanged(EventArgs e) {
|
---|
| 264 | SolutionCreator.SymbolicExpressionTreeParameter.ActualNameChanged += new EventHandler(SolutionCreator_SymbolicExpressionTreeParameter_ActualNameChanged);
|
---|
| 265 | ParameterizeSolutionCreator();
|
---|
| 266 | OnSolutionParameterNameChanged(e);
|
---|
| 267 | RaiseSolutionCreatorChanged(e);
|
---|
| 268 | }
|
---|
[3532] | 269 |
|
---|
[3545] | 270 | protected virtual void OnSolutionParameterNameChanged(EventArgs e) {
|
---|
| 271 | ParameterizeEvaluator();
|
---|
[3651] | 272 | ParameterizeAnalyzers();
|
---|
[3545] | 273 | ParameterizeOperators();
|
---|
[3294] | 274 | }
|
---|
| 275 |
|
---|
[3545] | 276 | protected virtual void OnEvaluatorChanged(EventArgs e) {
|
---|
| 277 | Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
| 278 | ParameterizeEvaluator();
|
---|
[3651] | 279 | ParameterizeAnalyzers();
|
---|
[3545] | 280 | RaiseEvaluatorChanged(e);
|
---|
| 281 | }
|
---|
| 282 | protected virtual void OnQualityParameterNameChanged(EventArgs e) {
|
---|
[3651] | 283 | ParameterizeAnalyzers();
|
---|
[3545] | 284 | }
|
---|
| 285 | #endregion
|
---|
[3513] | 286 |
|
---|
[3545] | 287 | #region event handlers
|
---|
| 288 | private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 289 | OnSolutionCreatorChanged(e);
|
---|
[3253] | 290 | }
|
---|
[3545] | 291 | private void SolutionCreator_SymbolicExpressionTreeParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
| 292 | OnSolutionParameterNameChanged(e);
|
---|
| 293 | }
|
---|
| 294 | private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 295 | OnEvaluatorChanged(e);
|
---|
| 296 | }
|
---|
| 297 | private void ArchitectureParameter_ValueChanged(object sender, EventArgs e) {
|
---|
[3756] | 298 | MaxFunctionArgumentsParameter.Value.ValueChanged += new EventHandler(ArchitectureParameterValue_ValueChanged);
|
---|
| 299 | MaxFunctionDefiningBranchesParameter.Value.ValueChanged += new EventHandler(ArchitectureParameterValue_ValueChanged);
|
---|
[3545] | 300 | OnArchitectureParameterChanged(e);
|
---|
| 301 | }
|
---|
[3756] | 302 | private void ArchitectureParameterValue_ValueChanged(object sender, EventArgs e) {
|
---|
| 303 | OnArchitectureParameterChanged(e);
|
---|
| 304 | }
|
---|
[3545] | 305 | private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
| 306 | OnQualityParameterNameChanged(e);
|
---|
| 307 | }
|
---|
| 308 | #endregion
|
---|
[3253] | 309 |
|
---|
[3545] | 310 | #region Helpers
|
---|
| 311 | private void Initialize() {
|
---|
| 312 | InitializeOperators();
|
---|
| 313 | RegisterParameterEvents();
|
---|
| 314 | RegisterParameterValueEvents();
|
---|
[3253] | 315 | }
|
---|
| 316 |
|
---|
[3545] | 317 | private void UpdateGrammar() {
|
---|
| 318 | foreach (var varSymbol in FunctionTreeGrammar.Symbols.OfType<HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols.Variable>()) {
|
---|
[3599] | 319 | varSymbol.VariableNames = DataAnalysisProblemData.InputVariables.CheckedItems.Select(x => x.Value.Value);
|
---|
[3545] | 320 | }
|
---|
[3559] | 321 | var globalGrammar = FunctionTreeGrammar as GlobalSymbolicExpressionGrammar;
|
---|
| 322 | if (globalGrammar != null) {
|
---|
| 323 | globalGrammar.MaxFunctionArguments = MaxFunctionArguments.Value;
|
---|
| 324 | globalGrammar.MaxFunctionDefinitions = MaxFunctionDefiningBranches.Value;
|
---|
| 325 | }
|
---|
[3253] | 326 | }
|
---|
| 327 |
|
---|
[3545] | 328 | private void UpdateEstimationLimits() {
|
---|
| 329 | if (TrainingSamplesStart.Value < TrainingSamplesEnd.Value &&
|
---|
| 330 | DataAnalysisProblemData.Dataset.VariableNames.Contains(DataAnalysisProblemData.TargetVariable.Value)) {
|
---|
| 331 | var targetValues = DataAnalysisProblemData.Dataset.GetVariableValues(DataAnalysisProblemData.TargetVariable.Value, TrainingSamplesStart.Value, TrainingSamplesEnd.Value);
|
---|
| 332 | var mean = targetValues.Average();
|
---|
| 333 | var range = targetValues.Max() - targetValues.Min();
|
---|
| 334 | UpperEstimationLimit = new DoubleValue(mean + PunishmentFactor.Value * range);
|
---|
| 335 | LowerEstimationLimit = new DoubleValue(mean - PunishmentFactor.Value * range);
|
---|
| 336 | }
|
---|
[3253] | 337 | }
|
---|
| 338 |
|
---|
| 339 | private void InitializeOperators() {
|
---|
[3651] | 340 | operators = new List<IOperator>();
|
---|
| 341 | operators.AddRange(ApplicationManager.Manager.GetInstances<ISymbolicExpressionTreeOperator>().OfType<IOperator>());
|
---|
[4028] | 342 | operators.Add(new SymbolicRegressionTournamentPruning());
|
---|
[3996] | 343 | operators.Add(new SymbolicRegressionVariableFrequencyAnalyzer());
|
---|
| 344 | operators.Add(new FixedValidationBestScaledSymbolicRegressionSolutionAnalyzer());
|
---|
[3817] | 345 | operators.Add(new MinAverageMaxSymbolicExpressionTreeSizeAnalyzer());
|
---|
[3253] | 346 | ParameterizeOperators();
|
---|
[3651] | 347 | ParameterizeAnalyzers();
|
---|
[3253] | 348 | }
|
---|
| 349 |
|
---|
| 350 | private void ParameterizeSolutionCreator() {
|
---|
| 351 | SolutionCreator.SymbolicExpressionGrammarParameter.ActualName = FunctionTreeGrammarParameter.Name;
|
---|
| 352 | SolutionCreator.MaxTreeHeightParameter.ActualName = MaxExpressionDepthParameter.Name;
|
---|
| 353 | SolutionCreator.MaxTreeSizeParameter.ActualName = MaxExpressionLengthParameter.Name;
|
---|
[3545] | 354 | SolutionCreator.MaxFunctionArgumentsParameter.ActualName = MaxFunctionArgumentsParameter.Name;
|
---|
| 355 | SolutionCreator.MaxFunctionDefinitionsParameter.ActualName = MaxFunctionDefiningBranchesParameter.Name;
|
---|
[3253] | 356 | }
|
---|
[3545] | 357 |
|
---|
[3253] | 358 | private void ParameterizeEvaluator() {
|
---|
[3452] | 359 | Evaluator.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
[3373] | 360 | Evaluator.RegressionProblemDataParameter.ActualName = DataAnalysisProblemDataParameter.Name;
|
---|
[3545] | 361 | Evaluator.SamplesStartParameter.Value = TrainingSamplesStart;
|
---|
| 362 | Evaluator.SamplesEndParameter.Value = TrainingSamplesEnd;
|
---|
[3253] | 363 | }
|
---|
[3545] | 364 |
|
---|
[3651] | 365 | private void ParameterizeAnalyzers() {
|
---|
| 366 | foreach (var analyzer in Analyzers) {
|
---|
| 367 | analyzer.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
[3996] | 368 | var fixedBestValidationSolutionAnalyzer = analyzer as FixedValidationBestScaledSymbolicRegressionSolutionAnalyzer;
|
---|
| 369 | if (fixedBestValidationSolutionAnalyzer != null) {
|
---|
| 370 | fixedBestValidationSolutionAnalyzer.ProblemDataParameter.ActualName = DataAnalysisProblemDataParameter.Name;
|
---|
| 371 | fixedBestValidationSolutionAnalyzer.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameter.Name;
|
---|
| 372 | fixedBestValidationSolutionAnalyzer.LowerEstimationLimitParameter.ActualName = LowerEstimationLimitParameter.Name;
|
---|
| 373 | fixedBestValidationSolutionAnalyzer.SymbolicExpressionTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
|
---|
| 374 | fixedBestValidationSolutionAnalyzer.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
| 375 | fixedBestValidationSolutionAnalyzer.ValidationSamplesStartParameter.Value = ValidationSamplesStart;
|
---|
| 376 | fixedBestValidationSolutionAnalyzer.ValidationSamplesEndParameter.Value = ValidationSamplesEnd;
|
---|
| 377 | fixedBestValidationSolutionAnalyzer.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name;
|
---|
| 378 | fixedBestValidationSolutionAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
|
---|
| 379 | }
|
---|
| 380 | var bestValidationSolutionAnalyzer = analyzer as FixedValidationBestScaledSymbolicRegressionSolutionAnalyzer;
|
---|
[3651] | 381 | if (bestValidationSolutionAnalyzer != null) {
|
---|
| 382 | bestValidationSolutionAnalyzer.ProblemDataParameter.ActualName = DataAnalysisProblemDataParameter.Name;
|
---|
| 383 | bestValidationSolutionAnalyzer.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameter.Name;
|
---|
| 384 | bestValidationSolutionAnalyzer.LowerEstimationLimitParameter.ActualName = LowerEstimationLimitParameter.Name;
|
---|
| 385 | bestValidationSolutionAnalyzer.SymbolicExpressionTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
|
---|
| 386 | bestValidationSolutionAnalyzer.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
[3806] | 387 | bestValidationSolutionAnalyzer.ValidationSamplesStartParameter.Value = ValidationSamplesStart;
|
---|
| 388 | bestValidationSolutionAnalyzer.ValidationSamplesEndParameter.Value = ValidationSamplesEnd;
|
---|
[3791] | 389 | bestValidationSolutionAnalyzer.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name;
|
---|
[3800] | 390 | bestValidationSolutionAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
|
---|
[3651] | 391 | }
|
---|
[3681] | 392 | var varFreqAnalyzer = analyzer as SymbolicRegressionVariableFrequencyAnalyzer;
|
---|
[3651] | 393 | if (varFreqAnalyzer != null) {
|
---|
| 394 | varFreqAnalyzer.ProblemDataParameter.ActualName = DataAnalysisProblemDataParameter.Name;
|
---|
| 395 | }
|
---|
[4028] | 396 | var pruningOperator = analyzer as SymbolicRegressionTournamentPruning;
|
---|
| 397 | if (pruningOperator != null) {
|
---|
| 398 | pruningOperator.SamplesStartParameter.Value = TrainingSamplesStart;
|
---|
| 399 | pruningOperator.SamplesEndParameter.Value = TrainingSamplesEnd;
|
---|
| 400 | pruningOperator.DataAnalysisProblemDataParameter.ActualName = DataAnalysisProblemDataParameter.Name;
|
---|
| 401 | pruningOperator.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
| 402 | pruningOperator.SymbolicExpressionTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
|
---|
| 403 | pruningOperator.LowerEstimationLimitParameter.ActualName = LowerEstimationLimitParameter.Name;
|
---|
| 404 | pruningOperator.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameter.Name;
|
---|
| 405 | }
|
---|
[3651] | 406 | }
|
---|
[3681] | 407 | foreach (ISymbolicExpressionTreeAnalyzer analyzer in Operators.OfType<ISymbolicExpressionTreeAnalyzer>()) {
|
---|
[3651] | 408 | analyzer.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
| 409 | }
|
---|
[3253] | 410 | }
|
---|
| 411 |
|
---|
| 412 | private void ParameterizeOperators() {
|
---|
| 413 | foreach (ISymbolicExpressionTreeOperator op in Operators.OfType<ISymbolicExpressionTreeOperator>()) {
|
---|
| 414 | op.MaxTreeHeightParameter.ActualName = MaxExpressionDepthParameter.Name;
|
---|
| 415 | op.MaxTreeSizeParameter.ActualName = MaxExpressionLengthParameter.Name;
|
---|
| 416 | op.SymbolicExpressionGrammarParameter.ActualName = FunctionTreeGrammarParameter.Name;
|
---|
| 417 | }
|
---|
[3534] | 418 | foreach (ISymbolicExpressionTreeCrossover op in Operators.OfType<ISymbolicExpressionTreeCrossover>()) {
|
---|
[3253] | 419 | op.ParentsParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
| 420 | op.ChildParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
| 421 | }
|
---|
[3534] | 422 | foreach (ISymbolicExpressionTreeManipulator op in Operators.OfType<ISymbolicExpressionTreeManipulator>()) {
|
---|
[3294] | 423 | op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
| 424 | }
|
---|
[3534] | 425 | foreach (ISymbolicExpressionTreeArchitectureManipulator op in Operators.OfType<ISymbolicExpressionTreeArchitectureManipulator>()) {
|
---|
| 426 | op.MaxFunctionArgumentsParameter.ActualName = MaxFunctionArgumentsParameter.Name;
|
---|
| 427 | op.MaxFunctionDefinitionsParameter.ActualName = MaxFunctionDefiningBranchesParameter.Name;
|
---|
[3294] | 428 | }
|
---|
[3253] | 429 | }
|
---|
| 430 | #endregion
|
---|
| 431 | }
|
---|
| 432 | }
|
---|