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