- Timestamp:
- 07/08/16 14:37:15 (8 years ago)
- Location:
- stable
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 13826,13921-13922,13941,13992-13993,14000
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Algorithms.DataAnalysis
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Algorithms.DataAnalysis merged: 13921-13922,13941,13992-13993,14000
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesAlgorithmStatic.cs
r13184 r14027 96 96 weights = new List<double>(); 97 97 // add constant model 98 models.Add(new ConstantModel(f0 ));98 models.Add(new ConstantModel(f0, problemData.TargetVariable)); 99 99 weights.Add(1.0); 100 100 } -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesModel.cs
r13184 r14027 33 33 [Item("Gradient boosted tree model", "")] 34 34 // this is essentially a collection of weighted regression models 35 public sealed class GradientBoostedTreesModel : NamedItem, IGradientBoostedTreesModel {35 public sealed class GradientBoostedTreesModel : RegressionModel, IGradientBoostedTreesModel { 36 36 // BackwardsCompatibility3.4 for allowing deserialization & serialization of old models 37 37 #region Backwards compatible code, remove with 3.5 … … 58 58 #endregion 59 59 60 public override IEnumerable<string> VariablesUsedForPrediction { 61 get { return models.SelectMany(x => x.VariablesUsedForPrediction).Distinct().OrderBy(x => x); } 62 } 63 60 64 private readonly IList<IRegressionModel> models; 61 65 public IEnumerable<IRegressionModel> Models { get { return models; } } … … 77 81 } 78 82 [Obsolete("The constructor of GBTModel should not be used directly anymore (use GBTModelSurrogate instead)")] 79 publicGradientBoostedTreesModel(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) { 81 85 this.models = new List<IRegressionModel>(models); 82 86 this.weights = new List<double>(weights); … … 89 93 } 90 94 91 public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {95 public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) { 92 96 // allocate target array go over all models and add up weighted estimation for each row 93 97 if (!rows.Any()) return Enumerable.Empty<double>(); // return immediately if rows is empty. This prevents multiple iteration over lazy rows enumerable. … … 105 109 } 106 110 107 public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {111 public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 108 112 return new RegressionSolution(this, (IRegressionProblemData)problemData.Clone()); 109 113 } 114 110 115 } 111 116 } -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesModelSurrogate.cs
r13184 r14027 22 22 23 23 using System.Collections.Generic; 24 using System.Linq; 24 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; … … 33 34 // recalculate the actual GBT model on demand 34 35 [Item("Gradient boosted tree model", "")] 35 public sealed class GradientBoostedTreesModelSurrogate : NamedItem, IGradientBoostedTreesModel {36 public sealed class GradientBoostedTreesModelSurrogate : RegressionModel, IGradientBoostedTreesModel { 36 37 // don't store the actual model! 37 38 private IGradientBoostedTreesModel actualModel; // the actual model is only recalculated when necessary … … 55 56 56 57 58 public override IEnumerable<string> VariablesUsedForPrediction { 59 get { return actualModel.Models.SelectMany(x => x.VariablesUsedForPrediction).Distinct().OrderBy(x => x); } 60 } 61 57 62 [StorableConstructor] 58 63 private GradientBoostedTreesModelSurrogate(bool deserializing) : base(deserializing) { } … … 73 78 74 79 // 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) { 77 83 this.trainingProblemData = trainingProblemData; 78 84 this.seed = seed; … … 86 92 87 93 // 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) 89 97 : this(trainingProblemData, seed, lossFunction, iterations, maxSize, r, m, nu) { 90 98 this.actualModel = model; … … 96 104 97 105 // 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) { 99 107 if (actualModel == null) actualModel = RecalculateModel(); 100 108 return actualModel.GetEstimatedValues(dataset, rows); 101 109 } 102 110 103 public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {111 public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 104 112 return new RegressionSolution(this, (IRegressionProblemData)problemData.Clone()); 105 113 } 106 107 114 108 115 private IGradientBoostedTreesModel RecalculateModel() { -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/RegressionTreeBuilder.cs
r14023 r14027 137 137 int nRows = idx.Count(); 138 138 139 // shuffle variable idx139 // shuffle variable names 140 140 HeuristicLab.Random.ListExtensions.ShuffleInPlace(allowedVariables, random); 141 141 … … 176 176 CreateRegressionTreeFromQueue(maxSize, lossFunction); 177 177 178 return new RegressionTreeModel(tree.ToArray() );178 return new RegressionTreeModel(tree.ToArray(), problemData.TargetVariable); 179 179 } 180 180 -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/RegressionTreeModel.cs
r14023 r14027 34 34 [StorableClass] 35 35 [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 } 37 40 38 41 // trees are represented as a flat array … … 83 86 private TreeNode[] tree; 84 87 85 #region old storable format 88 #region old storable format 86 89 // remove with HL 3.4 87 90 [Storable(AllowOneWay = true)] … … 145 148 } 146 149 #endregion 147 148 149 150 150 151 151 [StorableConstructor] … … 160 160 } 161 161 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.") { 164 164 this.tree = tree; 165 165 } … … 187 187 } 188 188 189 public IEnumerable<double> GetEstimatedValues(IDataset ds, IEnumerable<int> rows) {189 public override IEnumerable<double> GetEstimatedValues(IDataset ds, IEnumerable<int> rows) { 190 190 // lookup columns for variableNames in one pass over the tree to speed up evaluation later on 191 191 ReadOnlyCollection<double>[] columnCache = new ReadOnlyCollection<double>[tree.Length]; … … 201 201 } 202 202 203 public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {203 public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 204 204 return new RegressionSolution(this, new RegressionProblemData(problemData)); 205 205 } … … 220 220 } 221 221 } 222 222 223 } 223 224 }
Note: See TracChangeset
for help on using the changeset viewer.