Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1418: Added NonDiscoverableType attribute to outdated analyzers.

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