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