Changeset 16847 for branches/2847_M5Regression/HeuristicLab.Algorithms.DataAnalysis/3.4/M5Regression/LeafTypes/ComponentReductionLinearLeaf.cs
- Timestamp:
- 04/19/19 13:06:11 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2847_M5Regression/HeuristicLab.Algorithms.DataAnalysis/3.4/M5Regression/LeafTypes/ComponentReductionLinearLeaf.cs
r15967 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 [Storable Class]34 [StorableType("5730B54C-7A8B-4CA7-8F37-7FF3F9848CD2")] 35 35 [Item("ComponentReductionLinearLeaf", "A leaf type that uses principle component analysis to create smaller linear models as leaf models")] 36 36 public class ComponentReductionLinearLeaf : LeafBase { 37 public const string N oComponentsParameterName = "NoComponents";38 public IFixedValueParameter<IntValue> N oComponentsParameter {39 get { return Parameters[NoComponentsParameterName] as IFixedValueParameter<IntValue>; }37 public const string NumberOfComponentsParameterName = "NoComponents"; 38 public IFixedValueParameter<IntValue> NumberOfCompontentsParameter { 39 get { return (IFixedValueParameter<IntValue>)Parameters[NumberOfComponentsParameterName]; } 40 40 } 41 public int NoComponents { 42 get { return NoComponentsParameter.Value.Value; } 41 public int NumberOfComponents { 42 get { return NumberOfCompontentsParameter.Value.Value; } 43 set { NumberOfCompontentsParameter.Value.Value = value; } 43 44 } 44 45 45 46 #region Constructors & Cloning 46 47 [StorableConstructor] 47 protected ComponentReductionLinearLeaf( bool deserializing) : base(deserializing) { }48 protected ComponentReductionLinearLeaf(StorableConstructorFlag _) : base(_) { } 48 49 protected ComponentReductionLinearLeaf(ComponentReductionLinearLeaf original, Cloner cloner) : base(original, cloner) { } 49 50 public ComponentReductionLinearLeaf() { 50 Parameters.Add(new FixedValueParameter<IntValue>(N oComponentsParameterName, "The maximum number of principle components used", new IntValue(10)));51 Parameters.Add(new FixedValueParameter<IntValue>(NumberOfComponentsParameterName, "The maximum number of principle components used (default=10)", new IntValue(10))); 51 52 } 52 53 public override IDeepCloneable Clone(Cloner cloner) { … … 59 60 get { return false; } 60 61 } 62 61 63 public override IRegressionModel Build(IRegressionProblemData pd, IRandom random, 62 CancellationToken cancellationToken, out int n oParameters) {63 var pca = PrincipleComponentTransformation.CreateProjection(pd.Dataset, pd.TrainingIndices, pd.AllowedInputVariables, true);64 CancellationToken cancellationToken, out int numberOfParameters) { 65 var pca = PrincipleComponentTransformation.CreateProjection(pd.Dataset, pd.TrainingIndices, pd.AllowedInputVariables, normalize: true); 64 66 var pcdata = pca.TransformProblemData(pd); 65 67 ComponentReducedLinearModel bestModel = null; 66 68 var bestCvrmse = double.MaxValue; 67 n oParameters = 1;68 for (var i = 1; i <= Math.Min(N oComponents, pd.AllowedInputVariables.Count()); i++) {69 numberOfParameters = 1; 70 for (var i = 1; i <= Math.Min(NumberOfComponents, pd.AllowedInputVariables.Count()); i++) { 69 71 var pd2 = (IRegressionProblemData)pcdata.Clone(); 70 72 var inputs = new HashSet<string>(pca.ComponentNames.Take(i)); … … 75 77 if (rmse > bestCvrmse) continue; 76 78 bestModel = new ComponentReducedLinearModel(pd2.TargetVariable, model, pca); 77 n oParameters = i + 1;79 numberOfParameters = i + 1; 78 80 bestCvrmse = rmse; 79 81 } … … 82 84 83 85 public override int MinLeafSize(IRegressionProblemData pd) { 84 return N oComponents + 2;86 return NumberOfComponents + 2; 85 87 } 86 88 #endregion
Note: See TracChangeset
for help on using the changeset viewer.