Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2839_HiveProjectManagement/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationPruningAnalyzer.cs @ 17495

Last change on this file since 17495 was 16057, checked in by jkarder, 6 years ago

#2839:

File size: 4.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 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 HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Parameters;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27
28namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification {
29  [Item("SymbolicClassificationPruningAnalyzer", "An analyzer that prunes introns from the population.")]
30  [StorableClass]
31  public sealed class SymbolicClassificationPruningAnalyzer : SymbolicDataAnalysisSingleObjectivePruningAnalyzer {
32    private const string PruningOperatorParameterName = "PruningOperator";
33    public IValueParameter<SymbolicClassificationPruningOperator> PruningOperatorParameter {
34      get { return (IValueParameter<SymbolicClassificationPruningOperator>)Parameters[PruningOperatorParameterName]; }
35    }
36
37    protected override SymbolicDataAnalysisExpressionPruningOperator PruningOperator {
38      get { return PruningOperatorParameter.Value; }
39    }
40
41    private SymbolicClassificationPruningAnalyzer(SymbolicClassificationPruningAnalyzer original, Cloner cloner) : base(original, cloner) { }
42    public override IDeepCloneable Clone(Cloner cloner) { return new SymbolicClassificationPruningAnalyzer(this, cloner); }
43
44    [StorableConstructor]
45    private SymbolicClassificationPruningAnalyzer(bool deserializing) : base(deserializing) { }
46
47    public SymbolicClassificationPruningAnalyzer() {
48      Parameters.Add(new ValueParameter<SymbolicClassificationPruningOperator>(PruningOperatorParameterName, "The operator used to prune trees", new SymbolicClassificationPruningOperator(new SymbolicClassificationSolutionImpactValuesCalculator())));
49    }
50
51    [StorableHook(HookType.AfterDeserialization)]
52    private void AfterDeserialization() {
53      // BackwardsCompatibility3.3
54
55      #region Backwards compatible code, remove with 3.4
56      if (Parameters.ContainsKey(PruningOperatorParameterName)) {
57        var oldParam = Parameters[PruningOperatorParameterName] as ValueParameter<SymbolicDataAnalysisExpressionPruningOperator>;
58        if (oldParam != null) {
59          Parameters.Remove(oldParam);
60          Parameters.Add(new ValueParameter<SymbolicClassificationPruningOperator>(PruningOperatorParameterName, "The operator used to prune trees", new SymbolicClassificationPruningOperator(new SymbolicClassificationSolutionImpactValuesCalculator())));
61        }
62      } else {
63        // not yet contained
64        Parameters.Add(new ValueParameter<SymbolicClassificationPruningOperator>(PruningOperatorParameterName, "The operator used to prune trees", new SymbolicClassificationPruningOperator(new SymbolicClassificationSolutionImpactValuesCalculator())));
65      }
66
67      if (Parameters.ContainsKey("PruneOnlyZeroImpactNodes")) {
68        PruningOperator.PruneOnlyZeroImpactNodes = ((IFixedValueParameter<BoolValue>)Parameters["PruneOnlyZeroImpactNodes"]).Value.Value;
69        Parameters.Remove(Parameters["PruneOnlyZeroImpactNodes"]);
70      }
71      if (Parameters.ContainsKey("ImpactThreshold")) {
72        PruningOperator.NodeImpactThreshold = ((IFixedValueParameter<DoubleValue>)Parameters["ImpactThreshold"]).Value.Value;
73        Parameters.Remove(Parameters["ImpactThreshold"]);
74      }
75      if (Parameters.ContainsKey("ImpactValuesCalculator")) {
76        PruningOperator.ImpactValuesCalculator = ((ValueParameter<SymbolicDataAnalysisSolutionImpactValuesCalculator>)Parameters["ImpactValuesCalculator"]).Value;
77        Parameters.Remove(Parameters["ImpactValuesCalculator"]);
78      }
79      #endregion
80    }
81  }
82}
Note: See TracBrowser for help on using the repository browser.