Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/StandardGP.cs @ 2328

Last change on this file since 2328 was 2328, checked in by gkronber, 15 years ago

this is the remaining part of changeset r2327.
Applied changes in modeling plugins that are necessary for the new model analyzer (#722)

  • predictor has properties for the lower and upper limit of the predicted value
  • added views for predictors that show the limits (also added a new view for GeneticProgrammingModel that shows the size and height of the model)
  • Reintroduced TreeEvaluatorInjectors that read a PunishmentFactor and calculate the lower and upper limits for estimated values (limits are set in the tree evaluators)
  • Added operators to create Predictors. Changed modeling algorithms to use the predictors for the calculation of final model qualities and variable impacts (to be compatible with the new model analyzer the predictors use a very large PunishmentFactor)
  • replaced all private implementations of double.IsAlmost and use HL.Commons instead (see #733 r2324)
  • Implemented operator SolutionExtractor and moved BestSolutionStorer from HL.Logging to HL.Modeling (fixes #734)
File size: 10.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
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
22using HeuristicLab.Core;
23using HeuristicLab.DataAnalysis;
24using HeuristicLab.Operators;
25using HeuristicLab.Selection;
26using HeuristicLab.Logging;
27using HeuristicLab.Data;
28using HeuristicLab.Operators.Programmable;
29using HeuristicLab.Modeling;
30using HeuristicLab.GP.Operators;
31
32namespace HeuristicLab.GP.StructureIdentification {
33  public class StandardGP : AlgorithmBase, IEditable {
34
35    public override string Name { get { return "StandardGP"; } }
36
37    public override int TargetVariable {
38      get { return ProblemInjector.GetVariableValue<IntData>("TargetVariable", null, false).Data; }
39      set { ProblemInjector.GetVariableValue<IntData>("TargetVariable", null, false).Data = value; }
40    }
41
42    public override Dataset Dataset {
43      get { return ProblemInjector.GetVariableValue<Dataset>("Dataset", null, false); }
44      set { ProblemInjector.GetVariable("Dataset").Value = value; }
45    }
46
47    public virtual int MaxGenerations {
48      get { return GetVariableInjector().GetVariable("MaxGenerations").GetValue<IntData>().Data; }
49      set { GetVariableInjector().GetVariable("MaxGenerations").GetValue<IntData>().Data = value; }
50    }
51
52    public virtual int TournamentSize {
53      get { return GetVariableInjector().GetVariable("TournamentSize").GetValue<IntData>().Data; }
54      set { GetVariableInjector().GetVariable("TournamentSize").GetValue<IntData>().Data = value; }
55    }
56
57    public double FullTreeShakingFactor {
58      get { return GetVariableInjector().GetVariable("FullTreeShakingFactor").GetValue<DoubleData>().Data; }
59      set { GetVariableInjector().GetVariable("FullTreeShakingFactor").GetValue<DoubleData>().Data = value; }
60    }
61
62    public double OnePointShakingFactor {
63      get { return GetVariableInjector().GetVariable("OnePointShakingFactor").GetValue<DoubleData>().Data; }
64      set { GetVariableInjector().GetVariable("OnePointShakingFactor").GetValue<DoubleData>().Data = value; }
65    }
66
67    public int MinInitialTreeSize {
68      get { return GetVariableInjector().GetVariable("MinInitialTreeSize").GetValue<IntData>().Data; }
69      set { GetVariableInjector().GetVariable("MinInitialTreeSize").GetValue<IntData>().Data = value; }
70    }
71
72    public override int MaxTreeSize {
73      get {
74        return base.MaxTreeSize;
75      }
76      set {
77        base.MaxTreeSize = value;
78        MinInitialTreeSize = value / 2;
79      }
80    }
81
82    public override int PopulationSize {
83      get {
84        return base.PopulationSize;
85      }
86      set {
87        base.PopulationSize = value;
88        Parents = 2 * value;
89      }
90    }
91
92    public override IOperator ProblemInjector {
93      get { return base.ProblemInjector.SubOperators[0]; }
94      set {
95        value.Name = "ProblemInjector";
96        base.ProblemInjector.RemoveSubOperator(0);
97        base.ProblemInjector.AddSubOperator(value, 0);
98      }
99    }
100
101    public StandardGP()
102      : base() {
103      PopulationSize = 10000;
104      MaxGenerations = 500;
105      TournamentSize = 7;
106      MutationRate = 0.15;
107      Elites = 1;
108      MaxTreeSize = 100;
109      MaxTreeHeight = 10;
110      FullTreeShakingFactor = 0.1;
111      OnePointShakingFactor = 1.0;
112      UseEstimatedTargetValue = false;
113      SetSeedRandomly = true;
114    }
115
116    protected internal override IOperator CreateProblemInjector() {
117      SequentialProcessor seq = new SequentialProcessor();
118      var probInject = new ProblemInjector();
119      probInject.GetVariableInfo("MaxNumberOfTrainingSamples").Local = true;
120      probInject.AddVariable(new HeuristicLab.Core.Variable("MaxNumberOfTrainingSamples", new IntData(5000)));
121
122      var shuffler = new DatasetShuffler();
123      shuffler.GetVariableInfo("ShuffleStart").ActualName = "TrainingSamplesStart";
124      shuffler.GetVariableInfo("ShuffleEnd").ActualName = "TrainingSamplesEnd";
125
126      seq.AddSubOperator(probInject);
127      seq.AddSubOperator(shuffler);
128      return seq;
129    }
130
131    protected internal override IOperator CreateSelector() {
132      TournamentSelector selector = new TournamentSelector();
133      selector.Name = "Selector";
134      selector.GetVariableInfo("Selected").ActualName = "Parents";
135      selector.GetVariableInfo("GroupSize").Local = false;
136      selector.RemoveVariable("GroupSize");
137      selector.GetVariableInfo("GroupSize").ActualName = "TournamentSize";
138      return selector;
139    }
140
141    protected internal override IOperator CreateGlobalInjector() {
142      VariableInjector globalInjector = (VariableInjector)base.CreateGlobalInjector();
143      globalInjector.AddVariable(new HeuristicLab.Core.Variable("TournamentSize", new IntData()));
144      globalInjector.AddVariable(new HeuristicLab.Core.Variable("MaxGenerations", new IntData()));
145      globalInjector.AddVariable(new HeuristicLab.Core.Variable("FullTreeShakingFactor", new DoubleData()));
146      globalInjector.AddVariable(new HeuristicLab.Core.Variable("OnePointShakingFactor", new DoubleData()));
147      globalInjector.AddVariable(new HeuristicLab.Core.Variable("MinInitialTreeSize", new IntData()));
148      return globalInjector;
149    }
150
151    protected internal override IOperator CreateCrossover() {
152      StandardCrossOver crossover = new StandardCrossOver();
153      crossover.Name = "Crossover";
154      return crossover;
155    }
156
157    protected internal override IOperator CreateTreeCreator() {
158      ProbabilisticTreeCreator treeCreator = new ProbabilisticTreeCreator();
159      treeCreator.Name = "Tree generator";
160      treeCreator.GetVariableInfo("MinTreeSize").ActualName = "MinInitialTreeSize";
161      return treeCreator;
162    }
163
164    protected internal override IOperator CreateFunctionLibraryInjector() {
165      FunctionLibraryInjector funLibInjector = new FunctionLibraryInjector();
166      funLibInjector.GetVariableValue<BoolData>("Xor", null, false).Data = false;
167      funLibInjector.GetVariableValue<BoolData>("Average", null, false).Data = false;
168      return funLibInjector;
169    }
170
171    protected internal override IOperator CreateManipulator() {
172      CombinedOperator manipulator = new CombinedOperator();
173      manipulator.Name = "Manipulator";
174      StochasticMultiBranch multibranch = new StochasticMultiBranch();
175      FullTreeShaker fullTreeShaker = new FullTreeShaker();
176      fullTreeShaker.GetVariableInfo("ShakingFactor").ActualName = "FullTreeShakingFactor";
177
178      OnePointShaker onepointShaker = new OnePointShaker();
179      onepointShaker.GetVariableInfo("ShakingFactor").ActualName = "OnePointShakingFactor";
180      ChangeNodeTypeManipulation changeNodeTypeManipulation = new ChangeNodeTypeManipulation();
181      CutOutNodeManipulation cutOutNodeManipulation = new CutOutNodeManipulation();
182      DeleteSubTreeManipulation deleteSubTreeManipulation = new DeleteSubTreeManipulation();
183      SubstituteSubTreeManipulation substituteSubTreeManipulation = new SubstituteSubTreeManipulation();
184
185      IOperator[] manipulators = new IOperator[] {
186        onepointShaker, fullTreeShaker,
187        changeNodeTypeManipulation,
188        cutOutNodeManipulation,
189        deleteSubTreeManipulation,
190        substituteSubTreeManipulation};
191
192      DoubleArrayData probabilities = new DoubleArrayData(new double[manipulators.Length]);
193      for (int i = 0; i < manipulators.Length; i++) {
194        probabilities.Data[i] = 1.0;
195        multibranch.AddSubOperator(manipulators[i]);
196      }
197      multibranch.GetVariableInfo("Probabilities").Local = true;
198      multibranch.AddVariable(new HeuristicLab.Core.Variable("Probabilities", probabilities));
199
200      manipulator.OperatorGraph.AddOperator(multibranch);
201      manipulator.OperatorGraph.InitialOperator = multibranch;
202      return manipulator;
203    }
204
205    protected internal override IOperator CreateLoggingOperator() {
206      CombinedOperator loggingOperator = new CombinedOperator();
207      loggingOperator.Name = "Logging";
208      SequentialProcessor seq = new SequentialProcessor();
209
210      DataCollector collector = new DataCollector();
211      ItemList<StringData> names = collector.GetVariable("VariableNames").GetValue<ItemList<StringData>>();
212      names.Add(new StringData("BestQuality"));
213      names.Add(new StringData("AverageQuality"));
214      names.Add(new StringData("WorstQuality"));
215      names.Add(new StringData("BestValidationQuality"));
216      names.Add(new StringData("AverageValidationQuality"));
217      names.Add(new StringData("WorstValidationQuality"));
218      LinechartInjector lineChartInjector = new LinechartInjector();
219      lineChartInjector.GetVariableInfo("Linechart").ActualName = "Quality Linechart";
220      lineChartInjector.GetVariable("NumberOfLines").GetValue<IntData>().Data = 6;
221      QualityLogger qualityLogger = new QualityLogger();
222      QualityLogger validationQualityLogger = new QualityLogger();
223      validationQualityLogger.Name = "ValidationQualityLogger";
224      validationQualityLogger.GetVariableInfo("Quality").ActualName = "ValidationQuality";
225      validationQualityLogger.GetVariableInfo("QualityLog").ActualName = "ValidationQualityLog";
226
227      seq.AddSubOperator(collector);
228      seq.AddSubOperator(lineChartInjector);
229      seq.AddSubOperator(qualityLogger);
230      seq.AddSubOperator(validationQualityLogger);
231
232      loggingOperator.OperatorGraph.AddOperator(seq);
233      loggingOperator.OperatorGraph.InitialOperator = seq;
234      return loggingOperator;
235    }
236
237    public virtual IEditor CreateEditor() {
238      return new StandardGpEditor(this);
239    }
240
241    public override IView CreateView() {
242      return new StandardGpEditor(this);
243    }
244  }
245}
Note: See TracBrowser for help on using the repository browser.