Free cookie consent management tool by TermsFeed Policy Generator

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

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

removed ScaledSymbolicExpressionTree from the scopes in the ValidationBestScaledSymbolicReressionSolutionAnalyzer and
made SymbolicExpressionTree to work without a root node (ticket #938)

File size: 18.8 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      modelQualityAnalyzer.TrainingSamplesStartParameter.ActualName = TrainingSamplesStartParameter.Name;
189      modelQualityAnalyzer.TrainingSamplesEndParameter.ActualName = TrainingSamplesEndParameter.Name;
190      modelQualityAnalyzer.TestSamplesStartParameter.ActualName = TestSamplesStartParameter.Name;
191      modelQualityAnalyzer.TestSamplesEndParameter.ActualName = TestSamplesEndParameter.Name;
192
193      validationMseEvaluator.LowerEstimationLimitParameter.ActualName = LowerEstimationLimitParameter.Name;
194      validationMseEvaluator.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameter.Name;
195      validationMseEvaluator.SymbolicExpressionTreeParameter.ActualName = ScaledSymbolicExpressionTreeParameterName;
196      validationMseEvaluator.SymbolicExpressionTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
197      validationMseEvaluator.QualityParameter.ActualName = ScaledQualityParameterName;
198      validationMseEvaluator.RegressionProblemDataParameter.ActualName = ProblemDataParameter.Name;
199      validationMseEvaluator.SamplesStartParameter.ActualName = ValidationSamplesStartParameter.Name;
200      validationMseEvaluator.SamplesEndParameter.ActualName = ValidationSamplesEndParameter.Name;
201
202      bestSolutionAnalyzer.BestSolutionParameter.ActualName = BestSolutionParameter.Name;
203      bestSolutionAnalyzer.BestSolutionQualityParameter.ActualName = BestSolutionQualityParameter.Name;
204      bestSolutionAnalyzer.LowerEstimationLimitParameter.ActualName = LowerEstimationLimitParameter.Name;
205      bestSolutionAnalyzer.ProblemDataParameter.ActualName = ProblemDataParameter.Name;
206      bestSolutionAnalyzer.QualityParameter.ActualName = ScaledQualityParameterName;
207      bestSolutionAnalyzer.ResultsParameter.ActualName = ResultsParameter.Name;
208      bestSolutionAnalyzer.SymbolicExpressionTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
209      bestSolutionAnalyzer.SymbolicExpressionTreeParameter.ActualName = ScaledSymbolicExpressionTreeParameterName;
210      bestSolutionAnalyzer.SymbolicExpressionTreeParameter.Depth = SymbolicExpressionTreeParameter.Depth;
211      bestSolutionAnalyzer.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameter.Name;
212
213      cleaningSubScopesProcessor.Depth.Value = SymbolicExpressionTreeParameter.Depth;
214
215      removeScaledExpressionTreeAssigner.LeftSideParameter.ActualName = ScaledSymbolicExpressionTreeParameterName;
216      removeScaledExpressionTreeAssigner.RightSideParameter.Value = new SymbolicExpressionTree();
217
218      bestAvgWorstValidationQualityCalculator.AverageQualityParameter.ActualName = "Current average validation quality";
219      bestAvgWorstValidationQualityCalculator.BestQualityParameter.ActualName = CurrentBestValidationQualityParameterName;
220      bestAvgWorstValidationQualityCalculator.MaximizationParameter.Value = new BoolValue(false);
221      bestAvgWorstValidationQualityCalculator.QualityParameter.ActualName = ScaledQualityParameterName;
222      bestAvgWorstValidationQualityCalculator.QualityParameter.Depth = SymbolicExpressionTreeParameter.Depth;
223      bestAvgWorstValidationQualityCalculator.WorstQualityParameter.ActualName = "Current worst validation quality";
224
225      bestKnownQualityMemorizer.BestQualityParameter.ActualName = BestKnownQualityParameterName;
226      bestKnownQualityMemorizer.MaximizationParameter.Value = new BoolValue(false);
227      bestKnownQualityMemorizer.QualityParameter.ActualName = QualityParameter.Name;
228      bestKnownQualityMemorizer.QualityParameter.Depth = QualityParameter.Depth;
229
230      validationValuesCollector.DataTableParameter.ActualName = "Validation quality";
231      validationValuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(CurrentBestValidationQualityParameterName, null, CurrentBestValidationQualityParameterName));
232      validationValuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(BestSolutionQualityParameter.Name, null, BestSolutionQualityParameter.Name));
233
234      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(CurrentBestValidationQualityParameterName, null, CurrentBestValidationQualityParameterName));
235      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(BestSolutionQualityParameter.Name, null, BestSolutionQualityParameter.Name));
236      resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>("Validation quality"));
237      resultsCollector.ResultsParameter.ActualName = ResultsParameter.Name;
238      #endregion
239
240      #region operator graph
241      OperatorGraph.InitialOperator = subScopesProcessor;
242      subScopesProcessor.Operator = linearScaler;
243      linearScaler.Successor = validationMseEvaluator;
244      validationMseEvaluator.Successor = null;
245      subScopesProcessor.Successor = modelQualityAnalyzer;
246      modelQualityAnalyzer.Successor = bestSolutionAnalyzer;
247      bestSolutionAnalyzer.Successor = cleaningSubScopesProcessor;
248      cleaningSubScopesProcessor.Operator = removeScaledExpressionTreeAssigner;
249      cleaningSubScopesProcessor.Successor = bestAvgWorstValidationQualityCalculator;
250      bestAvgWorstValidationQualityCalculator.Successor = bestKnownQualityMemorizer;
251      bestKnownQualityMemorizer.Successor = validationValuesCollector;
252      validationValuesCollector.Successor = resultsCollector;
253      resultsCollector.Successor = null;
254      #endregion
255
256      Initialize();
257    }
258
259    [StorableConstructor]
260    private ValidationBestScaledSymbolicRegressionSolutionAnalyzer(bool deserializing) : base() { }
261
262    [StorableHook(HookType.AfterDeserialization)]
263    private void Initialize() {
264      SymbolicExpressionTreeParameter.DepthChanged += new EventHandler(SymbolicExpressionTreeParameter_DepthChanged);
265    }
266
267    public override IDeepCloneable Clone(Cloner cloner) {
268      ValidationBestScaledSymbolicRegressionSolutionAnalyzer clone = (ValidationBestScaledSymbolicRegressionSolutionAnalyzer)base.Clone(cloner);
269      clone.Initialize();
270      return clone;
271    }
272
273    private void SymbolicExpressionTreeParameter_DepthChanged(object sender, EventArgs e) {
274      subScopesProcessor.Depth.Value = SymbolicExpressionTreeParameter.Depth;
275      cleaningSubScopesProcessor.Depth.Value = SymbolicExpressionTreeParameter.Depth;
276      bestSolutionAnalyzer.SymbolicExpressionTreeParameter.Depth = SymbolicExpressionTreeParameter.Depth;
277      bestSolutionAnalyzer.QualityParameter.Depth = SymbolicExpressionTreeParameter.Depth;
278      bestAvgWorstValidationQualityCalculator.QualityParameter.Depth = SymbolicExpressionTreeParameter.Depth;
279      bestKnownQualityMemorizer.QualityParameter.Depth = SymbolicExpressionTreeParameter.Depth;
280      modelQualityAnalyzer.SymbolicExpressionTreeParameter.Depth = SymbolicExpressionTreeParameter.Depth;
281    }
282  }
283}
Note: See TracBrowser for help on using the repository browser.