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