Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2434_crossvalidation/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationSolution.cs @ 17006

Last change on this file since 17006 was 12012, checked in by ascheibe, 10 years ago

#2212 merged r12008, r12009, r12010 back into trunk

File size: 3.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 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
22using System.Linq;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
27using HeuristicLab.Optimization;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29
30namespace 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.")]
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(bool deserializing) : base(deserializing) { }
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}
Note: See TracBrowser for help on using the repository browser.