Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionSolution.cs @ 8961

Last change on this file since 8961 was 8723, checked in by mkommend, 12 years ago

#1964: Added new results to symbolic classification and regression solutions. Additionally, the way results are calculated was refactored and unified.

File size: 9.2 KB
RevLine 
[5607]1#region License Information
2/* HeuristicLab
[7259]3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[5607]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
[8723]22using System.Linq;
[5607]23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
[5914]26using HeuristicLab.Optimization;
[5607]27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
[5624]29namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
[5607]30  /// <summary>
31  /// Represents a symbolic regression solution (model + data) and attributes of the solution like accuracy and complexity
32  /// </summary>
33  [StorableClass]
34  [Item(Name = "SymbolicRegressionSolution", Description = "Represents a symbolic regression solution (model + data) and attributes of the solution like accuracy and complexity.")]
[5717]35  public sealed class SymbolicRegressionSolution : RegressionSolution, ISymbolicRegressionSolution {
[5975]36    private const string ModelLengthResultName = "Model Length";
37    private const string ModelDepthResultName = "Model Depth";
[5736]38
[8723]39    private const string EstimationLimitsResultsResultName = "Estimation Limits Results";
40    private const string EstimationLimitsResultName = "Estimation Limits";
41    private const string TrainingUpperEstimationLimitHitsResultName = "Training Upper Estimation Limit Hits";
42    private const string TestLowerEstimationLimitHitsResultName = "Test Lower Estimation Limit Hits";
43    private const string TrainingLowerEstimationLimitHitsResultName = "Training Lower Estimation Limit Hits";
44    private const string TestUpperEstimationLimitHitsResultName = "Test Upper Estimation Limit Hits";
45    private const string TrainingNaNEvaluationsResultName = "Training NaN Evaluations";
46    private const string TestNaNEvaluationsResultName = "Test NaN Evaluations";
47
[5624]48    public new ISymbolicRegressionModel Model {
49      get { return (ISymbolicRegressionModel)base.Model; }
[5717]50      set { base.Model = value; }
[5607]51    }
[5624]52    ISymbolicDataAnalysisModel ISymbolicDataAnalysisSolution.Model {
53      get { return (ISymbolicDataAnalysisModel)base.Model; }
[5607]54    }
[5736]55    public int ModelLength {
56      get { return ((IntValue)this[ModelLengthResultName].Value).Value; }
57      private set { ((IntValue)this[ModelLengthResultName].Value).Value = value; }
58    }
[5607]59
[5736]60    public int ModelDepth {
61      get { return ((IntValue)this[ModelDepthResultName].Value).Value; }
62      private set { ((IntValue)this[ModelDepthResultName].Value).Value = value; }
63    }
64
[8723]65    private ResultCollection EstimationLimitsResultCollection {
66      get { return (ResultCollection)this[EstimationLimitsResultsResultName].Value; }
67    }
68    public DoubleLimit EstimationLimits {
69      get { return (DoubleLimit)EstimationLimitsResultCollection[EstimationLimitsResultName].Value; }
70    }
71
72    public int TrainingUpperEstimationLimitHits {
73      get { return ((IntValue)EstimationLimitsResultCollection[TrainingUpperEstimationLimitHitsResultName].Value).Value; }
74      private set { ((IntValue)EstimationLimitsResultCollection[TrainingUpperEstimationLimitHitsResultName].Value).Value = value; }
75    }
76    public int TestUpperEstimationLimitHits {
77      get { return ((IntValue)EstimationLimitsResultCollection[TestUpperEstimationLimitHitsResultName].Value).Value; }
78      private set { ((IntValue)EstimationLimitsResultCollection[TestUpperEstimationLimitHitsResultName].Value).Value = value; }
79    }
80    public int TrainingLowerEstimationLimitHits {
81      get { return ((IntValue)EstimationLimitsResultCollection[TrainingLowerEstimationLimitHitsResultName].Value).Value; }
82      private set { ((IntValue)EstimationLimitsResultCollection[TrainingLowerEstimationLimitHitsResultName].Value).Value = value; }
83    }
84    public int TestLowerEstimationLimitHits {
85      get { return ((IntValue)EstimationLimitsResultCollection[TestLowerEstimationLimitHitsResultName].Value).Value; }
86      private set { ((IntValue)EstimationLimitsResultCollection[TestLowerEstimationLimitHitsResultName].Value).Value = value; }
87    }
88    public int TrainingNaNEvaluations {
89      get { return ((IntValue)EstimationLimitsResultCollection[TrainingNaNEvaluationsResultName].Value).Value; }
90      private set { ((IntValue)EstimationLimitsResultCollection[TrainingNaNEvaluationsResultName].Value).Value = value; }
91    }
92    public int TestNaNEvaluations {
93      get { return ((IntValue)EstimationLimitsResultCollection[TestNaNEvaluationsResultName].Value).Value; }
94      private set { ((IntValue)EstimationLimitsResultCollection[TestNaNEvaluationsResultName].Value).Value = value; }
95    }
96
[5607]97    [StorableConstructor]
[5717]98    private SymbolicRegressionSolution(bool deserializing) : base(deserializing) { }
99    private SymbolicRegressionSolution(SymbolicRegressionSolution original, Cloner cloner)
[5607]100      : base(original, cloner) {
101    }
[5624]102    public SymbolicRegressionSolution(ISymbolicRegressionModel model, IRegressionProblemData problemData)
103      : base(model, problemData) {
[5736]104      Add(new Result(ModelLengthResultName, "Length of the symbolic regression model.", new IntValue()));
105      Add(new Result(ModelDepthResultName, "Depth of the symbolic regression model.", new IntValue()));
[8723]106
107      ResultCollection estimationLimitResults = new ResultCollection();
108      estimationLimitResults.Add(new Result(EstimationLimitsResultName, "", new DoubleLimit()));
109      estimationLimitResults.Add(new Result(TrainingUpperEstimationLimitHitsResultName, "", new IntValue()));
110      estimationLimitResults.Add(new Result(TestUpperEstimationLimitHitsResultName, "", new IntValue()));
111      estimationLimitResults.Add(new Result(TrainingLowerEstimationLimitHitsResultName, "", new IntValue()));
112      estimationLimitResults.Add(new Result(TestLowerEstimationLimitHitsResultName, "", new IntValue()));
113      estimationLimitResults.Add(new Result(TrainingNaNEvaluationsResultName, "", new IntValue()));
114      estimationLimitResults.Add(new Result(TestNaNEvaluationsResultName, "", new IntValue()));
115      Add(new Result(EstimationLimitsResultsResultName, "Results concerning the estimation limits of symbolic regression solution", estimationLimitResults));
116
[6588]117      RecalculateResults();
[5607]118    }
119
120    public override IDeepCloneable Clone(Cloner cloner) {
121      return new SymbolicRegressionSolution(this, cloner);
122    }
[5729]123
[8723]124    [StorableHook(HookType.AfterDeserialization)]
125    private void AfterDeserialization() {
126      if (!ContainsKey(EstimationLimitsResultsResultName)) {
127        ResultCollection estimationLimitResults = new ResultCollection();
128        estimationLimitResults.Add(new Result(EstimationLimitsResultName, "", new DoubleLimit()));
129        estimationLimitResults.Add(new Result(TrainingUpperEstimationLimitHitsResultName, "", new IntValue()));
130        estimationLimitResults.Add(new Result(TestUpperEstimationLimitHitsResultName, "", new IntValue()));
131        estimationLimitResults.Add(new Result(TrainingLowerEstimationLimitHitsResultName, "", new IntValue()));
132        estimationLimitResults.Add(new Result(TestLowerEstimationLimitHitsResultName, "", new IntValue()));
133        estimationLimitResults.Add(new Result(TrainingNaNEvaluationsResultName, "", new IntValue()));
134        estimationLimitResults.Add(new Result(TestNaNEvaluationsResultName, "", new IntValue()));
135        Add(new Result(EstimationLimitsResultsResultName, "Results concerning the estimation limits of symbolic regression solution", estimationLimitResults));
136        CalculateResults();
137      }
138    }
139
[6411]140    protected override void RecalculateResults() {
[6602]141      base.RecalculateResults();
[8723]142      CalculateResults();
143    }
144
145    private void CalculateResults() {
[5736]146      ModelLength = Model.SymbolicExpressionTree.Length;
147      ModelDepth = Model.SymbolicExpressionTree.Depth;
[8723]148
149      EstimationLimits.Lower = Model.LowerEstimationLimit;
150      EstimationLimits.Upper = Model.UpperEstimationLimit;
151
152      TrainingUpperEstimationLimitHits = EstimatedTrainingValues.Count(x => x.IsAlmost(Model.UpperEstimationLimit));
153      TestUpperEstimationLimitHits = EstimatedTestValues.Count(x => x.IsAlmost(Model.UpperEstimationLimit));
154      TrainingLowerEstimationLimitHits = EstimatedTrainingValues.Count(x => x.IsAlmost(Model.LowerEstimationLimit));
155      TestLowerEstimationLimitHits = EstimatedTestValues.Count(x => x.IsAlmost(Model.LowerEstimationLimit));
156      TrainingNaNEvaluations = Model.Interpreter.GetSymbolicExpressionTreeValues(Model.SymbolicExpressionTree, ProblemData.Dataset, ProblemData.TrainingIndices).Count(double.IsNaN);
157      TestNaNEvaluations = Model.Interpreter.GetSymbolicExpressionTreeValues(Model.SymbolicExpressionTree, ProblemData.Dataset, ProblemData.TestIndices).Count(double.IsNaN);
[5736]158    }
[5607]159  }
160}
Note: See TracBrowser for help on using the repository browser.