Changeset 16847 for branches/2847_M5Regression/HeuristicLab.Algorithms.DataAnalysis/3.4/M5Regression/Pruning
- Timestamp:
- 04/19/19 13:06:11 (6 years ago)
- 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 28 28 using HeuristicLab.Data; 29 29 using HeuristicLab.Parameters; 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;31 30 using HeuristicLab.Problems.DataAnalysis; 31 using HEAL.Attic; 32 32 33 33 namespace HeuristicLab.Algorithms.DataAnalysis { 34 [StorableType("B643D965-D13F-415D-8589-3F3527460347")] 34 35 public class ComplexityPruning : ParameterizedNamedItem, IPruning { 35 36 public const string PruningStateVariableName = "PruningState"; 36 37 37 p rivateconst string PruningStrengthParameterName = "PruningStrength";38 p rivateconst string PruningDecayParameterName = "PruningDecay";39 p rivateconst string FastPruningParameterName = "FastPruning";38 public const string PruningStrengthParameterName = "PruningStrength"; 39 public const string PruningDecayParameterName = "PruningDecay"; 40 public const string FastPruningParameterName = "FastPruning"; 40 41 41 42 public IFixedValueParameter<DoubleValue> PruningStrengthParameter { … … 51 52 public double PruningStrength { 52 53 get { return PruningStrengthParameter.Value.Value; } 54 set { PruningStrengthParameter.Value.Value = value; } 53 55 } 54 56 public double PruningDecay { 55 57 get { return PruningDecayParameter.Value.Value; } 58 set { PruningDecayParameter.Value.Value = value; } 56 59 } 57 60 public bool FastPruning { 58 61 get { return FastPruningParameter.Value.Value; } 62 set { FastPruningParameter.Value.Value = value; } 59 63 } 60 64 61 65 #region Constructors & Cloning 62 66 [StorableConstructor] 63 protected ComplexityPruning( bool deserializing) : base(deserializing) { }67 protected ComplexityPruning(StorableConstructorFlag _) : base(_) { } 64 68 protected ComplexityPruning(ComplexityPruning original, Cloner cloner) : base(original, cloner) { } 65 69 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))); 69 73 } 70 74 public override IDeepCloneable Clone(Cloner cloner) { … … 136 140 } 137 141 138 139 142 private static void UpdateThreshold(RegressionNodeTreeModel tree, PruningState state) { 140 143 if (state.Code == 2) { … … 161 164 } 162 165 163 164 166 private static void BuildPruningModel(RegressionNodeModel regressionNode, ILeafModel leaf, IReadOnlyList<int> trainingRows, IReadOnlyList<int> pruningRows, PruningState state, RegressionTreeParameters regressionTreeParams, CancellationToken cancellationToken) { 165 167 //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(); 167 169 var reducedData = new Dataset(vars, vars.Select(x => regressionTreeParams.Data.GetDoubleValues(x, pruningRows).ToList())); 168 170 var pd = new RegressionProblemData(reducedData, regressionTreeParams.AllowedInputVariables, regressionTreeParams.TargetVariable); … … 179 181 state.modelErrors.Add(regressionNode, rmsModel); 180 182 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); } 183 184 } 184 185 … … 200 201 } 201 202 202 [Storable Class]203 [StorableType("EAD60C7E-2C58-45C4-9697-6F735F518CFD")] 203 204 public class PruningState : Item { 204 205 [Storable] … … 230 231 #region HLConstructors & Cloning 231 232 [StorableConstructor] 232 protected PruningState( bool deserializing) : base(deserializing) { }233 protected PruningState(StorableConstructorFlag _) : base(_) { } 233 234 protected PruningState(PruningState original, Cloner cloner) : base(original, cloner) { 234 235 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 24 24 using HeuristicLab.Common; 25 25 using HeuristicLab.Core; 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;27 26 using HeuristicLab.Problems.DataAnalysis; 27 using HEAL.Attic; 28 28 29 29 namespace HeuristicLab.Algorithms.DataAnalysis { 30 [Storable Class]30 [StorableType("D67152AA-3533-45D2-B77B-4A0742FB4B92")] 31 31 [Item("NoPruning", "No pruning")] 32 32 public class NoPruning : ParameterizedNamedItem, IPruning { 33 33 #region Constructors & Cloning 34 34 [StorableConstructor] 35 private NoPruning( bool deserializing) : base(deserializing) { }35 private NoPruning(StorableConstructorFlag _) : base(_) { } 36 36 private NoPruning(NoPruning original, Cloner cloner) : base(original, cloner) { } 37 37 public NoPruning() { }
Note: See TracChangeset
for help on using the changeset viewer.