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