Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/08/16 14:37:15 (8 years ago)
Author:
mkommend
Message:

#2604: Merged r13826,r13921, r13922, r13941, r13992, r13993, r14000 intos table.

Location:
stable
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Algorithms.DataAnalysis

  • stable/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesAlgorithmStatic.cs

    r13184 r14027  
    9696        weights = new List<double>();
    9797        // add constant model
    98         models.Add(new ConstantModel(f0));
     98        models.Add(new ConstantModel(f0, problemData.TargetVariable));
    9999        weights.Add(1.0);
    100100      }
  • stable/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesModel.cs

    r13184 r14027  
    3333  [Item("Gradient boosted tree model", "")]
    3434  // this is essentially a collection of weighted regression models
    35   public sealed class GradientBoostedTreesModel : NamedItem, IGradientBoostedTreesModel {
     35  public sealed class GradientBoostedTreesModel : RegressionModel, IGradientBoostedTreesModel {
    3636    // BackwardsCompatibility3.4 for allowing deserialization & serialization of old models
    3737    #region Backwards compatible code, remove with 3.5
     
    5858    #endregion
    5959
     60    public override IEnumerable<string> VariablesUsedForPrediction {
     61      get { return models.SelectMany(x => x.VariablesUsedForPrediction).Distinct().OrderBy(x => x); }
     62    }
     63
    6064    private readonly IList<IRegressionModel> models;
    6165    public IEnumerable<IRegressionModel> Models { get { return models; } }
     
    7781    }
    7882    [Obsolete("The constructor of GBTModel should not be used directly anymore (use GBTModelSurrogate instead)")]
    79     public GradientBoostedTreesModel(IEnumerable<IRegressionModel> models, IEnumerable<double> weights)
    80       : base("Gradient boosted tree model", string.Empty) {
     83    internal GradientBoostedTreesModel(IEnumerable<IRegressionModel> models, IEnumerable<double> weights)
     84      : base(string.Empty, "Gradient boosted tree model", string.Empty) {
    8185      this.models = new List<IRegressionModel>(models);
    8286      this.weights = new List<double>(weights);
     
    8993    }
    9094
    91     public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
     95    public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
    9296      // allocate target array go over all models and add up weighted estimation for each row
    9397      if (!rows.Any()) return Enumerable.Empty<double>(); // return immediately if rows is empty. This prevents multiple iteration over lazy rows enumerable.
     
    105109    }
    106110
    107     public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
     111    public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
    108112      return new RegressionSolution(this, (IRegressionProblemData)problemData.Clone());
    109113    }
     114
    110115  }
    111116}
  • stable/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesModelSurrogate.cs

    r13184 r14027  
    2222
    2323using System.Collections.Generic;
     24using System.Linq;
    2425using HeuristicLab.Common;
    2526using HeuristicLab.Core;
     
    3334  // recalculate the actual GBT model on demand
    3435  [Item("Gradient boosted tree model", "")]
    35   public sealed class GradientBoostedTreesModelSurrogate : NamedItem, IGradientBoostedTreesModel {
     36  public sealed class GradientBoostedTreesModelSurrogate : RegressionModel, IGradientBoostedTreesModel {
    3637    // don't store the actual model!
    3738    private IGradientBoostedTreesModel actualModel; // the actual model is only recalculated when necessary
     
    5556
    5657
     58    public override IEnumerable<string> VariablesUsedForPrediction {
     59      get { return actualModel.Models.SelectMany(x => x.VariablesUsedForPrediction).Distinct().OrderBy(x => x); }
     60    }
     61
    5762    [StorableConstructor]
    5863    private GradientBoostedTreesModelSurrogate(bool deserializing) : base(deserializing) { }
     
    7378
    7479    // create only the surrogate model without an actual model
    75     public GradientBoostedTreesModelSurrogate(IRegressionProblemData trainingProblemData, uint seed, ILossFunction lossFunction, int iterations, int maxSize, double r, double m, double nu)
    76       : base("Gradient boosted tree model", string.Empty) {
     80    public GradientBoostedTreesModelSurrogate(IRegressionProblemData trainingProblemData, uint seed,
     81      ILossFunction lossFunction, int iterations, int maxSize, double r, double m, double nu)
     82      : base(trainingProblemData.TargetVariable, "Gradient boosted tree model", string.Empty) {
    7783      this.trainingProblemData = trainingProblemData;
    7884      this.seed = seed;
     
    8692
    8793    // wrap an actual model in a surrograte
    88     public GradientBoostedTreesModelSurrogate(IRegressionProblemData trainingProblemData, uint seed, ILossFunction lossFunction, int iterations, int maxSize, double r, double m, double nu, IGradientBoostedTreesModel model)
     94    public GradientBoostedTreesModelSurrogate(IRegressionProblemData trainingProblemData, uint seed,
     95      ILossFunction lossFunction, int iterations, int maxSize, double r, double m, double nu,
     96      IGradientBoostedTreesModel model)
    8997      : this(trainingProblemData, seed, lossFunction, iterations, maxSize, r, m, nu) {
    9098      this.actualModel = model;
     
    96104
    97105    // forward message to actual model (recalculate model first if necessary)
    98     public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
     106    public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
    99107      if (actualModel == null) actualModel = RecalculateModel();
    100108      return actualModel.GetEstimatedValues(dataset, rows);
    101109    }
    102110
    103     public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
     111    public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
    104112      return new RegressionSolution(this, (IRegressionProblemData)problemData.Clone());
    105113    }
    106 
    107114
    108115    private IGradientBoostedTreesModel RecalculateModel() {
  • stable/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/RegressionTreeBuilder.cs

    r14023 r14027  
    137137      int nRows = idx.Count();
    138138
    139       // shuffle variable idx
     139      // shuffle variable names
    140140      HeuristicLab.Random.ListExtensions.ShuffleInPlace(allowedVariables, random);
    141141
     
    176176      CreateRegressionTreeFromQueue(maxSize, lossFunction);
    177177
    178       return new RegressionTreeModel(tree.ToArray());
     178      return new RegressionTreeModel(tree.ToArray(), problemData.TargetVariable);
    179179    }
    180180
  • stable/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/RegressionTreeModel.cs

    r14023 r14027  
    3434  [StorableClass]
    3535  [Item("RegressionTreeModel", "Represents a decision tree for regression.")]
    36   public sealed class RegressionTreeModel : NamedItem, IRegressionModel {
     36  public sealed class RegressionTreeModel : RegressionModel {
     37    public override IEnumerable<string> VariablesUsedForPrediction {
     38      get { return tree.Select(t => t.VarName).Where(v => v != TreeNode.NO_VARIABLE); }
     39    }
    3740
    3841    // trees are represented as a flat array   
     
    8386    private TreeNode[] tree;
    8487
    85     #region old storable format 
     88    #region old storable format
    8689    // remove with HL 3.4
    8790    [Storable(AllowOneWay = true)]
     
    145148    }
    146149    #endregion
    147 
    148 
    149 
    150150
    151151    [StorableConstructor]
     
    160160    }
    161161
    162     internal RegressionTreeModel(TreeNode[] tree)
    163       : base("RegressionTreeModel", "Represents a decision tree for regression.") {
     162    internal RegressionTreeModel(TreeNode[] tree, string targetVariable)
     163      : base(targetVariable, "RegressionTreeModel", "Represents a decision tree for regression.") {
    164164      this.tree = tree;
    165165    }
     
    187187    }
    188188
    189     public IEnumerable<double> GetEstimatedValues(IDataset ds, IEnumerable<int> rows) {
     189    public override IEnumerable<double> GetEstimatedValues(IDataset ds, IEnumerable<int> rows) {
    190190      // lookup columns for variableNames in one pass over the tree to speed up evaluation later on
    191191      ReadOnlyCollection<double>[] columnCache = new ReadOnlyCollection<double>[tree.Length];
     
    201201    }
    202202
    203     public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
     203    public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
    204204      return new RegressionSolution(this, new RegressionProblemData(problemData));
    205205    }
     
    220220      }
    221221    }
     222
    222223  }
    223224}
Note: See TracChangeset for help on using the changeset viewer.