Free cookie consent management tool by TermsFeed Policy Generator

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

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

Preparation for cross validation - removed the test samples from the trainining samples and added ValidationPercentage parameter (ticket #1199).

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