[5577] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[16565] | 3 | * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[5577] | 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;
|
---|
[15047] | 23 | using System.Collections.Generic;
|
---|
[5577] | 24 | using System.Drawing;
|
---|
[5618] | 25 | using System.Linq;
|
---|
[5577] | 26 | using HeuristicLab.Common;
|
---|
| 27 | using HeuristicLab.Common.Resources;
|
---|
| 28 | using HeuristicLab.Core;
|
---|
| 29 | using HeuristicLab.Data;
|
---|
[5618] | 30 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
[5577] | 31 | using HeuristicLab.Optimization;
|
---|
| 32 | using HeuristicLab.Parameters;
|
---|
[16565] | 33 | using HEAL.Attic;
|
---|
[5618] | 34 | using HeuristicLab.PluginInfrastructure;
|
---|
[7823] | 35 | using HeuristicLab.Problems.Instances;
|
---|
[5577] | 36 |
|
---|
| 37 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
|
---|
[16565] | 38 | [StorableType("59935E69-C4A5-480E-8FFB-D9669DE9BFD4")]
|
---|
[7823] | 39 | public abstract class SymbolicDataAnalysisProblem<T, U, V> : HeuristicOptimizationProblem<U, V>, IDataAnalysisProblem<T>, ISymbolicDataAnalysisProblem, IStorableContent,
|
---|
| 40 | IProblemInstanceConsumer<T>, IProblemInstanceExporter<T>
|
---|
[6978] | 41 | where T : class, IDataAnalysisProblemData
|
---|
[5580] | 42 | where U : class, ISymbolicDataAnalysisEvaluator<T>
|
---|
| 43 | where V : class, ISymbolicDataAnalysisSolutionCreator {
|
---|
[5770] | 44 |
|
---|
[5577] | 45 | #region parameter names & descriptions
|
---|
| 46 | private const string ProblemDataParameterName = "ProblemData";
|
---|
| 47 | private const string SymbolicExpressionTreeGrammarParameterName = "SymbolicExpressionTreeGrammar";
|
---|
| 48 | private const string SymbolicExpressionTreeInterpreterParameterName = "SymbolicExpressionTreeInterpreter";
|
---|
| 49 | private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth";
|
---|
| 50 | private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength";
|
---|
| 51 | private const string MaximumFunctionDefinitionsParameterName = "MaximumFunctionDefinitions";
|
---|
| 52 | private const string MaximumFunctionArgumentsParameterName = "MaximumFunctionArguments";
|
---|
[5759] | 53 | private const string RelativeNumberOfEvaluatedSamplesParameterName = "RelativeNumberOfEvaluatedSamples";
|
---|
[5733] | 54 | private const string FitnessCalculationPartitionParameterName = "FitnessCalculationPartition";
|
---|
[5775] | 55 | private const string ValidationPartitionParameterName = "ValidationPartition";
|
---|
[8664] | 56 | private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";
|
---|
[5577] | 57 |
|
---|
| 58 | private const string ProblemDataParameterDescription = "";
|
---|
| 59 | private const string SymbolicExpressionTreeGrammarParameterDescription = "The grammar that should be used for symbolic expression tree.";
|
---|
| 60 | private const string SymoblicExpressionTreeInterpreterParameterDescription = "The interpreter that should be used to evaluate the symbolic expression tree.";
|
---|
| 61 | private const string MaximumSymbolicExpressionTreeDepthParameterDescription = "Maximal depth of the symbolic expression. The minimum depth needed for the algorithm is 3 because two levels are reserved for the ProgramRoot and the Start symbol.";
|
---|
| 62 | private const string MaximumSymbolicExpressionTreeLengthParameterDescription = "Maximal length of the symbolic expression.";
|
---|
| 63 | private const string MaximumFunctionDefinitionsParameterDescription = "Maximal number of automatically defined functions";
|
---|
| 64 | private const string MaximumFunctionArgumentsParameterDescription = "Maximal number of arguments of automatically defined functions.";
|
---|
[5759] | 65 | private const string RelativeNumberOfEvaluatedSamplesParameterDescription = "The relative number of samples of the dataset partition, which should be randomly chosen for evaluation.";
|
---|
| 66 | private const string FitnessCalculationPartitionParameterDescription = "The partition of the problem data training partition, that should be used to calculate the fitness of an individual.";
|
---|
[5857] | 67 | private const string ValidationPartitionParameterDescription = "The partition of the problem data training partition, that should be used to select the best model from (optional).";
|
---|
[8664] | 68 | private const string ApplyLinearScalingParameterDescription = "Flag that indicates if the individual should be linearly scaled before evaluating.";
|
---|
[5577] | 69 | #endregion
|
---|
| 70 |
|
---|
| 71 | #region parameter properties
|
---|
| 72 | IParameter IDataAnalysisProblem.ProblemDataParameter {
|
---|
| 73 | get { return ProblemDataParameter; }
|
---|
| 74 | }
|
---|
| 75 | public IValueParameter<T> ProblemDataParameter {
|
---|
| 76 | get { return (IValueParameter<T>)Parameters[ProblemDataParameterName]; }
|
---|
| 77 | }
|
---|
| 78 | public IValueParameter<ISymbolicDataAnalysisGrammar> SymbolicExpressionTreeGrammarParameter {
|
---|
| 79 | get { return (IValueParameter<ISymbolicDataAnalysisGrammar>)Parameters[SymbolicExpressionTreeGrammarParameterName]; }
|
---|
| 80 | }
|
---|
[5624] | 81 | public IValueParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicExpressionTreeInterpreterParameter {
|
---|
| 82 | get { return (IValueParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[SymbolicExpressionTreeInterpreterParameterName]; }
|
---|
[5577] | 83 | }
|
---|
[5618] | 84 | public IFixedValueParameter<IntValue> MaximumSymbolicExpressionTreeDepthParameter {
|
---|
| 85 | get { return (IFixedValueParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeDepthParameterName]; }
|
---|
[5577] | 86 | }
|
---|
[5618] | 87 | public IFixedValueParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter {
|
---|
| 88 | get { return (IFixedValueParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]; }
|
---|
[5577] | 89 | }
|
---|
[5618] | 90 | public IFixedValueParameter<IntValue> MaximumFunctionDefinitionsParameter {
|
---|
| 91 | get { return (IFixedValueParameter<IntValue>)Parameters[MaximumFunctionDefinitionsParameterName]; }
|
---|
[5577] | 92 | }
|
---|
[5618] | 93 | public IFixedValueParameter<IntValue> MaximumFunctionArgumentsParameter {
|
---|
| 94 | get { return (IFixedValueParameter<IntValue>)Parameters[MaximumFunctionArgumentsParameterName]; }
|
---|
[5577] | 95 | }
|
---|
[5759] | 96 | public IFixedValueParameter<PercentValue> RelativeNumberOfEvaluatedSamplesParameter {
|
---|
| 97 | get { return (IFixedValueParameter<PercentValue>)Parameters[RelativeNumberOfEvaluatedSamplesParameterName]; }
|
---|
| 98 | }
|
---|
| 99 | public IFixedValueParameter<IntRange> FitnessCalculationPartitionParameter {
|
---|
| 100 | get { return (IFixedValueParameter<IntRange>)Parameters[FitnessCalculationPartitionParameterName]; }
|
---|
| 101 | }
|
---|
[5883] | 102 | public IFixedValueParameter<IntRange> ValidationPartitionParameter {
|
---|
[5775] | 103 | get { return (IFixedValueParameter<IntRange>)Parameters[ValidationPartitionParameterName]; }
|
---|
[5759] | 104 | }
|
---|
[8664] | 105 | public IFixedValueParameter<BoolValue> ApplyLinearScalingParameter {
|
---|
| 106 | get { return (IFixedValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }
|
---|
| 107 | }
|
---|
[5577] | 108 | #endregion
|
---|
| 109 |
|
---|
| 110 | #region properties
|
---|
| 111 | public string Filename { get; set; }
|
---|
[7201] | 112 | public static new Image StaticItemImage { get { return VSImageLibrary.Type; } }
|
---|
[5577] | 113 |
|
---|
| 114 | IDataAnalysisProblemData IDataAnalysisProblem.ProblemData {
|
---|
| 115 | get { return ProblemData; }
|
---|
| 116 | }
|
---|
| 117 | public T ProblemData {
|
---|
| 118 | get { return ProblemDataParameter.Value; }
|
---|
[5618] | 119 | set { ProblemDataParameter.Value = value; }
|
---|
[5577] | 120 | }
|
---|
| 121 |
|
---|
| 122 | public ISymbolicDataAnalysisGrammar SymbolicExpressionTreeGrammar {
|
---|
| 123 | get { return SymbolicExpressionTreeGrammarParameter.Value; }
|
---|
[5618] | 124 | set { SymbolicExpressionTreeGrammarParameter.Value = value; }
|
---|
[5577] | 125 | }
|
---|
[5624] | 126 | public ISymbolicDataAnalysisExpressionTreeInterpreter SymbolicExpressionTreeInterpreter {
|
---|
[5577] | 127 | get { return SymbolicExpressionTreeInterpreterParameter.Value; }
|
---|
[5618] | 128 | set { SymbolicExpressionTreeInterpreterParameter.Value = value; }
|
---|
[5577] | 129 | }
|
---|
| 130 |
|
---|
| 131 | public IntValue MaximumSymbolicExpressionTreeDepth {
|
---|
| 132 | get { return MaximumSymbolicExpressionTreeDepthParameter.Value; }
|
---|
| 133 | }
|
---|
| 134 | public IntValue MaximumSymbolicExpressionTreeLength {
|
---|
| 135 | get { return MaximumSymbolicExpressionTreeLengthParameter.Value; }
|
---|
| 136 | }
|
---|
| 137 | public IntValue MaximumFunctionDefinitions {
|
---|
| 138 | get { return MaximumFunctionDefinitionsParameter.Value; }
|
---|
| 139 | }
|
---|
| 140 | public IntValue MaximumFunctionArguments {
|
---|
[5618] | 141 | get { return MaximumFunctionArgumentsParameter.Value; }
|
---|
[5577] | 142 | }
|
---|
[5759] | 143 | public PercentValue RelativeNumberOfEvaluatedSamples {
|
---|
| 144 | get { return RelativeNumberOfEvaluatedSamplesParameter.Value; }
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | public IntRange FitnessCalculationPartition {
|
---|
| 148 | get { return FitnessCalculationPartitionParameter.Value; }
|
---|
| 149 | }
|
---|
[5775] | 150 | public IntRange ValidationPartition {
|
---|
[5883] | 151 | get { return ValidationPartitionParameter.Value; }
|
---|
[5759] | 152 | }
|
---|
[8664] | 153 | public BoolValue ApplyLinearScaling {
|
---|
| 154 | get { return ApplyLinearScalingParameter.Value; }
|
---|
| 155 | }
|
---|
[5577] | 156 | #endregion
|
---|
| 157 |
|
---|
| 158 | [StorableConstructor]
|
---|
[16565] | 159 | protected SymbolicDataAnalysisProblem(StorableConstructorFlag _) : base(_) { }
|
---|
[5618] | 160 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 161 | private void AfterDeserialization() {
|
---|
[8664] | 162 | if (!Parameters.ContainsKey(ApplyLinearScalingParameterName)) {
|
---|
| 163 | Parameters.Add(new FixedValueParameter<BoolValue>(ApplyLinearScalingParameterName, ApplyLinearScalingParameterDescription, new BoolValue(false)));
|
---|
| 164 | ApplyLinearScalingParameter.Hidden = true;
|
---|
[8666] | 165 |
|
---|
| 166 | //it is assumed that for all symbolic regression algorithms linear scaling was set to true
|
---|
| 167 | //there is no possibility to determine the previous value of the parameter as it was stored in the evaluator
|
---|
| 168 | if (GetType().Name.Contains("SymbolicRegression"))
|
---|
| 169 | ApplyLinearScaling.Value = true;
|
---|
[8664] | 170 | }
|
---|
| 171 |
|
---|
[5618] | 172 | RegisterEventHandlers();
|
---|
| 173 | }
|
---|
| 174 | protected SymbolicDataAnalysisProblem(SymbolicDataAnalysisProblem<T, U, V> original, Cloner cloner)
|
---|
| 175 | : base(original, cloner) {
|
---|
| 176 | RegisterEventHandlers();
|
---|
| 177 | }
|
---|
[5577] | 178 |
|
---|
[5618] | 179 | protected SymbolicDataAnalysisProblem(T problemData, U evaluator, V solutionCreator)
|
---|
| 180 | : base(evaluator, solutionCreator) {
|
---|
| 181 | Parameters.Add(new ValueParameter<T>(ProblemDataParameterName, ProblemDataParameterDescription, problemData));
|
---|
[5577] | 182 | Parameters.Add(new ValueParameter<ISymbolicDataAnalysisGrammar>(SymbolicExpressionTreeGrammarParameterName, SymbolicExpressionTreeGrammarParameterDescription));
|
---|
[5624] | 183 | Parameters.Add(new ValueParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicExpressionTreeInterpreterParameterName, SymoblicExpressionTreeInterpreterParameterDescription));
|
---|
[5847] | 184 | Parameters.Add(new FixedValueParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, MaximumSymbolicExpressionTreeDepthParameterDescription));
|
---|
| 185 | Parameters.Add(new FixedValueParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, MaximumSymbolicExpressionTreeLengthParameterDescription));
|
---|
| 186 | Parameters.Add(new FixedValueParameter<IntValue>(MaximumFunctionDefinitionsParameterName, MaximumFunctionDefinitionsParameterDescription));
|
---|
| 187 | Parameters.Add(new FixedValueParameter<IntValue>(MaximumFunctionArgumentsParameterName, MaximumFunctionArgumentsParameterDescription));
|
---|
| 188 | Parameters.Add(new FixedValueParameter<IntRange>(FitnessCalculationPartitionParameterName, FitnessCalculationPartitionParameterDescription));
|
---|
| 189 | Parameters.Add(new FixedValueParameter<IntRange>(ValidationPartitionParameterName, ValidationPartitionParameterDescription));
|
---|
[5759] | 190 | Parameters.Add(new FixedValueParameter<PercentValue>(RelativeNumberOfEvaluatedSamplesParameterName, RelativeNumberOfEvaluatedSamplesParameterDescription, new PercentValue(1)));
|
---|
[8664] | 191 | Parameters.Add(new FixedValueParameter<BoolValue>(ApplyLinearScalingParameterName, ApplyLinearScalingParameterDescription, new BoolValue(false)));
|
---|
[5618] | 192 |
|
---|
[5854] | 193 | SymbolicExpressionTreeInterpreterParameter.Hidden = true;
|
---|
| 194 | MaximumFunctionArgumentsParameter.Hidden = true;
|
---|
| 195 | MaximumFunctionDefinitionsParameter.Hidden = true;
|
---|
[8664] | 196 | ApplyLinearScalingParameter.Hidden = true;
|
---|
[5854] | 197 |
|
---|
[5618] | 198 | SymbolicExpressionTreeGrammar = new TypeCoherentExpressionGrammar();
|
---|
[9830] | 199 | SymbolicExpressionTreeInterpreter = new SymbolicDataAnalysisExpressionTreeLinearInterpreter();
|
---|
[5618] | 200 |
|
---|
[5770] | 201 | FitnessCalculationPartition.Start = ProblemData.TrainingPartition.Start;
|
---|
| 202 | FitnessCalculationPartition.End = ProblemData.TrainingPartition.End;
|
---|
| 203 |
|
---|
[5722] | 204 | InitializeOperators();
|
---|
| 205 |
|
---|
[5618] | 206 | UpdateGrammar();
|
---|
| 207 | RegisterEventHandlers();
|
---|
[5577] | 208 | }
|
---|
| 209 |
|
---|
[5685] | 210 | protected virtual void UpdateGrammar() {
|
---|
[14826] | 211 | var problemData = ProblemData;
|
---|
| 212 | var ds = problemData.Dataset;
|
---|
| 213 | var grammar = SymbolicExpressionTreeGrammar;
|
---|
| 214 | grammar.MaximumFunctionArguments = MaximumFunctionArguments.Value;
|
---|
| 215 | grammar.MaximumFunctionDefinitions = MaximumFunctionDefinitions.Value;
|
---|
| 216 | foreach (var varSymbol in grammar.Symbols.OfType<HeuristicLab.Problems.DataAnalysis.Symbolic.VariableBase>()) {
|
---|
[8936] | 217 | if (!varSymbol.Fixed) {
|
---|
[14826] | 218 | varSymbol.AllVariableNames = problemData.InputVariables.Select(x => x.Value).Where(x => ds.VariableHasType<double>(x));
|
---|
| 219 | varSymbol.VariableNames = problemData.AllowedInputVariables.Where(x => ds.VariableHasType<double>(x));
|
---|
[8936] | 220 | }
|
---|
[5685] | 221 | }
|
---|
[14826] | 222 | foreach (var factorSymbol in grammar.Symbols.OfType<BinaryFactorVariable>()) {
|
---|
| 223 | if (!factorSymbol.Fixed) {
|
---|
| 224 | factorSymbol.AllVariableNames = problemData.InputVariables.Select(x => x.Value).Where(x => ds.VariableHasType<string>(x));
|
---|
| 225 | factorSymbol.VariableNames = problemData.AllowedInputVariables.Where(x => ds.VariableHasType<string>(x));
|
---|
| 226 | factorSymbol.VariableValues = factorSymbol.VariableNames
|
---|
| 227 | .ToDictionary(varName => varName, varName => ds.GetStringValues(varName).Distinct().ToList());
|
---|
[8936] | 228 | }
|
---|
[5685] | 229 | }
|
---|
[14826] | 230 | foreach (var factorSymbol in grammar.Symbols.OfType<FactorVariable>()) {
|
---|
| 231 | if (!factorSymbol.Fixed) {
|
---|
| 232 | factorSymbol.AllVariableNames = problemData.InputVariables.Select(x => x.Value).Where(x => ds.VariableHasType<string>(x));
|
---|
| 233 | factorSymbol.VariableNames = problemData.AllowedInputVariables.Where(x => ds.VariableHasType<string>(x));
|
---|
| 234 | factorSymbol.VariableValues = factorSymbol.VariableNames
|
---|
| 235 | .ToDictionary(varName => varName,
|
---|
| 236 | varName => ds.GetStringValues(varName).Distinct()
|
---|
| 237 | .Select((n, i) => Tuple.Create(n, i))
|
---|
| 238 | .ToDictionary(tup => tup.Item1, tup => tup.Item2));
|
---|
| 239 | }
|
---|
| 240 | }
|
---|
[5685] | 241 | }
|
---|
| 242 |
|
---|
[5618] | 243 | private void InitializeOperators() {
|
---|
[15047] | 244 | var operators = new HashSet<IItem>(new TypeEqualityComparer<IItem>());
|
---|
| 245 | operators.Add(new SubtreeCrossover());
|
---|
| 246 | operators.Add(new MultiSymbolicExpressionTreeManipulator());
|
---|
| 247 |
|
---|
| 248 | foreach (var op in ApplicationManager.Manager.GetInstances<ISymbolicExpressionTreeOperator>())
|
---|
| 249 | operators.Add(op);
|
---|
| 250 | foreach (var op in ApplicationManager.Manager.GetInstances<ISymbolicDataAnalysisExpressionCrossover<T>>())
|
---|
| 251 | operators.Add(op);
|
---|
| 252 |
|
---|
| 253 | operators.Add(new SymbolicExpressionSymbolFrequencyAnalyzer());
|
---|
| 254 | operators.Add(new SymbolicDataAnalysisVariableFrequencyAnalyzer());
|
---|
| 255 | operators.Add(new MinAverageMaxSymbolicExpressionTreeLengthAnalyzer());
|
---|
| 256 | operators.Add(new SymbolicExpressionTreeLengthAnalyzer());
|
---|
| 257 | operators.Add(new SymbolicExpressionTreeBottomUpSimilarityCalculator());
|
---|
| 258 | operators.Add(new SymbolicDataAnalysisBottomUpDiversityAnalyzer(operators.OfType<SymbolicExpressionTreeBottomUpSimilarityCalculator>().First()));
|
---|
| 259 |
|
---|
| 260 | Operators.AddRange(operators);
|
---|
[5618] | 261 | ParameterizeOperators();
|
---|
| 262 | }
|
---|
| 263 |
|
---|
[5685] | 264 | #region events
|
---|
[5618] | 265 | private void RegisterEventHandlers() {
|
---|
| 266 | ProblemDataParameter.ValueChanged += new EventHandler(ProblemDataParameter_ValueChanged);
|
---|
| 267 | ProblemDataParameter.Value.Changed += (object sender, EventArgs e) => OnProblemDataChanged();
|
---|
| 268 |
|
---|
[5841] | 269 | SymbolicExpressionTreeGrammarParameter.ValueChanged += new EventHandler(SymbolicExpressionTreeGrammarParameter_ValueChanged);
|
---|
| 270 |
|
---|
[5618] | 271 | MaximumFunctionArguments.ValueChanged += new EventHandler(ArchitectureParameterValue_ValueChanged);
|
---|
| 272 | MaximumFunctionDefinitions.ValueChanged += new EventHandler(ArchitectureParameterValue_ValueChanged);
|
---|
| 273 | MaximumSymbolicExpressionTreeDepth.ValueChanged += new EventHandler(MaximumSymbolicExpressionTreeDepth_ValueChanged);
|
---|
| 274 | }
|
---|
| 275 |
|
---|
[5685] | 276 | private void ProblemDataParameter_ValueChanged(object sender, EventArgs e) {
|
---|
[5887] | 277 | ValidationPartition.Start = 0;
|
---|
| 278 | ValidationPartition.End = 0;
|
---|
[5685] | 279 | ProblemDataParameter.Value.Changed += (object s, EventArgs args) => OnProblemDataChanged();
|
---|
| 280 | OnProblemDataChanged();
|
---|
| 281 | }
|
---|
| 282 |
|
---|
[5841] | 283 | private void SymbolicExpressionTreeGrammarParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 284 | UpdateGrammar();
|
---|
| 285 | }
|
---|
| 286 |
|
---|
[5618] | 287 | private void ArchitectureParameterValue_ValueChanged(object sender, EventArgs e) {
|
---|
| 288 | UpdateGrammar();
|
---|
| 289 | }
|
---|
| 290 |
|
---|
| 291 | private void MaximumSymbolicExpressionTreeDepth_ValueChanged(object sender, EventArgs e) {
|
---|
| 292 | if (MaximumSymbolicExpressionTreeDepth != null && MaximumSymbolicExpressionTreeDepth.Value < 3)
|
---|
| 293 | MaximumSymbolicExpressionTreeDepth.Value = 3;
|
---|
| 294 | }
|
---|
| 295 |
|
---|
| 296 | protected override void OnSolutionCreatorChanged() {
|
---|
| 297 | base.OnSolutionCreatorChanged();
|
---|
| 298 | SolutionCreator.SymbolicExpressionTreeParameter.ActualNameChanged += new EventHandler(SolutionCreator_SymbolicExpressionTreeParameter_ActualNameChanged);
|
---|
| 299 | ParameterizeOperators();
|
---|
| 300 | }
|
---|
[5685] | 301 |
|
---|
[5618] | 302 | private void SolutionCreator_SymbolicExpressionTreeParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
| 303 | ParameterizeOperators();
|
---|
| 304 | }
|
---|
| 305 |
|
---|
| 306 | protected override void OnEvaluatorChanged() {
|
---|
| 307 | base.OnEvaluatorChanged();
|
---|
[5685] | 308 | ParameterizeOperators();
|
---|
[5618] | 309 | }
|
---|
| 310 |
|
---|
[5577] | 311 | public event EventHandler ProblemDataChanged;
|
---|
| 312 | protected virtual void OnProblemDataChanged() {
|
---|
[5770] | 313 | FitnessCalculationPartition.Start = ProblemData.TrainingPartition.Start;
|
---|
| 314 | FitnessCalculationPartition.End = ProblemData.TrainingPartition.End;
|
---|
| 315 |
|
---|
[5618] | 316 | UpdateGrammar();
|
---|
[5685] | 317 | ParameterizeOperators();
|
---|
| 318 |
|
---|
[5577] | 319 | var handler = ProblemDataChanged;
|
---|
| 320 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
[5618] | 321 |
|
---|
| 322 | OnReset();
|
---|
[5577] | 323 | }
|
---|
[5685] | 324 | #endregion
|
---|
[5618] | 325 |
|
---|
[5685] | 326 | protected virtual void ParameterizeOperators() {
|
---|
[7506] | 327 | var operators = Parameters.OfType<IValueParameter>().Select(p => p.Value).OfType<IOperator>().Union(Operators).ToList();
|
---|
[5618] | 328 |
|
---|
| 329 | foreach (var op in operators.OfType<ISymbolicExpressionTreeGrammarBasedOperator>()) {
|
---|
[8664] | 330 | op.SymbolicExpressionTreeGrammarParameter.ActualName = SymbolicExpressionTreeGrammarParameter.Name;
|
---|
[5618] | 331 | }
|
---|
| 332 | foreach (var op in operators.OfType<ISymbolicExpressionTreeSizeConstraintOperator>()) {
|
---|
[8664] | 333 | op.MaximumSymbolicExpressionTreeDepthParameter.ActualName = MaximumSymbolicExpressionTreeDepthParameter.Name;
|
---|
| 334 | op.MaximumSymbolicExpressionTreeLengthParameter.ActualName = MaximumSymbolicExpressionTreeLengthParameter.Name;
|
---|
[5618] | 335 | }
|
---|
| 336 | foreach (var op in operators.OfType<ISymbolicExpressionTreeArchitectureAlteringOperator>()) {
|
---|
[8664] | 337 | op.MaximumFunctionArgumentsParameter.ActualName = MaximumFunctionArgumentsParameter.Name;
|
---|
| 338 | op.MaximumFunctionDefinitionsParameter.ActualName = MaximumFunctionDefinitionsParameter.Name;
|
---|
[5618] | 339 | }
|
---|
| 340 | foreach (var op in operators.OfType<ISymbolicDataAnalysisEvaluator<T>>()) {
|
---|
[5685] | 341 | op.ProblemDataParameter.ActualName = ProblemDataParameterName;
|
---|
[5618] | 342 | op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
[5759] | 343 | op.EvaluationPartitionParameter.ActualName = FitnessCalculationPartitionParameter.Name;
|
---|
| 344 | op.RelativeNumberOfEvaluatedSamplesParameter.ActualName = RelativeNumberOfEvaluatedSamplesParameter.Name;
|
---|
[8664] | 345 | op.ApplyLinearScalingParameter.ActualName = ApplyLinearScalingParameter.Name;
|
---|
[5618] | 346 | }
|
---|
| 347 | foreach (var op in operators.OfType<ISymbolicExpressionTreeCrossover>()) {
|
---|
| 348 | op.ParentsParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
[12422] | 349 | op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
[5618] | 350 | }
|
---|
| 351 | foreach (var op in operators.OfType<ISymbolicExpressionTreeManipulator>()) {
|
---|
| 352 | op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
| 353 | }
|
---|
| 354 | foreach (var op in operators.OfType<ISymbolicExpressionTreeAnalyzer>()) {
|
---|
| 355 | op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
| 356 | }
|
---|
[8664] | 357 | foreach (var op in operators.OfType<ISymbolicDataAnalysisSingleObjectiveAnalyzer>()) {
|
---|
| 358 | op.ApplyLinearScalingParameter.ActualName = ApplyLinearScalingParameter.Name;
|
---|
| 359 | }
|
---|
| 360 | foreach (var op in operators.OfType<ISymbolicDataAnalysisMultiObjectiveAnalyzer>()) {
|
---|
| 361 | op.ApplyLinearScalingParameter.ActualName = ApplyLinearScalingParameter.Name;
|
---|
| 362 | }
|
---|
[6135] | 363 | foreach (var op in operators.OfType<ISymbolicDataAnalysisAnalyzer>()) {
|
---|
| 364 | op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
| 365 | }
|
---|
[5759] | 366 | foreach (var op in operators.OfType<ISymbolicDataAnalysisValidationAnalyzer<U, T>>()) {
|
---|
| 367 | op.RelativeNumberOfEvaluatedSamplesParameter.ActualName = RelativeNumberOfEvaluatedSamplesParameter.Name;
|
---|
[5883] | 368 | op.ValidationPartitionParameter.ActualName = ValidationPartitionParameter.Name;
|
---|
[5759] | 369 | }
|
---|
[5685] | 370 | foreach (var op in operators.OfType<ISymbolicDataAnalysisInterpreterOperator>()) {
|
---|
[8664] | 371 | op.SymbolicDataAnalysisTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
|
---|
[5685] | 372 | }
|
---|
[7506] | 373 | foreach (var op in operators.OfType<ISymbolicDataAnalysisExpressionCrossover<T>>()) {
|
---|
[8664] | 374 | op.EvaluationPartitionParameter.ActualName = FitnessCalculationPartitionParameter.Name;
|
---|
[7506] | 375 | op.ProblemDataParameter.ActualName = ProblemDataParameter.Name;
|
---|
| 376 | op.EvaluationPartitionParameter.ActualName = FitnessCalculationPartitionParameter.Name;
|
---|
| 377 | op.RelativeNumberOfEvaluatedSamplesParameter.ActualName = RelativeNumberOfEvaluatedSamplesParameter.Name;
|
---|
| 378 | op.EvaluatorParameter.ActualName = EvaluatorParameter.Name;
|
---|
| 379 | }
|
---|
[5618] | 380 | }
|
---|
[5623] | 381 |
|
---|
[7823] | 382 | #region Import & Export
|
---|
[9452] | 383 | public virtual void Load(T data) {
|
---|
[7823] | 384 | Name = data.Name;
|
---|
| 385 | Description = data.Description;
|
---|
| 386 | ProblemData = data;
|
---|
| 387 | }
|
---|
| 388 |
|
---|
[9452] | 389 | public virtual T Export() {
|
---|
[7823] | 390 | return ProblemData;
|
---|
| 391 | }
|
---|
| 392 | #endregion
|
---|
[5577] | 393 | }
|
---|
| 394 | }
|
---|