Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionPruningAnalyzer.cs @ 16628

Last change on this file since 16628 was 16628, checked in by gkronber, 5 years ago

#2971: made branch compile with current version of trunk

File size: 4.3 KB
Line 
1#region License Information
2
3/* HeuristicLab
4 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
5 *
6 * This file is part of HeuristicLab.
7 *
8 * HeuristicLab is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * HeuristicLab is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#endregion
23
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Parameters;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29using HEAL.Attic;
30
31namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
32  [Item("SymbolicRegressionPruningAnalyzer", "An analyzer that prunes introns from the population.")]
33  [StorableType("D69BBBC0-CB73-45B8-BCAD-AE3B89DDD41D")]
34  public sealed class SymbolicRegressionPruningAnalyzer : SymbolicDataAnalysisSingleObjectivePruningAnalyzer {
35    private const string PruningOperatorParameterName = "PruningOperator";
36    public IValueParameter<SymbolicRegressionPruningOperator> PruningOperatorParameter {
37      get { return (IValueParameter<SymbolicRegressionPruningOperator>)Parameters[PruningOperatorParameterName]; }
38    }
39
40    protected override SymbolicDataAnalysisExpressionPruningOperator PruningOperator {
41      get { return PruningOperatorParameter.Value; }
42    }
43
44    private SymbolicRegressionPruningAnalyzer(SymbolicRegressionPruningAnalyzer original, Cloner cloner) : base(original, cloner) { }
45    public override IDeepCloneable Clone(Cloner cloner) { return new SymbolicRegressionPruningAnalyzer(this, cloner); }
46
47    [StorableConstructor]
48    private SymbolicRegressionPruningAnalyzer(StorableConstructorFlag _) : base(_) { }
49
50    public SymbolicRegressionPruningAnalyzer() {
51      Parameters.Add(new ValueParameter<SymbolicRegressionPruningOperator>(PruningOperatorParameterName, "The operator used to prune trees", new SymbolicRegressionPruningOperator(new SymbolicRegressionSolutionImpactValuesCalculator())));
52    }
53
54    [StorableHook(HookType.AfterDeserialization)]
55    private void AfterDeserialization() {
56      // BackwardsCompatibility3.3
57
58      #region Backwards compatible code, remove with 3.4
59      if (Parameters.ContainsKey(PruningOperatorParameterName)) {
60        var oldParam = Parameters[PruningOperatorParameterName] as ValueParameter<SymbolicDataAnalysisExpressionPruningOperator>;
61        if (oldParam != null) {
62          Parameters.Remove(oldParam);
63          Parameters.Add(new ValueParameter<SymbolicRegressionPruningOperator>(PruningOperatorParameterName, "The operator used to prune trees", new SymbolicRegressionPruningOperator(new SymbolicRegressionSolutionImpactValuesCalculator())));
64        }
65      } else {
66        // not yet contained
67        Parameters.Add(new ValueParameter<SymbolicRegressionPruningOperator>(PruningOperatorParameterName, "The operator used to prune trees", new SymbolicRegressionPruningOperator(new SymbolicRegressionSolutionImpactValuesCalculator())));
68      }
69
70
71      if (Parameters.ContainsKey("PruneOnlyZeroImpactNodes")) {
72        PruningOperator.PruneOnlyZeroImpactNodes = ((IFixedValueParameter<BoolValue>)Parameters["PruneOnlyZeroImpactNodes"]).Value.Value;
73        Parameters.Remove(Parameters["PruneOnlyZeroImpactNodes"]);
74      }
75      if (Parameters.ContainsKey("ImpactThreshold")) {
76        PruningOperator.NodeImpactThreshold = ((IFixedValueParameter<DoubleValue>)Parameters["ImpactThreshold"]).Value.Value;
77        Parameters.Remove(Parameters["ImpactThreshold"]);
78      }
79      if (Parameters.ContainsKey("ImpactValuesCalculator")) {
80        PruningOperator.ImpactValuesCalculator = ((ValueParameter<SymbolicDataAnalysisSolutionImpactValuesCalculator>)Parameters["ImpactValuesCalculator"]).Value;
81        Parameters.Remove(Parameters["ImpactValuesCalculator"]);
82      }
83
84      #endregion
85    }
86  }
87}
Note: See TracBrowser for help on using the repository browser.