- Timestamp:
- 01/30/18 17:28:46 (7 years ago)
- Location:
- branches/2883_GBTModelStorage/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2883_GBTModelStorage/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesAlgorithm.cs
r15678 r15679 286 286 // produce solution 287 287 if (CreateSolution == ModelStorage.Parameter || CreateSolution == ModelStorage.Complete) { 288 IRegressionModel model = null;288 IRegressionModel model = state.GetModel(); 289 289 290 290 if (CreateSolution == ModelStorage.Parameter) { 291 model = state.GetModel(); 292 } else if (CreateSolution == ModelStorage.Complete) { 293 //If "Complete", a deep-copy is required, so no lazy lists 294 model = state.GetModel(false); 295 (model as GradientBoostedTreesModel).IsCompatibilityLoaded = true; 291 model = new GradientBoostedTreesModelSurrogate(problemData, (uint)Seed, lossFunction, Iterations, MaxSize, R, M, Nu, (GradientBoostedTreesModel)model); 296 292 } 297 293 -
branches/2883_GBTModelStorage/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesAlgorithmStatic.cs
r15678 r15679 33 33 34 34 public interface IGbmState { 35 IRegressionModel GetModel( bool shallow = true);35 IRegressionModel GetModel(); 36 36 double GetTrainLoss(); 37 37 double GetTestLoss(); … … 100 100 } 101 101 102 public IRegressionModel GetModel(bool shallow = true) { 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 if (shallow) { 110 return new GradientBoostedTreesModelSurrogate(problemData, randSeed, lossFunction, weights.Count - 1, maxSize, r, m, nu, model); 111 } else { 112 return model; 113 } 102 public IRegressionModel GetModel() { 103 #pragma warning disable CS0618 // Type or member is obsolete 104 return new GradientBoostedTreesModel(models, weights); 105 #pragma warning restore CS0618 // Type or member is obsolete 114 106 } 115 107 public IEnumerable<KeyValuePair<string, double>> GetVariableRelevance() { -
branches/2883_GBTModelStorage/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesModel.cs
r15678 r15679 36 36 // BackwardsCompatibility3.4 for allowing deserialization & serialization of old models 37 37 #region Backwards compatible code, remove with 3.5 38 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 internal bool IsCompatibilityLoaded { get { return this.isCompatibilityLoaded; } set { this.isCompatibilityLoaded = value; } }40 38 41 39 [Storable(Name = "models")] 42 private IList<IRegressionModel> __persistedModels { 43 set { 44 this.isCompatibilityLoaded = true; 40 private IList<IRegressionModel> __persistedModels 41 { 42 set 43 { 45 44 this.models.Clear(); 46 45 foreach (var m in value) this.models.Add(m); 47 46 } 48 get { if (this.isCompatibilityLoaded) return models; else return null; }47 get { return models; } 49 48 } 50 49 [Storable(Name = "weights")] 51 private IList<double> __persistedWeights { 52 set { 53 this.isCompatibilityLoaded = true; 50 private IList<double> __persistedWeights 51 { 52 set 53 { 54 54 this.weights.Clear(); 55 55 foreach (var w in value) this.weights.Add(w); 56 56 } 57 get { if (this.isCompatibilityLoaded) return weights; else return null; }57 get { return weights; } 58 58 } 59 59 #endregion 60 60 61 public override IEnumerable<string> VariablesUsedForPrediction { 61 public override IEnumerable<string> VariablesUsedForPrediction 62 { 62 63 get { return models.SelectMany(x => x.VariablesUsedForPrediction).Distinct().OrderBy(x => x); } 63 64 } … … 79 80 this.weights = new List<double>(original.weights); 80 81 this.models = new List<IRegressionModel>(original.models.Select(m => cloner.Clone(m))); 81 this.isCompatibilityLoaded = original.isCompatibilityLoaded;82 82 } 83 83 [Obsolete("The constructor of GBTModel should not be used directly anymore (use GBTModelSurrogate instead)")] -
branches/2883_GBTModelStorage/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesModelSurrogate.cs
r15583 r15679 39 39 // the actual model is only recalculated when necessary 40 40 private readonly Lazy<IGradientBoostedTreesModel> actualModel; 41 private IGradientBoostedTreesModel ActualModel { 41 private IGradientBoostedTreesModel ActualModel 42 { 42 43 get { return actualModel.Value; } 43 44 } … … 61 62 62 63 63 public override IEnumerable<string> VariablesUsedForPrediction { 64 get { 64 public override IEnumerable<string> VariablesUsedForPrediction 65 { 66 get 67 { 65 68 return ActualModel.Models.SelectMany(x => x.VariablesUsedForPrediction).Distinct().OrderBy(x => x); 66 69 } … … 134 137 } 135 138 136 public IEnumerable<IRegressionModel> Models { 137 get { 139 public IEnumerable<IRegressionModel> Models 140 { 141 get 142 { 138 143 return ActualModel.Models; 139 144 } 140 145 } 141 146 142 public IEnumerable<double> Weights { 143 get { 147 public IEnumerable<double> Weights 148 { 149 get 150 { 144 151 return ActualModel.Weights; 145 152 }
Note: See TracChangeset
for help on using the changeset viewer.