Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/ValidationBestScaledSymbolicRegressionSolutionAnalyzer.cs @ 7214

Last change on this file since 7214 was 7214, checked in by ascheibe, 12 years ago

#1706 adapted outdated plugins to changes in IAnalyzer

File size: 18.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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 System;
23using HeuristicLab.Analysis;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
28using HeuristicLab.Operators;
29using HeuristicLab.Optimization;
30using HeuristicLab.Optimization.Operators;
31using HeuristicLab.Parameters;
32using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
33using HeuristicLab.PluginInfrastructure;
34using HeuristicLab.Problems.DataAnalysis.Symbolic;
35
36namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Analyzers {
37  /// <summary>
38  /// An operator that analyzes the validation best scaled symbolic regression solution.
39  /// </summary>
40  [Item("ValidationBestScaledSymbolicRegressionSolutionAnalyzer", "An operator that analyzes the validation best scaled symbolic regression solution.")]
41  [StorableClass]
42  [NonDiscoverableType]
43  public sealed class ValidationBestScaledSymbolicRegressionSolutionAnalyzer : AlgorithmOperator, ISymbolicRegressionAnalyzer {
44    private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
45    private const string ScaledSymbolicExpressionTreeParameterName = "ScaledSymbolicExpressionTree";
46    private const string SymbolicExpressionTreeInterpreterParameterName = "SymbolicExpressionTreeInterpreter";
47    private const string ProblemDataParameterName = "ProblemData";
48    private const string TrainingSamplesStartParameterName = "TrainingSamplesStart";
49    private const string TrainingSamplesEndParameterName = "TrainingSamplesEnd";
50    private const string ValidationSamplesStartParameterName = "ValidationSamplesStart";
51    private const string ValidationSamplesEndParameterName = "ValidationSamplesEnd";
52    private const string TestSamplesStartParameterName = "TestSamplesStart";
53    private const string TestSamplesEndParameterName = "TestSamplesEnd";
54    private const string QualityParameterName = "Quality";
55    private const string ScaledQualityParameterName = "ScaledQuality";
56    private const string UpperEstimationLimitParameterName = "UpperEstimationLimit";
57    private const string LowerEstimationLimitParameterName = "LowerEstimationLimit";
58    private const string AlphaParameterName = "Alpha";
59    private const string BetaParameterName = "Beta";
60    private const string BestSolutionParameterName = "Best solution (validation)";
61    private const string BestSolutionQualityParameterName = "Best solution quality (validation)";
62    private const string CurrentBestValidationQualityParameterName = "Current best validation quality";
63    private const string ResultsParameterName = "Results";
64    private const string BestKnownQualityParameterName = "BestKnownQuality";
65
66    public bool EnabledByDefault {
67      get { return true; }
68    }
69
70    public ScopeTreeLookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter {
71      get { return (ScopeTreeLookupParameter<SymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
72    }
73    public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
74      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters[QualityParameterName]; }
75    }
76    public IValueLookupParameter<ISymbolicExpressionTreeInterpreter> SymbolicExpressionTreeInterpreterParameter {
77      get { return (IValueLookupParameter<ISymbolicExpressionTreeInterpreter>)Parameters[SymbolicExpressionTreeInterpreterParameterName]; }
78    }
79    public IValueLookupParameter<DataAnalysisProblemData> ProblemDataParameter {
80      get { return (IValueLookupParameter<DataAnalysisProblemData>)Parameters[ProblemDataParameterName]; }
81    }
82    public IValueLookupParameter<IntValue> TrainingSamplesStartParameter {
83      get { return (IValueLookupParameter<IntValue>)Parameters[TrainingSamplesStartParameterName]; }
84    }
85    public IValueLookupParameter<IntValue> TrainingSamplesEndParameter {
86      get { return (IValueLookupParameter<IntValue>)Parameters[TrainingSamplesEndParameterName]; }
87    }
88    public IValueLookupParameter<IntValue> ValidationSamplesStartParameter {
89      get { return (IValueLookupParameter<IntValue>)Parameters[ValidationSamplesStartParameterName]; }
90    }
91    public IValueLookupParameter<IntValue> ValidationSamplesEndParameter {
92      get { return (IValueLookupParameter<IntValue>)Parameters[ValidationSamplesEndParameterName]; }
93    }
94    public IValueLookupParameter<IntValue> TestSamplesStartParameter {
95      get { return (IValueLookupParameter<IntValue>)Parameters[TestSamplesStartParameterName]; }
96    }
97    public IValueLookupParameter<IntValue> TestSamplesEndParameter {
98      get { return (IValueLookupParameter<IntValue>)Parameters[TestSamplesEndParameterName]; }
99    }
100    public IValueLookupParameter<DoubleValue> UpperEstimationLimitParameter {
101      get { return (IValueLookupParameter<DoubleValue>)Parameters[UpperEstimationLimitParameterName]; }
102    }
103    public IValueLookupParameter<DoubleValue> LowerEstimationLimitParameter {
104      get { return (IValueLookupParameter<DoubleValue>)Parameters[LowerEstimationLimitParameterName]; }
105    }
106    public ILookupParameter<SymbolicRegressionSolution> BestSolutionParameter {
107      get { return (ILookupParameter<SymbolicRegressionSolution>)Parameters[BestSolutionParameterName]; }
108    }
109    public ILookupParameter<DoubleValue> BestSolutionQualityParameter {
110      get { return (ILookupParameter<DoubleValue>)Parameters[BestSolutionQualityParameterName]; }
111    }
112    public ILookupParameter<ResultCollection> ResultsParameter {
113      get { return (ILookupParameter<ResultCollection>)Parameters[ResultsParameterName]; }
114    }
115    public ILookupParameter<DoubleValue> BestKnownQualityParameter {
116      get { return (ILookupParameter<DoubleValue>)Parameters[BestKnownQualityParameterName]; }
117    }
118
119    [Storable]
120    private UniformSubScopesProcessor subScopesProcessor;
121    [Storable]
122    private SymbolicRegressionSolutionLinearScaler linearScaler;
123    [Storable]
124    private SymbolicRegressionModelQualityAnalyzer modelQualityAnalyzer;
125    [Storable]
126    private SymbolicRegressionMeanSquaredErrorEvaluator validationMseEvaluator;
127    [Storable]
128    private BestSymbolicRegressionSolutionAnalyzer bestSolutionAnalyzer;
129    [Storable]
130    private UniformSubScopesProcessor cleaningSubScopesProcessor;
131    [Storable]
132    private Assigner removeScaledExpressionTreeAssigner;
133    [Storable]
134    private BestQualityMemorizer bestKnownQualityMemorizer;
135    [Storable]
136    private BestAverageWorstQualityCalculator bestAvgWorstValidationQualityCalculator;
137    [Storable]
138    private DataTableValuesCollector validationValuesCollector;
139    [Storable]
140    private ResultsCollector resultsCollector;
141
142    [StorableConstructor]
143    private ValidationBestScaledSymbolicRegressionSolutionAnalyzer(bool deserializing) : base(deserializing) { }
144    private ValidationBestScaledSymbolicRegressionSolutionAnalyzer(ValidationBestScaledSymbolicRegressionSolutionAnalyzer original, Cloner cloner)
145      : base(original, cloner) {
146      Initialize();
147    }
148    public ValidationBestScaledSymbolicRegressionSolutionAnalyzer()
149      : base() {
150      Parameters.Add(new ScopeTreeLookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression trees to analyze."));
151      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>(QualityParameterName, "The quality of the symbolic expression trees to analyze."));
152      Parameters.Add(new ValueLookupParameter<ISymbolicExpressionTreeInterpreter>(SymbolicExpressionTreeInterpreterParameterName, "The interpreter that should be used for the analysis of symbolic expression trees."));
153      Parameters.Add(new ValueLookupParameter<DataAnalysisProblemData>(ProblemDataParameterName, "The problem data for which the symbolic expression tree is a solution."));
154      Parameters.Add(new ValueLookupParameter<IntValue>(TrainingSamplesStartParameterName, "The first index of the training partition of the data set."));
155      Parameters.Add(new ValueLookupParameter<IntValue>(TrainingSamplesEndParameterName, "The last index of the training partition of the data set."));
156      Parameters.Add(new ValueLookupParameter<IntValue>(ValidationSamplesStartParameterName, "The first index of the validation partition of the data set."));
157      Parameters.Add(new ValueLookupParameter<IntValue>(ValidationSamplesEndParameterName, "The last index of the validation partition of the data set."));
158      Parameters.Add(new ValueLookupParameter<IntValue>(TestSamplesStartParameterName, "The first index of the test partition of the data set."));
159      Parameters.Add(new ValueLookupParameter<IntValue>(TestSamplesEndParameterName, "The last index of the test partition of the data set."));
160      Parameters.Add(new ValueLookupParameter<DoubleValue>(UpperEstimationLimitParameterName, "The upper estimation limit that was set for the evaluation of the symbolic expression trees."));
161      Parameters.Add(new ValueLookupParameter<DoubleValue>(LowerEstimationLimitParameterName, "The lower estimation limit that was set for the evaluation of the symbolic expression trees."));
162      Parameters.Add(new LookupParameter<SymbolicRegressionSolution>(BestSolutionParameterName, "The best symbolic regression solution."));
163      Parameters.Add(new LookupParameter<DoubleValue>(BestSolutionQualityParameterName, "The quality of the best symbolic regression solution."));
164      Parameters.Add(new LookupParameter<ResultCollection>(ResultsParameterName, "The result collection where the best symbolic regression solution should be stored."));
165      Parameters.Add(new LookupParameter<DoubleValue>(BestKnownQualityParameterName, "The best known (validation) quality achieved on the data set."));
166
167      #region operator initialization
168      subScopesProcessor = new UniformSubScopesProcessor();
169      linearScaler = new SymbolicRegressionSolutionLinearScaler();
170      modelQualityAnalyzer = new SymbolicRegressionModelQualityAnalyzer();
171      validationMseEvaluator = new SymbolicRegressionMeanSquaredErrorEvaluator();
172      bestSolutionAnalyzer = new BestSymbolicRegressionSolutionAnalyzer();
173      cleaningSubScopesProcessor = new UniformSubScopesProcessor();
174      removeScaledExpressionTreeAssigner = new Assigner();
175      bestKnownQualityMemorizer = new BestQualityMemorizer();
176      bestAvgWorstValidationQualityCalculator = new BestAverageWorstQualityCalculator();
177      validationValuesCollector = new DataTableValuesCollector();
178      resultsCollector = new ResultsCollector();
179      #endregion
180
181      #region parameter wiring
182      subScopesProcessor.Depth.Value = SymbolicExpressionTreeParameter.Depth;
183
184      linearScaler.AlphaParameter.ActualName = AlphaParameterName;
185      linearScaler.BetaParameter.ActualName = BetaParameterName;
186      linearScaler.SymbolicExpressionTreeParameter.ActualName = SymbolicExpressionTreeParameter.Name;
187      linearScaler.ScaledSymbolicExpressionTreeParameter.ActualName = ScaledSymbolicExpressionTreeParameterName;
188
189      modelQualityAnalyzer.ProblemDataParameter.ActualName = ProblemDataParameter.Name;
190      modelQualityAnalyzer.SymbolicExpressionTreeParameter.ActualName = ScaledSymbolicExpressionTreeParameterName;
191      modelQualityAnalyzer.SymbolicExpressionTreeParameter.Depth = SymbolicExpressionTreeParameter.Depth;
192      modelQualityAnalyzer.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameter.Name;
193      modelQualityAnalyzer.LowerEstimationLimitParameter.ActualName = LowerEstimationLimitParameter.Name;
194      modelQualityAnalyzer.SymbolicExpressionTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
195
196      validationMseEvaluator.LowerEstimationLimitParameter.ActualName = LowerEstimationLimitParameter.Name;
197      validationMseEvaluator.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameter.Name;
198      validationMseEvaluator.SymbolicExpressionTreeParameter.ActualName = ScaledSymbolicExpressionTreeParameterName;
199      validationMseEvaluator.SymbolicExpressionTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
200      validationMseEvaluator.QualityParameter.ActualName = ScaledQualityParameterName;
201      validationMseEvaluator.RegressionProblemDataParameter.ActualName = ProblemDataParameter.Name;
202      validationMseEvaluator.SamplesStartParameter.ActualName = ValidationSamplesStartParameter.Name;
203      validationMseEvaluator.SamplesEndParameter.ActualName = ValidationSamplesEndParameter.Name;
204
205      bestSolutionAnalyzer.BestSolutionParameter.ActualName = BestSolutionParameter.Name;
206      bestSolutionAnalyzer.BestSolutionQualityParameter.ActualName = BestSolutionQualityParameter.Name;
207      bestSolutionAnalyzer.LowerEstimationLimitParameter.ActualName = LowerEstimationLimitParameter.Name;
208      bestSolutionAnalyzer.ProblemDataParameter.ActualName = ProblemDataParameter.Name;
209      bestSolutionAnalyzer.QualityParameter.ActualName = ScaledQualityParameterName;
210      bestSolutionAnalyzer.ResultsParameter.ActualName = ResultsParameter.Name;
211      bestSolutionAnalyzer.SymbolicExpressionTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
212      bestSolutionAnalyzer.SymbolicExpressionTreeParameter.ActualName = ScaledSymbolicExpressionTreeParameterName;
213      bestSolutionAnalyzer.SymbolicExpressionTreeParameter.Depth = SymbolicExpressionTreeParameter.Depth;
214      bestSolutionAnalyzer.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameter.Name;
215
216      cleaningSubScopesProcessor.Depth.Value = SymbolicExpressionTreeParameter.Depth;
217
218      removeScaledExpressionTreeAssigner.LeftSideParameter.ActualName = ScaledSymbolicExpressionTreeParameterName;
219      removeScaledExpressionTreeAssigner.RightSideParameter.Value = new SymbolicExpressionTree();
220
221      bestAvgWorstValidationQualityCalculator.AverageQualityParameter.ActualName = "Current average validation quality";
222      bestAvgWorstValidationQualityCalculator.BestQualityParameter.ActualName = CurrentBestValidationQualityParameterName;
223      bestAvgWorstValidationQualityCalculator.MaximizationParameter.Value = new BoolValue(false);
224      bestAvgWorstValidationQualityCalculator.QualityParameter.ActualName = ScaledQualityParameterName;
225      bestAvgWorstValidationQualityCalculator.QualityParameter.Depth = SymbolicExpressionTreeParameter.Depth;
226      bestAvgWorstValidationQualityCalculator.WorstQualityParameter.ActualName = "Current worst validation quality";
227
228      bestKnownQualityMemorizer.BestQualityParameter.ActualName = BestKnownQualityParameterName;
229      bestKnownQualityMemorizer.MaximizationParameter.Value = new BoolValue(false);
230      bestKnownQualityMemorizer.QualityParameter.ActualName = QualityParameter.Name;
231      bestKnownQualityMemorizer.QualityParameter.Depth = QualityParameter.Depth;
232
233      validationValuesCollector.DataTableParameter.ActualName = "Validation quality";
234      validationValuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(CurrentBestValidationQualityParameterName, null, CurrentBestValidationQualityParameterName));
235      validationValuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(BestSolutionQualityParameter.Name, null, BestSolutionQualityParameter.Name));
236
237      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(CurrentBestValidationQualityParameterName, null, CurrentBestValidationQualityParameterName));
238      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(BestSolutionQualityParameter.Name, null, BestSolutionQualityParameter.Name));
239      resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>("Validation quality"));
240      resultsCollector.ResultsParameter.ActualName = ResultsParameter.Name;
241      #endregion
242
243      #region operator graph
244      OperatorGraph.InitialOperator = subScopesProcessor;
245      subScopesProcessor.Operator = linearScaler;
246      linearScaler.Successor = validationMseEvaluator;
247      validationMseEvaluator.Successor = null;
248      subScopesProcessor.Successor = modelQualityAnalyzer;
249      modelQualityAnalyzer.Successor = bestSolutionAnalyzer;
250      bestSolutionAnalyzer.Successor = cleaningSubScopesProcessor;
251      cleaningSubScopesProcessor.Operator = removeScaledExpressionTreeAssigner;
252      cleaningSubScopesProcessor.Successor = bestAvgWorstValidationQualityCalculator;
253      bestAvgWorstValidationQualityCalculator.Successor = bestKnownQualityMemorizer;
254      bestKnownQualityMemorizer.Successor = validationValuesCollector;
255      validationValuesCollector.Successor = resultsCollector;
256      resultsCollector.Successor = null;
257      #endregion
258
259      Initialize();
260    }
261
262    public override IDeepCloneable Clone(Cloner cloner) {
263      return new ValidationBestScaledSymbolicRegressionSolutionAnalyzer(this, cloner);
264    }
265
266    [StorableHook(HookType.AfterDeserialization)]
267    private void AfterDeserialization() {
268      Initialize();
269    }
270    private void Initialize() {
271      SymbolicExpressionTreeParameter.DepthChanged += new EventHandler(SymbolicExpressionTreeParameter_DepthChanged);
272    }
273
274
275    private void SymbolicExpressionTreeParameter_DepthChanged(object sender, EventArgs e) {
276      subScopesProcessor.Depth.Value = SymbolicExpressionTreeParameter.Depth;
277      cleaningSubScopesProcessor.Depth.Value = SymbolicExpressionTreeParameter.Depth;
278      bestSolutionAnalyzer.SymbolicExpressionTreeParameter.Depth = SymbolicExpressionTreeParameter.Depth;
279      bestSolutionAnalyzer.QualityParameter.Depth = SymbolicExpressionTreeParameter.Depth;
280      bestAvgWorstValidationQualityCalculator.QualityParameter.Depth = SymbolicExpressionTreeParameter.Depth;
281      bestKnownQualityMemorizer.QualityParameter.Depth = SymbolicExpressionTreeParameter.Depth;
282      modelQualityAnalyzer.SymbolicExpressionTreeParameter.Depth = SymbolicExpressionTreeParameter.Depth;
283    }
284  }
285}
Note: See TracBrowser for help on using the repository browser.