Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OaaS/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicDiscriminantFunctionClassificationSolution.cs @ 11328

Last change on this file since 11328 was 9363, checked in by spimming, 12 years ago

#1888:

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