Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 4054 was 4054, checked in by mkommend, 14 years ago

improved Analyzers for SymoblicRegressionProblems (ticket #1074)

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