[5577] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[17180] | 3 | * Copyright (C) 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;
|
---|
[17456] | 26 | using HEAL.Attic;
|
---|
[5577] | 27 | using HeuristicLab.Common;
|
---|
| 28 | using HeuristicLab.Common.Resources;
|
---|
| 29 | using HeuristicLab.Core;
|
---|
| 30 | using HeuristicLab.Data;
|
---|
[5618] | 31 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
[5577] | 32 | using HeuristicLab.Optimization;
|
---|
| 33 | using HeuristicLab.Parameters;
|
---|
[5618] | 34 | using HeuristicLab.PluginInfrastructure;
|
---|
[7823] | 35 | using HeuristicLab.Problems.Instances;
|
---|
[5577] | 36 |
|
---|
[17448] | 37 | using DoubleVector = MathNet.Numerics.LinearAlgebra.Vector<double>;
|
---|
| 38 |
|
---|
[5577] | 39 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
|
---|
[16565] | 40 | [StorableType("59935E69-C4A5-480E-8FFB-D9669DE9BFD4")]
|
---|
[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]
|
---|
[16565] | 161 | protected SymbolicDataAnalysisProblem(StorableConstructorFlag _) : base(_) { }
|
---|
[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() {
|
---|
[14826] | 213 | var problemData = ProblemData;
|
---|
| 214 | var grammar = SymbolicExpressionTreeGrammar;
|
---|
[17456] | 215 |
|
---|
[14826] | 216 | grammar.MaximumFunctionArguments = MaximumFunctionArguments.Value;
|
---|
| 217 | grammar.MaximumFunctionDefinitions = MaximumFunctionDefinitions.Value;
|
---|
[17456] | 218 |
|
---|
| 219 | grammar.ConfigureVariableSymbols(problemData);
|
---|
[5685] | 220 | }
|
---|
| 221 |
|
---|
[5618] | 222 | private void InitializeOperators() {
|
---|
[15047] | 223 | var operators = new HashSet<IItem>(new TypeEqualityComparer<IItem>());
|
---|
| 224 | operators.Add(new SubtreeCrossover());
|
---|
| 225 | operators.Add(new MultiSymbolicExpressionTreeManipulator());
|
---|
| 226 |
|
---|
| 227 | foreach (var op in ApplicationManager.Manager.GetInstances<ISymbolicExpressionTreeOperator>())
|
---|
| 228 | operators.Add(op);
|
---|
| 229 | foreach (var op in ApplicationManager.Manager.GetInstances<ISymbolicDataAnalysisExpressionCrossover<T>>())
|
---|
| 230 | operators.Add(op);
|
---|
[18082] | 231 | foreach (var op in ApplicationManager.Manager.GetInstances<ISymbolicDataAnalysisExpressionManipulator<T>>())
|
---|
| 232 | operators.Add(op);
|
---|
[15047] | 233 |
|
---|
| 234 | operators.Add(new SymbolicExpressionSymbolFrequencyAnalyzer());
|
---|
| 235 | operators.Add(new SymbolicDataAnalysisVariableFrequencyAnalyzer());
|
---|
| 236 | operators.Add(new MinAverageMaxSymbolicExpressionTreeLengthAnalyzer());
|
---|
| 237 | operators.Add(new SymbolicExpressionTreeLengthAnalyzer());
|
---|
| 238 | operators.Add(new SymbolicExpressionTreeBottomUpSimilarityCalculator());
|
---|
| 239 | operators.Add(new SymbolicDataAnalysisBottomUpDiversityAnalyzer(operators.OfType<SymbolicExpressionTreeBottomUpSimilarityCalculator>().First()));
|
---|
| 240 |
|
---|
| 241 | Operators.AddRange(operators);
|
---|
[5618] | 242 | ParameterizeOperators();
|
---|
| 243 | }
|
---|
| 244 |
|
---|
[5685] | 245 | #region events
|
---|
[5618] | 246 | private void RegisterEventHandlers() {
|
---|
| 247 | ProblemDataParameter.ValueChanged += new EventHandler(ProblemDataParameter_ValueChanged);
|
---|
| 248 | ProblemDataParameter.Value.Changed += (object sender, EventArgs e) => OnProblemDataChanged();
|
---|
| 249 |
|
---|
[5841] | 250 | SymbolicExpressionTreeGrammarParameter.ValueChanged += new EventHandler(SymbolicExpressionTreeGrammarParameter_ValueChanged);
|
---|
| 251 |
|
---|
[5618] | 252 | MaximumFunctionArguments.ValueChanged += new EventHandler(ArchitectureParameterValue_ValueChanged);
|
---|
| 253 | MaximumFunctionDefinitions.ValueChanged += new EventHandler(ArchitectureParameterValue_ValueChanged);
|
---|
| 254 | MaximumSymbolicExpressionTreeDepth.ValueChanged += new EventHandler(MaximumSymbolicExpressionTreeDepth_ValueChanged);
|
---|
| 255 | }
|
---|
| 256 |
|
---|
[5685] | 257 | private void ProblemDataParameter_ValueChanged(object sender, EventArgs e) {
|
---|
[5887] | 258 | ValidationPartition.Start = 0;
|
---|
| 259 | ValidationPartition.End = 0;
|
---|
[5685] | 260 | ProblemDataParameter.Value.Changed += (object s, EventArgs args) => OnProblemDataChanged();
|
---|
| 261 | OnProblemDataChanged();
|
---|
| 262 | }
|
---|
| 263 |
|
---|
[5841] | 264 | private void SymbolicExpressionTreeGrammarParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 265 | UpdateGrammar();
|
---|
| 266 | }
|
---|
| 267 |
|
---|
[5618] | 268 | private void ArchitectureParameterValue_ValueChanged(object sender, EventArgs e) {
|
---|
| 269 | UpdateGrammar();
|
---|
| 270 | }
|
---|
| 271 |
|
---|
| 272 | private void MaximumSymbolicExpressionTreeDepth_ValueChanged(object sender, EventArgs e) {
|
---|
| 273 | if (MaximumSymbolicExpressionTreeDepth != null && MaximumSymbolicExpressionTreeDepth.Value < 3)
|
---|
| 274 | MaximumSymbolicExpressionTreeDepth.Value = 3;
|
---|
| 275 | }
|
---|
| 276 |
|
---|
| 277 | protected override void OnSolutionCreatorChanged() {
|
---|
| 278 | base.OnSolutionCreatorChanged();
|
---|
| 279 | SolutionCreator.SymbolicExpressionTreeParameter.ActualNameChanged += new EventHandler(SolutionCreator_SymbolicExpressionTreeParameter_ActualNameChanged);
|
---|
| 280 | ParameterizeOperators();
|
---|
| 281 | }
|
---|
[5685] | 282 |
|
---|
[5618] | 283 | private void SolutionCreator_SymbolicExpressionTreeParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
| 284 | ParameterizeOperators();
|
---|
| 285 | }
|
---|
| 286 |
|
---|
| 287 | protected override void OnEvaluatorChanged() {
|
---|
| 288 | base.OnEvaluatorChanged();
|
---|
[5685] | 289 | ParameterizeOperators();
|
---|
[5618] | 290 | }
|
---|
| 291 |
|
---|
[5577] | 292 | public event EventHandler ProblemDataChanged;
|
---|
| 293 | protected virtual void OnProblemDataChanged() {
|
---|
[5770] | 294 | FitnessCalculationPartition.Start = ProblemData.TrainingPartition.Start;
|
---|
| 295 | FitnessCalculationPartition.End = ProblemData.TrainingPartition.End;
|
---|
| 296 |
|
---|
[5618] | 297 | UpdateGrammar();
|
---|
[5685] | 298 | ParameterizeOperators();
|
---|
| 299 |
|
---|
[5577] | 300 | var handler = ProblemDataChanged;
|
---|
| 301 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
[5618] | 302 |
|
---|
| 303 | OnReset();
|
---|
[5577] | 304 | }
|
---|
[5685] | 305 | #endregion
|
---|
[5618] | 306 |
|
---|
[5685] | 307 | protected virtual void ParameterizeOperators() {
|
---|
[7506] | 308 | var operators = Parameters.OfType<IValueParameter>().Select(p => p.Value).OfType<IOperator>().Union(Operators).ToList();
|
---|
[5618] | 309 |
|
---|
| 310 | foreach (var op in operators.OfType<ISymbolicExpressionTreeGrammarBasedOperator>()) {
|
---|
[8664] | 311 | op.SymbolicExpressionTreeGrammarParameter.ActualName = SymbolicExpressionTreeGrammarParameter.Name;
|
---|
[5618] | 312 | }
|
---|
| 313 | foreach (var op in operators.OfType<ISymbolicExpressionTreeSizeConstraintOperator>()) {
|
---|
[8664] | 314 | op.MaximumSymbolicExpressionTreeDepthParameter.ActualName = MaximumSymbolicExpressionTreeDepthParameter.Name;
|
---|
| 315 | op.MaximumSymbolicExpressionTreeLengthParameter.ActualName = MaximumSymbolicExpressionTreeLengthParameter.Name;
|
---|
[5618] | 316 | }
|
---|
| 317 | foreach (var op in operators.OfType<ISymbolicExpressionTreeArchitectureAlteringOperator>()) {
|
---|
[8664] | 318 | op.MaximumFunctionArgumentsParameter.ActualName = MaximumFunctionArgumentsParameter.Name;
|
---|
| 319 | op.MaximumFunctionDefinitionsParameter.ActualName = MaximumFunctionDefinitionsParameter.Name;
|
---|
[5618] | 320 | }
|
---|
| 321 | foreach (var op in operators.OfType<ISymbolicDataAnalysisEvaluator<T>>()) {
|
---|
[5685] | 322 | op.ProblemDataParameter.ActualName = ProblemDataParameterName;
|
---|
[5618] | 323 | op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
[5759] | 324 | op.EvaluationPartitionParameter.ActualName = FitnessCalculationPartitionParameter.Name;
|
---|
| 325 | op.RelativeNumberOfEvaluatedSamplesParameter.ActualName = RelativeNumberOfEvaluatedSamplesParameter.Name;
|
---|
[8664] | 326 | op.ApplyLinearScalingParameter.ActualName = ApplyLinearScalingParameter.Name;
|
---|
[5618] | 327 | }
|
---|
| 328 | foreach (var op in operators.OfType<ISymbolicExpressionTreeCrossover>()) {
|
---|
| 329 | op.ParentsParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
[12422] | 330 | op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
[5618] | 331 | }
|
---|
| 332 | foreach (var op in operators.OfType<ISymbolicExpressionTreeManipulator>()) {
|
---|
| 333 | op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
| 334 | }
|
---|
| 335 | foreach (var op in operators.OfType<ISymbolicExpressionTreeAnalyzer>()) {
|
---|
| 336 | op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
| 337 | }
|
---|
[8664] | 338 | foreach (var op in operators.OfType<ISymbolicDataAnalysisSingleObjectiveAnalyzer>()) {
|
---|
| 339 | op.ApplyLinearScalingParameter.ActualName = ApplyLinearScalingParameter.Name;
|
---|
| 340 | }
|
---|
| 341 | foreach (var op in operators.OfType<ISymbolicDataAnalysisMultiObjectiveAnalyzer>()) {
|
---|
| 342 | op.ApplyLinearScalingParameter.ActualName = ApplyLinearScalingParameter.Name;
|
---|
| 343 | }
|
---|
[6135] | 344 | foreach (var op in operators.OfType<ISymbolicDataAnalysisAnalyzer>()) {
|
---|
| 345 | op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
| 346 | }
|
---|
[5759] | 347 | foreach (var op in operators.OfType<ISymbolicDataAnalysisValidationAnalyzer<U, T>>()) {
|
---|
| 348 | op.RelativeNumberOfEvaluatedSamplesParameter.ActualName = RelativeNumberOfEvaluatedSamplesParameter.Name;
|
---|
[5883] | 349 | op.ValidationPartitionParameter.ActualName = ValidationPartitionParameter.Name;
|
---|
[5759] | 350 | }
|
---|
[5685] | 351 | foreach (var op in operators.OfType<ISymbolicDataAnalysisInterpreterOperator>()) {
|
---|
[8664] | 352 | op.SymbolicDataAnalysisTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
|
---|
[5685] | 353 | }
|
---|
[7506] | 354 | foreach (var op in operators.OfType<ISymbolicDataAnalysisExpressionCrossover<T>>()) {
|
---|
[8664] | 355 | op.EvaluationPartitionParameter.ActualName = FitnessCalculationPartitionParameter.Name;
|
---|
[7506] | 356 | op.ProblemDataParameter.ActualName = ProblemDataParameter.Name;
|
---|
| 357 | op.EvaluationPartitionParameter.ActualName = FitnessCalculationPartitionParameter.Name;
|
---|
| 358 | op.RelativeNumberOfEvaluatedSamplesParameter.ActualName = RelativeNumberOfEvaluatedSamplesParameter.Name;
|
---|
| 359 | op.EvaluatorParameter.ActualName = EvaluatorParameter.Name;
|
---|
| 360 | }
|
---|
[18082] | 361 | foreach (var op in operators.OfType<ISymbolicDataAnalysisExpressionManipulator<T>>()) {
|
---|
| 362 | op.EvaluationPartitionParameter.ActualName = FitnessCalculationPartitionParameter.Name;
|
---|
| 363 | op.ProblemDataParameter.ActualName = ProblemDataParameter.Name;
|
---|
| 364 | op.EvaluationPartitionParameter.ActualName = FitnessCalculationPartitionParameter.Name;
|
---|
| 365 | op.RelativeNumberOfEvaluatedSamplesParameter.ActualName = RelativeNumberOfEvaluatedSamplesParameter.Name;
|
---|
| 366 | op.EvaluatorParameter.ActualName = EvaluatorParameter.Name;
|
---|
| 367 | }
|
---|
[5618] | 368 | }
|
---|
[5623] | 369 |
|
---|
[7823] | 370 | #region Import & Export
|
---|
[9452] | 371 | public virtual void Load(T data) {
|
---|
[7823] | 372 | Name = data.Name;
|
---|
| 373 | Description = data.Description;
|
---|
| 374 | ProblemData = data;
|
---|
| 375 | }
|
---|
| 376 |
|
---|
[9452] | 377 | public virtual T Export() {
|
---|
[7823] | 378 | return ProblemData;
|
---|
| 379 | }
|
---|
| 380 | #endregion
|
---|
[5577] | 381 | }
|
---|
| 382 | }
|
---|