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
RevLine 
[3651]1#region License Information
2/* HeuristicLab
[5445]3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[3651]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;
[5863]33using HeuristicLab.PluginInfrastructure;
[3651]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>
[3681]40  [Item("ValidationBestScaledSymbolicRegressionSolutionAnalyzer", "An operator that analyzes the validation best scaled symbolic regression solution.")]
[3651]41  [StorableClass]
[5863]42  [NonDiscoverableType]
[3681]43  public sealed class ValidationBestScaledSymbolicRegressionSolutionAnalyzer : AlgorithmOperator, ISymbolicRegressionAnalyzer {
[3651]44    private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
45    private const string ScaledSymbolicExpressionTreeParameterName = "ScaledSymbolicExpressionTree";
46    private const string SymbolicExpressionTreeInterpreterParameterName = "SymbolicExpressionTreeInterpreter";
47    private const string ProblemDataParameterName = "ProblemData";
[3806]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";
[3800]54    private const string QualityParameterName = "Quality";
55    private const string ScaledQualityParameterName = "ScaledQuality";
[3651]56    private const string UpperEstimationLimitParameterName = "UpperEstimationLimit";
57    private const string LowerEstimationLimitParameterName = "LowerEstimationLimit";
58    private const string AlphaParameterName = "Alpha";
59    private const string BetaParameterName = "Beta";
[3710]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";
[3651]63    private const string ResultsParameterName = "Results";
[3790]64    private const string BestKnownQualityParameterName = "BestKnownQuality";
[3651]65
[3681]66    public ScopeTreeLookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter {
67      get { return (ScopeTreeLookupParameter<SymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
[3651]68    }
[3800]69    public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
70      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters[QualityParameterName]; }
71    }
[3681]72    public IValueLookupParameter<ISymbolicExpressionTreeInterpreter> SymbolicExpressionTreeInterpreterParameter {
73      get { return (IValueLookupParameter<ISymbolicExpressionTreeInterpreter>)Parameters[SymbolicExpressionTreeInterpreterParameterName]; }
[3651]74    }
[3681]75    public IValueLookupParameter<DataAnalysisProblemData> ProblemDataParameter {
76      get { return (IValueLookupParameter<DataAnalysisProblemData>)Parameters[ProblemDataParameterName]; }
[3651]77    }
[3806]78    public IValueLookupParameter<IntValue> TrainingSamplesStartParameter {
79      get { return (IValueLookupParameter<IntValue>)Parameters[TrainingSamplesStartParameterName]; }
[3651]80    }
[3806]81    public IValueLookupParameter<IntValue> TrainingSamplesEndParameter {
82      get { return (IValueLookupParameter<IntValue>)Parameters[TrainingSamplesEndParameterName]; }
[3651]83    }
[3806]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    }
[3681]96    public IValueLookupParameter<DoubleValue> UpperEstimationLimitParameter {
97      get { return (IValueLookupParameter<DoubleValue>)Parameters[UpperEstimationLimitParameterName]; }
[3651]98    }
[3681]99    public IValueLookupParameter<DoubleValue> LowerEstimationLimitParameter {
100      get { return (IValueLookupParameter<DoubleValue>)Parameters[LowerEstimationLimitParameterName]; }
[3651]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    }
[3790]111    public ILookupParameter<DoubleValue> BestKnownQualityParameter {
112      get { return (ILookupParameter<DoubleValue>)Parameters[BestKnownQualityParameterName]; }
113    }
[3651]114
[3681]115    [Storable]
[3926]116    private UniformSubScopesProcessor subScopesProcessor;
117    [Storable]
118    private SymbolicRegressionSolutionLinearScaler linearScaler;
119    [Storable]
120    private SymbolicRegressionModelQualityAnalyzer modelQualityAnalyzer;
121    [Storable]
122    private SymbolicRegressionMeanSquaredErrorEvaluator validationMseEvaluator;
123    [Storable]
[3681]124    private BestSymbolicRegressionSolutionAnalyzer bestSolutionAnalyzer;
[3683]125    [Storable]
[3926]126    private UniformSubScopesProcessor cleaningSubScopesProcessor;
[3683]127    [Storable]
[3926]128    private Assigner removeScaledExpressionTreeAssigner;
[3800]129    [Storable]
130    private BestQualityMemorizer bestKnownQualityMemorizer;
[3806]131    [Storable]
[3926]132    private BestAverageWorstQualityCalculator bestAvgWorstValidationQualityCalculator;
133    [Storable]
134    private DataTableValuesCollector validationValuesCollector;
135    [Storable]
136    private ResultsCollector resultsCollector;
[3681]137
[4722]138    [StorableConstructor]
139    private ValidationBestScaledSymbolicRegressionSolutionAnalyzer(bool deserializing) : base(deserializing) { }
140    private ValidationBestScaledSymbolicRegressionSolutionAnalyzer(ValidationBestScaledSymbolicRegressionSolutionAnalyzer original, Cloner cloner)
141      : base(original, cloner) {
142      Initialize();
143    }
[3681]144    public ValidationBestScaledSymbolicRegressionSolutionAnalyzer()
[3651]145      : base() {
[3659]146      Parameters.Add(new ScopeTreeLookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression trees to analyze."));
[3800]147      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>(QualityParameterName, "The quality of the symbolic expression trees to analyze."));
[3681]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."));
[3806]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."));
[3681]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."));
[3651]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."));
[3790]161      Parameters.Add(new LookupParameter<DoubleValue>(BestKnownQualityParameterName, "The best known (validation) quality achieved on the data set."));
[3651]162
163      #region operator initialization
[3710]164      subScopesProcessor = new UniformSubScopesProcessor();
[3926]165      linearScaler = new SymbolicRegressionSolutionLinearScaler();
[3806]166      modelQualityAnalyzer = new SymbolicRegressionModelQualityAnalyzer();
[3926]167      validationMseEvaluator = new SymbolicRegressionMeanSquaredErrorEvaluator();
[3681]168      bestSolutionAnalyzer = new BestSymbolicRegressionSolutionAnalyzer();
[3926]169      cleaningSubScopesProcessor = new UniformSubScopesProcessor();
170      removeScaledExpressionTreeAssigner = new Assigner();
[3800]171      bestKnownQualityMemorizer = new BestQualityMemorizer();
172      bestAvgWorstValidationQualityCalculator = new BestAverageWorstQualityCalculator();
[3926]173      validationValuesCollector = new DataTableValuesCollector();
174      resultsCollector = new ResultsCollector();
[3651]175      #endregion
176
177      #region parameter wiring
[3710]178      subScopesProcessor.Depth.Value = SymbolicExpressionTreeParameter.Depth;
179
[3651]180      linearScaler.AlphaParameter.ActualName = AlphaParameterName;
181      linearScaler.BetaParameter.ActualName = BetaParameterName;
[3681]182      linearScaler.SymbolicExpressionTreeParameter.ActualName = SymbolicExpressionTreeParameter.Name;
[3651]183      linearScaler.ScaledSymbolicExpressionTreeParameter.ActualName = ScaledSymbolicExpressionTreeParameterName;
184
[3806]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
[3710]192      validationMseEvaluator.LowerEstimationLimitParameter.ActualName = LowerEstimationLimitParameter.Name;
193      validationMseEvaluator.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameter.Name;
194      validationMseEvaluator.SymbolicExpressionTreeParameter.ActualName = ScaledSymbolicExpressionTreeParameterName;
195      validationMseEvaluator.SymbolicExpressionTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
[3800]196      validationMseEvaluator.QualityParameter.ActualName = ScaledQualityParameterName;
[3710]197      validationMseEvaluator.RegressionProblemDataParameter.ActualName = ProblemDataParameter.Name;
[3806]198      validationMseEvaluator.SamplesStartParameter.ActualName = ValidationSamplesStartParameter.Name;
199      validationMseEvaluator.SamplesEndParameter.ActualName = ValidationSamplesEndParameter.Name;
[3651]200
[3681]201      bestSolutionAnalyzer.BestSolutionParameter.ActualName = BestSolutionParameter.Name;
202      bestSolutionAnalyzer.BestSolutionQualityParameter.ActualName = BestSolutionQualityParameter.Name;
203      bestSolutionAnalyzer.LowerEstimationLimitParameter.ActualName = LowerEstimationLimitParameter.Name;
204      bestSolutionAnalyzer.ProblemDataParameter.ActualName = ProblemDataParameter.Name;
[3800]205      bestSolutionAnalyzer.QualityParameter.ActualName = ScaledQualityParameterName;
[3681]206      bestSolutionAnalyzer.ResultsParameter.ActualName = ResultsParameter.Name;
207      bestSolutionAnalyzer.SymbolicExpressionTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
[3651]208      bestSolutionAnalyzer.SymbolicExpressionTreeParameter.ActualName = ScaledSymbolicExpressionTreeParameterName;
[3681]209      bestSolutionAnalyzer.SymbolicExpressionTreeParameter.Depth = SymbolicExpressionTreeParameter.Depth;
210      bestSolutionAnalyzer.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameter.Name;
211
[3926]212      cleaningSubScopesProcessor.Depth.Value = SymbolicExpressionTreeParameter.Depth;
213
214      removeScaledExpressionTreeAssigner.LeftSideParameter.ActualName = ScaledSymbolicExpressionTreeParameterName;
215      removeScaledExpressionTreeAssigner.RightSideParameter.Value = new SymbolicExpressionTree();
216
[3710]217      bestAvgWorstValidationQualityCalculator.AverageQualityParameter.ActualName = "Current average validation quality";
218      bestAvgWorstValidationQualityCalculator.BestQualityParameter.ActualName = CurrentBestValidationQualityParameterName;
[3681]219      bestAvgWorstValidationQualityCalculator.MaximizationParameter.Value = new BoolValue(false);
[3800]220      bestAvgWorstValidationQualityCalculator.QualityParameter.ActualName = ScaledQualityParameterName;
[3710]221      bestAvgWorstValidationQualityCalculator.QualityParameter.Depth = SymbolicExpressionTreeParameter.Depth;
222      bestAvgWorstValidationQualityCalculator.WorstQualityParameter.ActualName = "Current worst validation quality";
[3681]223
[3790]224      bestKnownQualityMemorizer.BestQualityParameter.ActualName = BestKnownQualityParameterName;
225      bestKnownQualityMemorizer.MaximizationParameter.Value = new BoolValue(false);
[3800]226      bestKnownQualityMemorizer.QualityParameter.ActualName = QualityParameter.Name;
227      bestKnownQualityMemorizer.QualityParameter.Depth = QualityParameter.Depth;
[3790]228
[3710]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));
[3681]232
[3710]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"));
[3681]236      resultsCollector.ResultsParameter.ActualName = ResultsParameter.Name;
[3651]237      #endregion
238
239      #region operator graph
[3710]240      OperatorGraph.InitialOperator = subScopesProcessor;
241      subScopesProcessor.Operator = linearScaler;
242      linearScaler.Successor = validationMseEvaluator;
243      validationMseEvaluator.Successor = null;
[3806]244      subScopesProcessor.Successor = modelQualityAnalyzer;
245      modelQualityAnalyzer.Successor = bestSolutionAnalyzer;
[3926]246      bestSolutionAnalyzer.Successor = cleaningSubScopesProcessor;
247      cleaningSubScopesProcessor.Operator = removeScaledExpressionTreeAssigner;
248      cleaningSubScopesProcessor.Successor = bestAvgWorstValidationQualityCalculator;
[3790]249      bestAvgWorstValidationQualityCalculator.Successor = bestKnownQualityMemorizer;
250      bestKnownQualityMemorizer.Successor = validationValuesCollector;
[3681]251      validationValuesCollector.Successor = resultsCollector;
252      resultsCollector.Successor = null;
[3651]253      #endregion
[3681]254
255      Initialize();
[3651]256    }
[3681]257
[4722]258    public override IDeepCloneable Clone(Cloner cloner) {
259      return new ValidationBestScaledSymbolicRegressionSolutionAnalyzer(this, cloner);
260    }
[3681]261
262    [StorableHook(HookType.AfterDeserialization)]
[4722]263    private void AfterDeserialization() {
264      Initialize();
265    }
[3681]266    private void Initialize() {
267      SymbolicExpressionTreeParameter.DepthChanged += new EventHandler(SymbolicExpressionTreeParameter_DepthChanged);
268    }
269
270
271    private void SymbolicExpressionTreeParameter_DepthChanged(object sender, EventArgs e) {
[3710]272      subScopesProcessor.Depth.Value = SymbolicExpressionTreeParameter.Depth;
[3926]273      cleaningSubScopesProcessor.Depth.Value = SymbolicExpressionTreeParameter.Depth;
[3681]274      bestSolutionAnalyzer.SymbolicExpressionTreeParameter.Depth = SymbolicExpressionTreeParameter.Depth;
[3683]275      bestSolutionAnalyzer.QualityParameter.Depth = SymbolicExpressionTreeParameter.Depth;
[3710]276      bestAvgWorstValidationQualityCalculator.QualityParameter.Depth = SymbolicExpressionTreeParameter.Depth;
[3800]277      bestKnownQualityMemorizer.QualityParameter.Depth = SymbolicExpressionTreeParameter.Depth;
[3806]278      modelQualityAnalyzer.SymbolicExpressionTreeParameter.Depth = SymbolicExpressionTreeParameter.Depth;
[3681]279    }
[3651]280  }
281}
Note: See TracBrowser for help on using the repository browser.