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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using HeuristicLab.Core;
|
---|
25 | using HeuristicLab.Data;
|
---|
26 | using HeuristicLab.Evolutionary;
|
---|
27 | using HeuristicLab.Logging;
|
---|
28 | using HeuristicLab.Operators;
|
---|
29 | using HeuristicLab.Selection;
|
---|
30 | using HeuristicLab.Selection.OffspringSelection;
|
---|
31 | using HeuristicLab.Modeling;
|
---|
32 |
|
---|
33 | namespace HeuristicLab.GP.StructureIdentification {
|
---|
34 | public class OffspringSelectionGP : HeuristicLab.GP.Algorithms.OffspringSelectionGP {
|
---|
35 | public override string Name { get { return "OffspringSelectionGP - StructureIdentification"; } }
|
---|
36 |
|
---|
37 | public virtual double PunishmentFactor {
|
---|
38 | get { return GetVariableInjector().GetVariable("PunishmentFactor").GetValue<DoubleData>().Data; }
|
---|
39 | set { GetVariableInjector().GetVariable("PunishmentFactor").GetValue<DoubleData>().Data = value; }
|
---|
40 | }
|
---|
41 |
|
---|
42 | public OffspringSelectionGP()
|
---|
43 | : base() {
|
---|
44 | PunishmentFactor = 10.0;
|
---|
45 | }
|
---|
46 |
|
---|
47 | protected override IOperator CreateFunctionLibraryInjector() {
|
---|
48 | CombinedOperator op = new CombinedOperator();
|
---|
49 | op.Name = "FunctionLibraryInjector";
|
---|
50 | SequentialProcessor seq = new SequentialProcessor();
|
---|
51 | seq.AddSubOperator(new FunctionLibraryInjector());
|
---|
52 | seq.AddSubOperator(new HL2TreeEvaluatorInjector());
|
---|
53 | op.OperatorGraph.AddOperator(seq);
|
---|
54 | op.OperatorGraph.InitialOperator = seq;
|
---|
55 | return op;
|
---|
56 | }
|
---|
57 |
|
---|
58 | protected override IOperator CreateProblemInjector() {
|
---|
59 | return new ProblemInjector();
|
---|
60 | }
|
---|
61 |
|
---|
62 | protected override IOperator CreateInitialPopulationEvaluator() {
|
---|
63 | MeanSquaredErrorEvaluator eval = new MeanSquaredErrorEvaluator();
|
---|
64 | eval.Name = "Evaluator";
|
---|
65 | eval.GetVariableInfo("MSE").ActualName = "Quality";
|
---|
66 | eval.GetVariableInfo("SamplesStart").ActualName = "ActualTrainingSamplesStart";
|
---|
67 | eval.GetVariableInfo("SamplesEnd").ActualName = "ActualTrainingSamplesEnd";
|
---|
68 | return eval;
|
---|
69 | }
|
---|
70 |
|
---|
71 | protected override IOperator CreateEvaluationOperator() {
|
---|
72 | return CreateInitialPopulationEvaluator();
|
---|
73 | }
|
---|
74 |
|
---|
75 |
|
---|
76 | protected override IOperator CreateGenerationStepHook() {
|
---|
77 | CombinedOperator op = new CombinedOperator();
|
---|
78 | SequentialProcessor seq = new SequentialProcessor();
|
---|
79 | UniformSequentialSubScopesProcessor subScopesProc = new UniformSequentialSubScopesProcessor();
|
---|
80 | SequentialProcessor individualProc = new SequentialProcessor();
|
---|
81 | MeanSquaredErrorEvaluator validationEvaluator = new MeanSquaredErrorEvaluator();
|
---|
82 | validationEvaluator.Name = "ValidationEvaluator";
|
---|
83 | validationEvaluator.GetVariableInfo("MSE").ActualName = "ValidationQuality";
|
---|
84 | validationEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";
|
---|
85 | validationEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";
|
---|
86 |
|
---|
87 | individualProc.AddSubOperator(validationEvaluator);
|
---|
88 |
|
---|
89 | BestSolutionStorer solutionStorer = new BestSolutionStorer();
|
---|
90 | solutionStorer.GetVariableInfo("BestSolution").ActualName = "BestValidationSolution";
|
---|
91 | solutionStorer.GetVariableInfo("Quality").ActualName = "ValidationQuality";
|
---|
92 |
|
---|
93 | BestAverageWorstQualityCalculator validationQualityCalculator = new BestAverageWorstQualityCalculator();
|
---|
94 | validationQualityCalculator.Name = "BestAverageWorstValidationQualityCalculator";
|
---|
95 | validationQualityCalculator.GetVariableInfo("Quality").ActualName = "ValidationQuality";
|
---|
96 | validationQualityCalculator.GetVariableInfo("BestQuality").ActualName = "BestValidationQuality";
|
---|
97 | validationQualityCalculator.GetVariableInfo("AverageQuality").ActualName = "AverageValidationQuality";
|
---|
98 | validationQualityCalculator.GetVariableInfo("WorstQuality").ActualName = "WorstValidationQuality";
|
---|
99 |
|
---|
100 | subScopesProc.AddSubOperator(individualProc);
|
---|
101 |
|
---|
102 | seq.AddSubOperator(subScopesProc);
|
---|
103 | seq.AddSubOperator(solutionStorer);
|
---|
104 | seq.AddSubOperator(validationQualityCalculator);
|
---|
105 |
|
---|
106 | op.OperatorGraph.AddOperator(seq);
|
---|
107 | op.OperatorGraph.InitialOperator = seq;
|
---|
108 | return op;
|
---|
109 | }
|
---|
110 |
|
---|
111 | protected override VariableInjector CreateGlobalInjector() {
|
---|
112 | VariableInjector injector = base.CreateGlobalInjector();
|
---|
113 | injector.AddVariable(new HeuristicLab.Core.Variable("UseEstimatedTargetValue", new BoolData()));
|
---|
114 | injector.AddVariable(new HeuristicLab.Core.Variable("PunishmentFactor", new DoubleData()));
|
---|
115 | return injector;
|
---|
116 | }
|
---|
117 |
|
---|
118 | protected override IOperator CreateLoggingOperator() {
|
---|
119 | CombinedOperator loggingOperator = new CombinedOperator();
|
---|
120 | loggingOperator.Name = "Logging";
|
---|
121 | SequentialProcessor seq = new SequentialProcessor();
|
---|
122 |
|
---|
123 | DataCollector collector = new DataCollector();
|
---|
124 | ItemList<StringData> names = collector.GetVariable("VariableNames").GetValue<ItemList<StringData>>();
|
---|
125 | names.Add(new StringData("BestQuality"));
|
---|
126 | names.Add(new StringData("AverageQuality"));
|
---|
127 | names.Add(new StringData("WorstQuality"));
|
---|
128 | names.Add(new StringData("BestValidationQuality"));
|
---|
129 | names.Add(new StringData("AverageValidationQuality"));
|
---|
130 | names.Add(new StringData("WorstValidationQuality"));
|
---|
131 | names.Add(new StringData("EvaluatedSolutions"));
|
---|
132 | names.Add(new StringData("SelectionPressure"));
|
---|
133 | QualityLogger qualityLogger = new QualityLogger();
|
---|
134 | QualityLogger validationQualityLogger = new QualityLogger();
|
---|
135 | validationQualityLogger.GetVariableInfo("Quality").ActualName = "ValidationQuality";
|
---|
136 | validationQualityLogger.GetVariableInfo("QualityLog").ActualName = "ValidationQualityLog";
|
---|
137 | seq.AddSubOperator(collector);
|
---|
138 | seq.AddSubOperator(qualityLogger);
|
---|
139 | seq.AddSubOperator(validationQualityLogger);
|
---|
140 |
|
---|
141 | loggingOperator.OperatorGraph.AddOperator(seq);
|
---|
142 | loggingOperator.OperatorGraph.InitialOperator = seq;
|
---|
143 | return loggingOperator;
|
---|
144 | }
|
---|
145 |
|
---|
146 | public override object Clone(IDictionary<Guid, object> clonedObjects) {
|
---|
147 | OffspringSelectionGP clone = (OffspringSelectionGP)base.Clone(clonedObjects);
|
---|
148 | clone.PunishmentFactor = PunishmentFactor;
|
---|
149 | return clone;
|
---|
150 | }
|
---|
151 | }
|
---|
152 | }
|
---|