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