Free cookie consent management tool by TermsFeed Policy Generator

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

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

Moved common (not algorithm specific) model analyzer code (same operator tree in all regression/classification/time-series-prognosis engines) to HL.Modeling. #625, #705, #739.

File size: 7.8 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      BestAverageWorstQualityCalculator validationQualityCalculator = new BestAverageWorstQualityCalculator();
75      validationQualityCalculator.Name = "BestAverageWorstValidationQualityCalculator";
76      validationQualityCalculator.GetVariableInfo("Quality").ActualName = "ValidationQuality";
77      validationQualityCalculator.GetVariableInfo("BestQuality").ActualName = "BestValidationQuality";
78      validationQualityCalculator.GetVariableInfo("AverageQuality").ActualName = "AverageValidationQuality";
79      validationQualityCalculator.GetVariableInfo("WorstQuality").ActualName = "WorstValidationQuality";
80
81      subScopesProc.AddSubOperator(individualProc);
82
83      seq.AddSubOperator(subScopesProc);
84      seq.AddSubOperator(solutionStorer);
85      seq.AddSubOperator(validationQualityCalculator);
86
87      op.OperatorGraph.AddOperator(seq);
88      op.OperatorGraph.InitialOperator = seq;
89      return op;
90    }
91
92
93    public static IOperator CreatePreparationForPostProcessingOperator() {
94      SequentialProcessor seq = new SequentialProcessor();
95      LeftReducer cleanUp = new LeftReducer();
96      cleanUp.Name = "Reset Population";
97      seq.AddSubOperator(cleanUp);
98
99      SolutionExtractor extractor = new SolutionExtractor();
100      extractor.GetVariableInfo("Scope").ActualName = "BestValidationSolution";
101      SequentialSubScopesProcessor seqSubScopeProc = new SequentialSubScopesProcessor();
102      SequentialProcessor solutionProc = new SequentialProcessor();
103
104      seq.AddSubOperator(extractor);
105      seq.AddSubOperator(seqSubScopeProc);
106      seqSubScopeProc.AddSubOperator(solutionProc);
107
108      HL3TreeEvaluatorInjector evaluatorInjector = new HL3TreeEvaluatorInjector();
109      evaluatorInjector.AddVariable(new HeuristicLab.Core.Variable("PunishmentFactor", new DoubleData(1000.0)));
110      evaluatorInjector.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
111
112      #region simple evaluators
113      SimpleEvaluator trainingEvaluator = new SimpleEvaluator();
114      trainingEvaluator.Name = "TrainingEvaluator";
115      trainingEvaluator.GetVariableInfo("SamplesStart").ActualName = "TrainingSamplesStart";
116      trainingEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd";
117      trainingEvaluator.GetVariableInfo("Values").ActualName = "TrainingValues";
118      trainingEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
119      SimpleEvaluator validationEvaluator = new SimpleEvaluator();
120      validationEvaluator.Name = "ValidationEvaluator";
121      validationEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";
122      validationEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";
123      validationEvaluator.GetVariableInfo("Values").ActualName = "ValidationValues";
124      validationEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
125      SimpleEvaluator testEvaluator = new SimpleEvaluator();
126      testEvaluator.Name = "TestEvaluator";
127      testEvaluator.GetVariableInfo("SamplesStart").ActualName = "TestSamplesStart";
128      testEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TestSamplesEnd";
129      testEvaluator.GetVariableInfo("Values").ActualName = "TestValues";
130      testEvaluator.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
131      solutionProc.AddSubOperator(evaluatorInjector);
132      solutionProc.AddSubOperator(trainingEvaluator);
133      solutionProc.AddSubOperator(validationEvaluator);
134      solutionProc.AddSubOperator(testEvaluator);
135      #endregion
136
137      #region variable impacts
138      // calculate and set variable impacts
139      VariableNamesExtractor namesExtractor = new VariableNamesExtractor();
140      namesExtractor.GetVariableInfo("VariableNames").ActualName = "InputVariableNames";
141      PredictorBuilder predictorBuilder = new PredictorBuilder();
142      predictorBuilder.GetVariableInfo("TreeEvaluator").ActualName = "ModelAnalysisTreeEvaluator";
143
144      solutionProc.AddSubOperator(namesExtractor);
145      solutionProc.AddSubOperator(predictorBuilder);
146      #endregion
147
148      return seq;
149    }
150
151    public static void PopulateAnalyzerModel(IScope bestModelScope, IAnalyzerModel model) {
152      model.SetMetaData("EvaluatedSolutions", bestModelScope.GetVariableValue<DoubleData>("EvaluatedSolutions", false).Data);
153      IGeneticProgrammingModel gpModel = bestModelScope.GetVariableValue<IGeneticProgrammingModel>("FunctionTree", false);
154      model.SetMetaData("TreeSize", gpModel.Size);
155      model.SetMetaData("TreeHeight", gpModel.Height);
156    }
157  }
158}
Note: See TracBrowser for help on using the repository browser.