Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 5313 was 4722, checked in by swagner, 14 years ago

Merged cloning refactoring branch back into trunk (#922)

File size: 18.5 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
[4722]137    [StorableConstructor]
138    private ValidationBestScaledSymbolicRegressionSolutionAnalyzer(bool deserializing) : base(deserializing) { }
139    private ValidationBestScaledSymbolicRegressionSolutionAnalyzer(ValidationBestScaledSymbolicRegressionSolutionAnalyzer original, Cloner cloner)
140      : base(original, cloner) {
141      Initialize();
142    }
[3681]143    public ValidationBestScaledSymbolicRegressionSolutionAnalyzer()
[3651]144      : base() {
[3659]145      Parameters.Add(new ScopeTreeLookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression trees to analyze."));
[3800]146      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>(QualityParameterName, "The quality of the symbolic expression trees to analyze."));
[3681]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."));
[3806]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."));
[3681]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."));
[3651]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."));
[3790]160      Parameters.Add(new LookupParameter<DoubleValue>(BestKnownQualityParameterName, "The best known (validation) quality achieved on the data set."));
[3651]161
162      #region operator initialization
[3710]163      subScopesProcessor = new UniformSubScopesProcessor();
[3926]164      linearScaler = new SymbolicRegressionSolutionLinearScaler();
[3806]165      modelQualityAnalyzer = new SymbolicRegressionModelQualityAnalyzer();
[3926]166      validationMseEvaluator = new SymbolicRegressionMeanSquaredErrorEvaluator();
[3681]167      bestSolutionAnalyzer = new BestSymbolicRegressionSolutionAnalyzer();
[3926]168      cleaningSubScopesProcessor = new UniformSubScopesProcessor();
169      removeScaledExpressionTreeAssigner = new Assigner();
[3800]170      bestKnownQualityMemorizer = new BestQualityMemorizer();
171      bestAvgWorstValidationQualityCalculator = new BestAverageWorstQualityCalculator();
[3926]172      validationValuesCollector = new DataTableValuesCollector();
173      resultsCollector = new ResultsCollector();
[3651]174      #endregion
175
176      #region parameter wiring
[3710]177      subScopesProcessor.Depth.Value = SymbolicExpressionTreeParameter.Depth;
178
[3651]179      linearScaler.AlphaParameter.ActualName = AlphaParameterName;
180      linearScaler.BetaParameter.ActualName = BetaParameterName;
[3681]181      linearScaler.SymbolicExpressionTreeParameter.ActualName = SymbolicExpressionTreeParameter.Name;
[3651]182      linearScaler.ScaledSymbolicExpressionTreeParameter.ActualName = ScaledSymbolicExpressionTreeParameterName;
183
[3806]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
[3710]191      validationMseEvaluator.LowerEstimationLimitParameter.ActualName = LowerEstimationLimitParameter.Name;
192      validationMseEvaluator.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameter.Name;
193      validationMseEvaluator.SymbolicExpressionTreeParameter.ActualName = ScaledSymbolicExpressionTreeParameterName;
194      validationMseEvaluator.SymbolicExpressionTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
[3800]195      validationMseEvaluator.QualityParameter.ActualName = ScaledQualityParameterName;
[3710]196      validationMseEvaluator.RegressionProblemDataParameter.ActualName = ProblemDataParameter.Name;
[3806]197      validationMseEvaluator.SamplesStartParameter.ActualName = ValidationSamplesStartParameter.Name;
198      validationMseEvaluator.SamplesEndParameter.ActualName = ValidationSamplesEndParameter.Name;
[3651]199
[3681]200      bestSolutionAnalyzer.BestSolutionParameter.ActualName = BestSolutionParameter.Name;
201      bestSolutionAnalyzer.BestSolutionQualityParameter.ActualName = BestSolutionQualityParameter.Name;
202      bestSolutionAnalyzer.LowerEstimationLimitParameter.ActualName = LowerEstimationLimitParameter.Name;
203      bestSolutionAnalyzer.ProblemDataParameter.ActualName = ProblemDataParameter.Name;
[3800]204      bestSolutionAnalyzer.QualityParameter.ActualName = ScaledQualityParameterName;
[3681]205      bestSolutionAnalyzer.ResultsParameter.ActualName = ResultsParameter.Name;
206      bestSolutionAnalyzer.SymbolicExpressionTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
[3651]207      bestSolutionAnalyzer.SymbolicExpressionTreeParameter.ActualName = ScaledSymbolicExpressionTreeParameterName;
[3681]208      bestSolutionAnalyzer.SymbolicExpressionTreeParameter.Depth = SymbolicExpressionTreeParameter.Depth;
209      bestSolutionAnalyzer.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameter.Name;
210
[3926]211      cleaningSubScopesProcessor.Depth.Value = SymbolicExpressionTreeParameter.Depth;
212
213      removeScaledExpressionTreeAssigner.LeftSideParameter.ActualName = ScaledSymbolicExpressionTreeParameterName;
214      removeScaledExpressionTreeAssigner.RightSideParameter.Value = new SymbolicExpressionTree();
215
[3710]216      bestAvgWorstValidationQualityCalculator.AverageQualityParameter.ActualName = "Current average validation quality";
217      bestAvgWorstValidationQualityCalculator.BestQualityParameter.ActualName = CurrentBestValidationQualityParameterName;
[3681]218      bestAvgWorstValidationQualityCalculator.MaximizationParameter.Value = new BoolValue(false);
[3800]219      bestAvgWorstValidationQualityCalculator.QualityParameter.ActualName = ScaledQualityParameterName;
[3710]220      bestAvgWorstValidationQualityCalculator.QualityParameter.Depth = SymbolicExpressionTreeParameter.Depth;
221      bestAvgWorstValidationQualityCalculator.WorstQualityParameter.ActualName = "Current worst validation quality";
[3681]222
[3790]223      bestKnownQualityMemorizer.BestQualityParameter.ActualName = BestKnownQualityParameterName;
224      bestKnownQualityMemorizer.MaximizationParameter.Value = new BoolValue(false);
[3800]225      bestKnownQualityMemorizer.QualityParameter.ActualName = QualityParameter.Name;
226      bestKnownQualityMemorizer.QualityParameter.Depth = QualityParameter.Depth;
[3790]227
[3710]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));
[3681]231
[3710]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"));
[3681]235      resultsCollector.ResultsParameter.ActualName = ResultsParameter.Name;
[3651]236      #endregion
237
238      #region operator graph
[3710]239      OperatorGraph.InitialOperator = subScopesProcessor;
240      subScopesProcessor.Operator = linearScaler;
241      linearScaler.Successor = validationMseEvaluator;
242      validationMseEvaluator.Successor = null;
[3806]243      subScopesProcessor.Successor = modelQualityAnalyzer;
244      modelQualityAnalyzer.Successor = bestSolutionAnalyzer;
[3926]245      bestSolutionAnalyzer.Successor = cleaningSubScopesProcessor;
246      cleaningSubScopesProcessor.Operator = removeScaledExpressionTreeAssigner;
247      cleaningSubScopesProcessor.Successor = bestAvgWorstValidationQualityCalculator;
[3790]248      bestAvgWorstValidationQualityCalculator.Successor = bestKnownQualityMemorizer;
249      bestKnownQualityMemorizer.Successor = validationValuesCollector;
[3681]250      validationValuesCollector.Successor = resultsCollector;
251      resultsCollector.Successor = null;
[3651]252      #endregion
[3681]253
254      Initialize();
[3651]255    }
[3681]256
[4722]257    public override IDeepCloneable Clone(Cloner cloner) {
258      return new ValidationBestScaledSymbolicRegressionSolutionAnalyzer(this, cloner);
259    }
[3681]260
261    [StorableHook(HookType.AfterDeserialization)]
[4722]262    private void AfterDeserialization() {
263      Initialize();
264    }
[3681]265    private void Initialize() {
266      SymbolicExpressionTreeParameter.DepthChanged += new EventHandler(SymbolicExpressionTreeParameter_DepthChanged);
267    }
268
269
270    private void SymbolicExpressionTreeParameter_DepthChanged(object sender, EventArgs e) {
[3710]271      subScopesProcessor.Depth.Value = SymbolicExpressionTreeParameter.Depth;
[3926]272      cleaningSubScopesProcessor.Depth.Value = SymbolicExpressionTreeParameter.Depth;
[3681]273      bestSolutionAnalyzer.SymbolicExpressionTreeParameter.Depth = SymbolicExpressionTreeParameter.Depth;
[3683]274      bestSolutionAnalyzer.QualityParameter.Depth = SymbolicExpressionTreeParameter.Depth;
[3710]275      bestAvgWorstValidationQualityCalculator.QualityParameter.Depth = SymbolicExpressionTreeParameter.Depth;
[3800]276      bestKnownQualityMemorizer.QualityParameter.Depth = SymbolicExpressionTreeParameter.Depth;
[3806]277      modelQualityAnalyzer.SymbolicExpressionTreeParameter.Depth = SymbolicExpressionTreeParameter.Depth;
[3681]278    }
[3651]279  }
280}
Note: See TracBrowser for help on using the repository browser.