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