- Timestamp:
- 07/23/19 20:20:35 (5 years ago)
- Location:
- stable
- Files:
-
- 10 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk merged: 17030,17032-17033,17043-17044,17137
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Algorithms.DataAnalysis
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Algorithms.DataAnalysis merged: 17030,17032,17043-17044,17137
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Algorithms.DataAnalysis/3.4
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Algorithms.DataAnalysis/3.4 merged: 17030,17032,17043-17044,17137
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesAlgorithm.cs
r17097 r17156 24 24 using System.Linq; 25 25 using System.Threading; 26 using HeuristicLab.Algorithms.DataAnalysis.GradientBoostedTrees; 26 27 using HeuristicLab.Analysis; 27 28 using HeuristicLab.Common; … … 49 50 private const string LossFunctionParameterName = "LossFunction"; 50 51 private const string UpdateIntervalParameterName = "UpdateInterval"; 51 private const string CreateSolutionParameterName = "CreateSolution";52 private const string ModelCreationParameterName = "ModelCreation"; 52 53 #endregion 53 54 … … 80 81 get { return (IFixedValueParameter<IntValue>)Parameters[UpdateIntervalParameterName]; } 81 82 } 82 p ublic IFixedValueParameter<BoolValue> CreateSolutionParameter {83 get { return (IFixedValueParameter< BoolValue>)Parameters[CreateSolutionParameterName]; }83 private IFixedValueParameter<EnumValue<ModelCreation>> ModelCreationParameter { 84 get { return (IFixedValueParameter<EnumValue<ModelCreation>>)Parameters[ModelCreationParameterName]; } 84 85 } 85 86 #endregion … … 114 115 set { MParameter.Value.Value = value; } 115 116 } 116 public bool CreateSolution {117 get { return CreateSolutionParameter.Value.Value; }118 set { CreateSolutionParameter.Value.Value = value; }117 public ModelCreation ModelCreation { 118 get { return ModelCreationParameter.Value.Value; } 119 set { ModelCreationParameter.Value.Value = value; } 119 120 } 120 121 #endregion … … 147 148 Parameters.Add(new FixedValueParameter<IntValue>(SeedParameterName, "The random seed used to initialize the new pseudo random number generator.", new IntValue(0))); 148 149 Parameters.Add(new FixedValueParameter<BoolValue>(SetSeedRandomlyParameterName, "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true))); 149 Parameters.Add(new FixedValueParameter<IntValue>(MaxSizeParameterName, "Maximal size of the tree learned in each step (prefer smaller sizes if possible)", new IntValue(10)));150 Parameters.Add(new FixedValueParameter<IntValue>(MaxSizeParameterName, "Maximal size of the tree learned in each step (prefer smaller sizes (3 to 10) if possible)", new IntValue(10))); 150 151 Parameters.Add(new FixedValueParameter<DoubleValue>(RParameterName, "Ratio of training rows selected randomly in each step (0 < R <= 1)", new DoubleValue(0.5))); 151 152 Parameters.Add(new FixedValueParameter<DoubleValue>(MParameterName, "Ratio of variables selected randomly in each step (0 < M <= 1)", new DoubleValue(0.5))); … … 153 154 Parameters.Add(new FixedValueParameter<IntValue>(UpdateIntervalParameterName, "", new IntValue(100))); 154 155 Parameters[UpdateIntervalParameterName].Hidden = true; 155 Parameters.Add(new FixedValueParameter< BoolValue>(CreateSolutionParameterName, "Flag that indicates if a solution should be produced at the end of the run", new BoolValue(true)));156 Parameters[ CreateSolutionParameterName].Hidden = true;156 Parameters.Add(new FixedValueParameter<EnumValue<ModelCreation>>(ModelCreationParameterName, "Defines the results produced at the end of the run (Surrogate => Less disk space, lazy recalculation of model)", new EnumValue<ModelCreation>(ModelCreation.Model))); 157 Parameters[ModelCreationParameterName].Hidden = true; 157 158 158 159 var lossFunctions = ApplicationManager.Manager.GetInstances<ILossFunction>(); … … 165 166 // BackwardsCompatibility3.4 166 167 #region Backwards compatible code, remove with 3.5 168 169 #region LossFunction 167 170 // parameter type has been changed 168 171 var lossFunctionParam = Parameters[LossFunctionParameterName] as ConstrainedValueParameter<StringValue>; … … 183 186 } 184 187 #endregion 188 189 #region CreateSolution 190 // parameter type has been changed 191 if (Parameters.ContainsKey("CreateSolution")) { 192 var createSolutionParam = Parameters["CreateSolution"] as FixedValueParameter<BoolValue>; 193 Parameters.Remove(createSolutionParam); 194 195 ModelCreation value = createSolutionParam.Value.Value ? ModelCreation.Model : ModelCreation.QualityOnly; 196 Parameters.Add(new FixedValueParameter<EnumValue<ModelCreation>>(ModelCreationParameterName, "Defines the results produced at the end of the run (Surrogate => Less disk space, lazy recalculation of model)", new EnumValue<ModelCreation>(value))); 197 Parameters[ModelCreationParameterName].Hidden = true; 198 } 199 #endregion 200 #endregion 185 201 } 186 202 … … 249 265 250 266 // produce solution 251 if (CreateSolution) { 252 var model = state.GetModel(); 267 if (ModelCreation == ModelCreation.SurrogateModel || ModelCreation == ModelCreation.Model) { 268 IRegressionModel model = state.GetModel(); 269 270 if (ModelCreation == ModelCreation.SurrogateModel) { 271 model = new GradientBoostedTreesModelSurrogate((GradientBoostedTreesModel)model, problemData, (uint)Seed, lossFunction, Iterations, MaxSize, R, M, Nu); 272 } 253 273 254 274 // for logistic regression we produce a classification solution … … 272 292 Results.Add(new Result("Solution", new GradientBoostedTreesSolution(model, problemData))); 273 293 } 294 } else if (ModelCreation == ModelCreation.QualityOnly) { 295 //Do nothing 296 } else { 297 throw new NotImplementedException("Selected parameter for CreateSolution isn't implemented yet"); 274 298 } 275 299 } -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesAlgorithmStatic.cs
r17097 r17156 101 101 102 102 public IRegressionModel GetModel() { 103 #pragma warning disable 618 104 var model = new GradientBoostedTreesModel(models, weights); 105 #pragma warning restore 618 106 // we don't know the number of iterations here but the number of weights is equal 107 // to the number of iterations + 1 (for the constant model) 108 // wrap the actual model in a surrogate that enables persistence and lazy recalculation of the model if necessary 109 return new GradientBoostedTreesModelSurrogate(problemData, randSeed, lossFunction, weights.Count - 1, maxSize, r, m, nu, model); 103 return new GradientBoostedTreesModel(models, weights); 110 104 } 111 105 public IEnumerable<KeyValuePair<string, double>> GetVariableRelevance() { -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesModel.cs
r17097 r17156 34 34 // this is essentially a collection of weighted regression models 35 35 public sealed class GradientBoostedTreesModel : RegressionModel, IGradientBoostedTreesModel { 36 // BackwardsCompatibility3.4 for allowing deserialization & serialization of old models37 #region Backwards compatible code, remove with 3.538 private bool isCompatibilityLoaded = false; // only set to true if the model is deserialized from the old format, needed to make sure that information is serialized again if it was loaded from the old format39 40 36 [Storable(Name = "models")] 41 37 private IList<IRegressionModel> __persistedModels { 42 38 set { 43 this.isCompatibilityLoaded = true;44 39 this.models.Clear(); 45 40 foreach (var m in value) this.models.Add(m); 46 41 } 47 get { if (this.isCompatibilityLoaded) return models; else return null; }42 get { return models; } 48 43 } 49 44 [Storable(Name = "weights")] 50 45 private IList<double> __persistedWeights { 51 46 set { 52 this.isCompatibilityLoaded = true;53 47 this.weights.Clear(); 54 48 foreach (var w in value) this.weights.Add(w); 55 49 } 56 get { if (this.isCompatibilityLoaded) return weights; else return null; }50 get { return weights; } 57 51 } 58 #endregion59 52 60 53 public override IEnumerable<string> VariablesUsedForPrediction { … … 77 70 this.weights = new List<double>(original.weights); 78 71 this.models = new List<IRegressionModel>(original.models.Select(m => cloner.Clone(m))); 79 this.isCompatibilityLoaded = original.isCompatibilityLoaded;80 72 } 81 [Obsolete("The constructor of GBTModel should not be used directly anymore (use GBTModelSurrogate instead)")] 73 82 74 internal GradientBoostedTreesModel(IEnumerable<IRegressionModel> models, IEnumerable<double> weights) 83 75 : base(string.Empty, "Gradient boosted tree model", string.Empty) { -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesModelSurrogate.cs
r17097 r17156 75 75 : base(original, cloner) { 76 76 IGradientBoostedTreesModel clonedModel = null; 77 if (original. ActualModel != null) clonedModel = cloner.Clone(original.ActualModel);77 if (original.actualModel.IsValueCreated) clonedModel = cloner.Clone(original.ActualModel); 78 78 actualModel = new Lazy<IGradientBoostedTreesModel>(CreateLazyInitFunc(clonedModel)); // only capture clonedModel in the closure 79 79 … … 90 90 private Func<IGradientBoostedTreesModel> CreateLazyInitFunc(IGradientBoostedTreesModel clonedModel) { 91 91 return () => { 92 return clonedModel == null ? RecalculateModel() : clonedModel;92 return clonedModel ?? RecalculateModel(); 93 93 }; 94 94 } 95 95 96 96 // create only the surrogate model without an actual model 97 p ublicGradientBoostedTreesModelSurrogate(IRegressionProblemData trainingProblemData, uint seed,97 private GradientBoostedTreesModelSurrogate(IRegressionProblemData trainingProblemData, uint seed, 98 98 ILossFunction lossFunction, int iterations, int maxSize, double r, double m, double nu) 99 99 : base(trainingProblemData.TargetVariable, "Gradient boosted tree model", string.Empty) { … … 106 106 this.m = m; 107 107 this.nu = nu; 108 109 actualModel = new Lazy<IGradientBoostedTreesModel>(() => RecalculateModel()); 108 110 } 109 111 110 112 // wrap an actual model in a surrograte 111 public GradientBoostedTreesModelSurrogate(IRegressionProblemData trainingProblemData, uint seed, 112 ILossFunction lossFunction, int iterations, int maxSize, double r, double m, double nu, 113 IGradientBoostedTreesModel model) 113 public GradientBoostedTreesModelSurrogate(IGradientBoostedTreesModel model, IRegressionProblemData trainingProblemData, uint seed, 114 ILossFunction lossFunction, int iterations, int maxSize, double r, double m, double nu) 114 115 : this(trainingProblemData, seed, lossFunction, iterations, maxSize, r, m, nu) { 115 116 actualModel = new Lazy<IGradientBoostedTreesModel>(() => model); -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/ModelCreation.cs
r17030 r17156 27 27 /// <summary> 28 28 /// Defines what part of the Model should be stored. 29 /// Quality - only the resulting Quality will be stored.30 /// Parameter - only the parameters will be stored, the models can be calculated afterwards31 /// Complete- the complete model will be stored (consider the amount of memory needed)29 /// QualityOnly - no solution will be created. 30 /// SurrogateModel - only the parameters will be stored, the model is calculated during deserialization 31 /// Model - the complete model will be stored (consider the amount of memory needed) 32 32 /// </summary> 33 33 [StorableType("EE55C357-C4B3-4662-B40B-D1D06A851809")] -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/HeuristicLab.Algorithms.DataAnalysis-3.4.csproj
r17105 r17156 217 217 <Compile Include="GradientBoostedTrees\LossFunctions\SquaredErrorLoss.cs" /> 218 218 <Compile Include="GradientBoostedTrees\GradientBoostedTreesSolution.cs" /> 219 <Compile Include="GradientBoostedTrees\ModelCreation.cs" /> 219 220 <Compile Include="GradientBoostedTrees\RegressionTreeBuilder.cs" /> 220 221 <Compile Include="GradientBoostedTrees\RegressionTreeModel.cs" /> -
stable/HeuristicLab.Tests
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Tests merged: 17033
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Tests/HeuristicLab.Algorithms.DataAnalysis-3.4/GradientBoostingTest.cs
r15292 r17156 237 237 gbt.Iterations = 5000; 238 238 gbt.MaxSize = 20; 239 gbt. CreateSolution = false;239 gbt.ModelCreation = GradientBoostedTrees.ModelCreation.QualityOnly; 240 240 #endregion 241 241 … … 265 265 gbt.Nu = 0.02; 266 266 gbt.LossFunctionParameter.Value = gbt.LossFunctionParameter.ValidValues.First(l => l.ToString().Contains("Absolute")); 267 gbt. CreateSolution = false;267 gbt.ModelCreation = GradientBoostedTrees.ModelCreation.QualityOnly; 268 268 #endregion 269 269 … … 293 293 gbt.Nu = 0.005; 294 294 gbt.LossFunctionParameter.Value = gbt.LossFunctionParameter.ValidValues.First(l => l.ToString().Contains("Relative")); 295 gbt. CreateSolution = false;295 gbt.ModelCreation = GradientBoostedTrees.ModelCreation.QualityOnly; 296 296 #endregion 297 297
Note: See TracChangeset
for help on using the changeset viewer.