Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/19/19 13:06:11 (6 years ago)
Author:
gkronber
Message:

#2847: made some minor changes while reviewing

Location:
branches/2847_M5Regression/HeuristicLab.Algorithms.DataAnalysis/3.4/M5Regression/Pruning
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/2847_M5Regression/HeuristicLab.Algorithms.DataAnalysis/3.4/M5Regression/Pruning/ComplexityPruning.cs

    r15830 r16847  
    2828using HeuristicLab.Data;
    2929using HeuristicLab.Parameters;
    30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3130using HeuristicLab.Problems.DataAnalysis;
     31using HEAL.Attic;
    3232
    3333namespace HeuristicLab.Algorithms.DataAnalysis {
     34  [StorableType("B643D965-D13F-415D-8589-3F3527460347")]
    3435  public class ComplexityPruning : ParameterizedNamedItem, IPruning {
    3536    public const string PruningStateVariableName = "PruningState";
    3637
    37     private const string PruningStrengthParameterName = "PruningStrength";
    38     private const string PruningDecayParameterName = "PruningDecay";
    39     private const string FastPruningParameterName = "FastPruning";
     38    public const string PruningStrengthParameterName = "PruningStrength";
     39    public const string PruningDecayParameterName = "PruningDecay";
     40    public const string FastPruningParameterName = "FastPruning";
    4041
    4142    public IFixedValueParameter<DoubleValue> PruningStrengthParameter {
     
    5152    public double PruningStrength {
    5253      get { return PruningStrengthParameter.Value.Value; }
     54      set { PruningStrengthParameter.Value.Value = value; }
    5355    }
    5456    public double PruningDecay {
    5557      get { return PruningDecayParameter.Value.Value; }
     58      set { PruningDecayParameter.Value.Value = value; }
    5659    }
    5760    public bool FastPruning {
    5861      get { return FastPruningParameter.Value.Value; }
     62      set { FastPruningParameter.Value.Value = value; }
    5963    }
    6064
    6165    #region Constructors & Cloning
    6266    [StorableConstructor]
    63     protected ComplexityPruning(bool deserializing) : base(deserializing) { }
     67    protected ComplexityPruning(StorableConstructorFlag _) : base(_) { }
    6468    protected ComplexityPruning(ComplexityPruning original, Cloner cloner) : base(original, cloner) { }
    6569    public ComplexityPruning() {
    66       Parameters.Add(new FixedValueParameter<DoubleValue>(PruningStrengthParameterName, "The strength of the pruning. Higher values force the algorithm to create simpler models", new DoubleValue(2.0)));
    67       Parameters.Add(new FixedValueParameter<DoubleValue>(PruningDecayParameterName, "Pruning decay allows nodes higher up in the tree to be more stable.", new DoubleValue(1.0)));
    68       Parameters.Add(new FixedValueParameter<BoolValue>(FastPruningParameterName, "Accelerate Pruning by using linear models instead of leaf models", new BoolValue(true)));
     70      Parameters.Add(new FixedValueParameter<DoubleValue>(PruningStrengthParameterName, "The strength of the pruning. Higher values force the algorithm to create simpler models (default=2.0).", new DoubleValue(2.0)));
     71      Parameters.Add(new FixedValueParameter<DoubleValue>(PruningDecayParameterName, "Pruning decay allows nodes higher up in the tree to be more stable (default=1.0).", new DoubleValue(1.0)));
     72      Parameters.Add(new FixedValueParameter<BoolValue>(FastPruningParameterName, "Accelerate pruning by using linear models instead of leaf models (default=true).", new BoolValue(true)));
    6973    }
    7074    public override IDeepCloneable Clone(Cloner cloner) {
     
    136140    }
    137141
    138 
    139142    private static void UpdateThreshold(RegressionNodeTreeModel tree, PruningState state) {
    140143      if (state.Code == 2) {
     
    161164    }
    162165
    163 
    164166    private static void BuildPruningModel(RegressionNodeModel regressionNode, ILeafModel leaf, IReadOnlyList<int> trainingRows, IReadOnlyList<int> pruningRows, PruningState state, RegressionTreeParameters regressionTreeParams, CancellationToken cancellationToken) {
    165167      //create regressionProblemdata from pruning data
    166       var vars = regressionTreeParams.AllowedInputVariables.Concat(new[] {regressionTreeParams.TargetVariable}).ToArray();
     168      var vars = regressionTreeParams.AllowedInputVariables.Concat(new[] { regressionTreeParams.TargetVariable }).ToArray();
    167169      var reducedData = new Dataset(vars, vars.Select(x => regressionTreeParams.Data.GetDoubleValues(x, pruningRows).ToList()));
    168170      var pd = new RegressionProblemData(reducedData, regressionTreeParams.AllowedInputVariables, regressionTreeParams.TargetVariable);
     
    179181      state.modelErrors.Add(regressionNode, rmsModel);
    180182      state.modelComplexities.Add(regressionNode, numModelParams);
    181       if (regressionNode.IsLeaf) { state.nodeComplexities[regressionNode] = state.modelComplexities[regressionNode]; }
    182       else { state.nodeComplexities.Add(regressionNode, state.nodeComplexities[regressionNode.Left] + state.nodeComplexities[regressionNode.Right] + 1); }
     183      if (regressionNode.IsLeaf) { state.nodeComplexities[regressionNode] = state.modelComplexities[regressionNode]; } else { state.nodeComplexities.Add(regressionNode, state.nodeComplexities[regressionNode.Left] + state.nodeComplexities[regressionNode.Right] + 1); }
    183184    }
    184185
     
    200201    }
    201202
    202     [StorableClass]
     203    [StorableType("EAD60C7E-2C58-45C4-9697-6F735F518CFD")]
    203204    public class PruningState : Item {
    204205      [Storable]
     
    230231      #region HLConstructors & Cloning
    231232      [StorableConstructor]
    232       protected PruningState(bool deserializing) : base(deserializing) { }
     233      protected PruningState(StorableConstructorFlag _) : base(_) { }
    233234      protected PruningState(PruningState original, Cloner cloner) : base(original, cloner) {
    234235        modelComplexities = original.modelComplexities.ToDictionary(x => cloner.Clone(x.Key), x => x.Value);
  • branches/2847_M5Regression/HeuristicLab.Algorithms.DataAnalysis/3.4/M5Regression/Pruning/NoPruning.cs

    r15830 r16847  
    2424using HeuristicLab.Common;
    2525using HeuristicLab.Core;
    26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2726using HeuristicLab.Problems.DataAnalysis;
     27using HEAL.Attic;
    2828
    2929namespace HeuristicLab.Algorithms.DataAnalysis {
    30   [StorableClass]
     30  [StorableType("D67152AA-3533-45D2-B77B-4A0742FB4B92")]
    3131  [Item("NoPruning", "No pruning")]
    3232  public class NoPruning : ParameterizedNamedItem, IPruning {
    3333    #region Constructors & Cloning
    3434    [StorableConstructor]
    35     private NoPruning(bool deserializing) : base(deserializing) { }
     35    private NoPruning(StorableConstructorFlag _) : base(_) { }
    3636    private NoPruning(NoPruning original, Cloner cloner) : base(original, cloner) { }
    3737    public NoPruning() { }
Note: See TracChangeset for help on using the changeset viewer.