Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/DefaultStructureIdentificationOperators.cs @ 2375

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

Fixed problems with classification algorithms. #746 (CEDMA server is not compatible with new data-modeling algorithms)

File size: 8.1 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.GP.Interfaces;
25using HeuristicLab.Operators;
26using HeuristicLab.Modeling;
27using HeuristicLab.Logging;
28using HeuristicLab.Selection;
29using HeuristicLab.Data;
30
31namespace HeuristicLab.GP.StructureIdentification {
32  public static class DefaultStructureIdentificationOperators {
33    public static IOperator CreateFunctionLibraryInjector() {
34      CombinedOperator op = new CombinedOperator();
35      op.Name = "FunctionLibraryInjector";
36      SequentialProcessor seq = new SequentialProcessor();
37      seq.AddSubOperator(new FunctionLibraryInjector());
38      seq.AddSubOperator(new HL3TreeEvaluatorInjector());
39      op.OperatorGraph.AddOperator(seq);
40      op.OperatorGraph.InitialOperator = seq;
41      return op;
42    }
43
44    public static IOperator CreateInitialPopulationEvaluator() {
45      MeanSquaredErrorEvaluator eval = new MeanSquaredErrorEvaluator();
46      eval.Name = "Evaluator";
47      eval.GetVariableInfo("MSE").ActualName = "Quality";
48      eval.GetVariableInfo("SamplesStart").ActualName = "ActualTrainingSamplesStart";
49      eval.GetVariableInfo("SamplesEnd").ActualName = "ActualTrainingSamplesEnd";
50      return eval;
51    }
52
53    public static IOperator CreateEvaluator() {
54      return CreateInitialPopulationEvaluator();
55    }
56
57    public static IOperator CreateGenerationStepHook() {
58      CombinedOperator op = new CombinedOperator();
59      SequentialProcessor seq = new SequentialProcessor();
60      UniformSequentialSubScopesProcessor subScopesProc = new UniformSequentialSubScopesProcessor();
61      SequentialProcessor individualProc = new SequentialProcessor();
62      MeanSquaredErrorEvaluator validationEvaluator = new MeanSquaredErrorEvaluator();
63      validationEvaluator.Name = "ValidationEvaluator";
64      validationEvaluator.GetVariableInfo("MSE").ActualName = "ValidationQuality";
65      validationEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";
66      validationEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";
67
68      individualProc.AddSubOperator(validationEvaluator);
69
70      BestSolutionStorer solutionStorer = new BestSolutionStorer();
71      solutionStorer.GetVariableInfo("BestSolution").ActualName = "BestValidationSolution";
72      solutionStorer.GetVariableInfo("Quality").ActualName = "ValidationQuality";
73
74      OperatorExtractor bestSolutionProcessor = new OperatorExtractor();
75      bestSolutionProcessor.Name = "BestSolutionProcessor (extr.)";
76      bestSolutionProcessor.GetVariableInfo("Operator").ActualName = "BestSolutionProcessor";
77
78      solutionStorer.AddSubOperator(bestSolutionProcessor);
79
80      BestAverageWorstQualityCalculator validationQualityCalculator = new BestAverageWorstQualityCalculator();
81      validationQualityCalculator.Name = "BestAverageWorstValidationQualityCalculator";
82      validationQualityCalculator.GetVariableInfo("Quality").ActualName = "ValidationQuality";
83      validationQualityCalculator.GetVariableInfo("BestQuality").ActualName = "BestValidationQuality";
84      validationQualityCalculator.GetVariableInfo("AverageQuality").ActualName = "AverageValidationQuality";
85      validationQualityCalculator.GetVariableInfo("WorstQuality").ActualName = "WorstValidationQuality";
86
87      subScopesProc.AddSubOperator(individualProc);
88
89      seq.AddSubOperator(subScopesProc);
90      seq.AddSubOperator(solutionStorer);
91      seq.AddSubOperator(validationQualityCalculator);
92
93      op.OperatorGraph.AddOperator(seq);
94      op.OperatorGraph.InitialOperator = seq;
95      return op;
96    }
97
98
99    public static IOperator CreatePreparationForPostProcessingOperator() {
100      SequentialProcessor seq = new SequentialProcessor();
101      LeftReducer cleanUp = new LeftReducer();
102      cleanUp.Name = "Reset Population";
103      seq.AddSubOperator(cleanUp);
104
105      SolutionExtractor extractor = new SolutionExtractor();
106      extractor.GetVariableInfo("Scope").ActualName = "BestValidationSolution";
107      SequentialSubScopesProcessor seqSubScopeProc = new SequentialSubScopesProcessor();
108      SequentialProcessor solutionProc = new SequentialProcessor();
109
110      seq.AddSubOperator(extractor);
111      seq.AddSubOperator(seqSubScopeProc);
112      seqSubScopeProc.AddSubOperator(solutionProc);
113
114      HL3TreeEvaluatorInjector evaluatorInjector = new HL3TreeEvaluatorInjector();
115      evaluatorInjector.AddVariable(new HeuristicLab.Core.Variable("PunishmentFactor", new DoubleData(1000.0)));
116      evaluatorInjector.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
117
118      #region simple evaluators
119      SimpleEvaluator trainingEvaluator = new SimpleEvaluator();
120      trainingEvaluator.Name = "TrainingEvaluator";
121      trainingEvaluator.GetVariableInfo("SamplesStart").ActualName = "TrainingSamplesStart";
122      trainingEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd";
123      trainingEvaluator.GetVariableInfo("Values").ActualName = "TrainingValues";
124      trainingEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
125      SimpleEvaluator validationEvaluator = new SimpleEvaluator();
126      validationEvaluator.Name = "ValidationEvaluator";
127      validationEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";
128      validationEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";
129      validationEvaluator.GetVariableInfo("Values").ActualName = "ValidationValues";
130      validationEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
131      SimpleEvaluator testEvaluator = new SimpleEvaluator();
132      testEvaluator.Name = "TestEvaluator";
133      testEvaluator.GetVariableInfo("SamplesStart").ActualName = "TestSamplesStart";
134      testEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TestSamplesEnd";
135      testEvaluator.GetVariableInfo("Values").ActualName = "TestValues";
136      testEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
137      solutionProc.AddSubOperator(evaluatorInjector);
138      solutionProc.AddSubOperator(trainingEvaluator);
139      solutionProc.AddSubOperator(validationEvaluator);
140      solutionProc.AddSubOperator(testEvaluator);
141      #endregion
142
143      #region variable impacts
144      // calculate and set variable impacts
145      VariableNamesExtractor namesExtractor = new VariableNamesExtractor();
146      namesExtractor.GetVariableInfo("VariableNames").ActualName = "InputVariableNames";
147      PredictorBuilder predictorBuilder = new PredictorBuilder();
148      predictorBuilder.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
149
150      solutionProc.AddSubOperator(namesExtractor);
151      solutionProc.AddSubOperator(predictorBuilder);
152      #endregion
153
154      return seq;
155    }
156
157    public static void PopulateAnalyzerModel(IScope bestModelScope, IAnalyzerModel model) {
158      model.SetMetaData("EvaluatedSolutions", bestModelScope.GetVariableValue<IntData>("EvaluatedSolutions", false).Data);
159      IGeneticProgrammingModel gpModel = bestModelScope.GetVariableValue<IGeneticProgrammingModel>("FunctionTree", false);
160      model.SetMetaData("TreeSize", gpModel.Size);
161      model.SetMetaData("TreeHeight", gpModel.Height);
162    }
163  }
164}
Note: See TracBrowser for help on using the repository browser.