Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 4195 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

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