Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/ValidationBestScaledSymbolicRegressionSolutionAnalyzer.cs @ 12467

Last change on this file since 12467 was 5275, checked in by gkronber, 14 years ago

Merged changes from trunk to data analysis exploration branch and added fractional distance metric evaluator. #1142

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