Ignore:
Timestamp:
04/19/19 13:06:11 (7 months ago)
Author:
gkronber
Message:

#2847: made some minor changes while reviewing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2847_M5Regression/HeuristicLab.Algorithms.DataAnalysis/3.4/M5Regression/LeafTypes/ComponentReductionLinearLeaf.cs

    r15967 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   [StorableClass]
     34  [StorableType("5730B54C-7A8B-4CA7-8F37-7FF3F9848CD2")]
    3535  [Item("ComponentReductionLinearLeaf", "A leaf type that uses principle component analysis to create smaller linear models as leaf models")]
    3636  public class ComponentReductionLinearLeaf : LeafBase {
    37     public const string NoComponentsParameterName = "NoComponents";
    38     public IFixedValueParameter<IntValue> NoComponentsParameter {
    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]; }
    4040    }
    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; }
    4344    }
    4445
    4546    #region Constructors & Cloning
    4647    [StorableConstructor]
    47     protected ComponentReductionLinearLeaf(bool deserializing) : base(deserializing) { }
     48    protected ComponentReductionLinearLeaf(StorableConstructorFlag _) : base(_) { }
    4849    protected ComponentReductionLinearLeaf(ComponentReductionLinearLeaf original, Cloner cloner) : base(original, cloner) { }
    4950    public ComponentReductionLinearLeaf() {
    50       Parameters.Add(new FixedValueParameter<IntValue>(NoComponentsParameterName, "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)));
    5152    }
    5253    public override IDeepCloneable Clone(Cloner cloner) {
     
    5960      get { return false; }
    6061    }
     62
    6163    public override IRegressionModel Build(IRegressionProblemData pd, IRandom random,
    62       CancellationToken cancellationToken, out int noParameters) {
    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);
    6466      var pcdata = pca.TransformProblemData(pd);
    6567      ComponentReducedLinearModel bestModel = null;
    6668      var bestCvrmse = double.MaxValue;
    67       noParameters = 1;
    68       for (var i = 1; i <= Math.Min(NoComponents, pd.AllowedInputVariables.Count()); i++) {
     69      numberOfParameters = 1;
     70      for (var i = 1; i <= Math.Min(NumberOfComponents, pd.AllowedInputVariables.Count()); i++) {
    6971        var pd2 = (IRegressionProblemData)pcdata.Clone();
    7072        var inputs = new HashSet<string>(pca.ComponentNames.Take(i));
     
    7577        if (rmse > bestCvrmse) continue;
    7678        bestModel = new ComponentReducedLinearModel(pd2.TargetVariable, model, pca);
    77         noParameters = i + 1;
     79        numberOfParameters = i + 1;
    7880        bestCvrmse = rmse;
    7981      }
     
    8284
    8385    public override int MinLeafSize(IRegressionProblemData pd) {
    84       return NoComponents + 2;
     86      return NumberOfComponents + 2;
    8587    }
    8688    #endregion
Note: See TracChangeset for help on using the changeset viewer.