[5624] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[16057] | 3 | * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[5624] | 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 |
|
---|
[11332] | 22 | using System.Linq;
|
---|
[5624] | 23 | using HeuristicLab.Common;
|
---|
| 24 | using HeuristicLab.Core;
|
---|
| 25 | using HeuristicLab.Data;
|
---|
[11332] | 26 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
[6411] | 27 | using HeuristicLab.Optimization;
|
---|
[5624] | 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 = "SymbolicClassificationSolution", Description = "Represents a symbolic classification solution (model + data) and attributes of the solution like accuracy and complexity.")]
|
---|
[5717] | 36 | public sealed class SymbolicClassificationSolution : ClassificationSolution, ISymbolicClassificationSolution {
|
---|
[5736] | 37 | private const string ModelLengthResultName = "ModelLength";
|
---|
| 38 | private const string ModelDepthResultName = "ModelDepth";
|
---|
[5624] | 39 |
|
---|
| 40 | public new ISymbolicClassificationModel Model {
|
---|
| 41 | get { return (ISymbolicClassificationModel)base.Model; }
|
---|
[5717] | 42 | set { base.Model = value; }
|
---|
[5624] | 43 | }
|
---|
| 44 |
|
---|
| 45 | ISymbolicDataAnalysisModel ISymbolicDataAnalysisSolution.Model {
|
---|
| 46 | get { return (ISymbolicDataAnalysisModel)base.Model; }
|
---|
| 47 | }
|
---|
[5736] | 48 | public int ModelLength {
|
---|
| 49 | get { return ((IntValue)this[ModelLengthResultName].Value).Value; }
|
---|
| 50 | private set { ((IntValue)this[ModelLengthResultName].Value).Value = value; }
|
---|
| 51 | }
|
---|
[5624] | 52 |
|
---|
[5736] | 53 | public int ModelDepth {
|
---|
| 54 | get { return ((IntValue)this[ModelDepthResultName].Value).Value; }
|
---|
| 55 | private set { ((IntValue)this[ModelDepthResultName].Value).Value = value; }
|
---|
| 56 | }
|
---|
| 57 |
|
---|
[5624] | 58 | [StorableConstructor]
|
---|
[5717] | 59 | private SymbolicClassificationSolution(bool deserializing) : base(deserializing) { }
|
---|
| 60 | private SymbolicClassificationSolution(SymbolicClassificationSolution original, Cloner cloner)
|
---|
[5624] | 61 | : base(original, cloner) {
|
---|
| 62 | }
|
---|
| 63 | public SymbolicClassificationSolution(ISymbolicClassificationModel model, IClassificationProblemData problemData)
|
---|
| 64 | : base(model, problemData) {
|
---|
[11332] | 65 | foreach (var node in model.SymbolicExpressionTree.Root.IterateNodesPrefix().OfType<SymbolicExpressionTreeTopLevelNode>())
|
---|
| 66 | node.SetGrammar(null);
|
---|
| 67 |
|
---|
[5736] | 68 | Add(new Result(ModelLengthResultName, "Length of the symbolic classification model.", new IntValue()));
|
---|
| 69 | Add(new Result(ModelDepthResultName, "Depth of the symbolic classification model.", new IntValue()));
|
---|
[6589] | 70 | RecalculateResults();
|
---|
[5624] | 71 | }
|
---|
| 72 |
|
---|
| 73 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 74 | return new SymbolicClassificationSolution(this, cloner);
|
---|
| 75 | }
|
---|
[5736] | 76 |
|
---|
[6411] | 77 | protected override void RecalculateResults() {
|
---|
[8723] | 78 | base.RecalculateResults();
|
---|
[5736] | 79 | ModelLength = Model.SymbolicExpressionTree.Length;
|
---|
| 80 | ModelDepth = Model.SymbolicExpressionTree.Depth;
|
---|
| 81 | }
|
---|
[5624] | 82 | }
|
---|
| 83 | }
|
---|