Changeset 12869 for branches/crossvalidation-2434/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesModel.cs
- Timestamp:
- 08/17/15 16:35:47 (9 years ago)
- Location:
- branches/crossvalidation-2434
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/crossvalidation-2434
- Property svn:mergeinfo changed
/trunk/sources merged: 12835-12837,12839,12844-12846,12851,12855,12868
- Property svn:mergeinfo changed
-
branches/crossvalidation-2434/HeuristicLab.Algorithms.DataAnalysis
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Algorithms.DataAnalysis merged: 12868
- Property svn:mergeinfo changed
-
branches/crossvalidation-2434/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesModel.cs
r12660 r12869 34 34 // this is essentially a collection of weighted regression models 35 35 public sealed class GradientBoostedTreesModel : NamedItem, IRegressionModel { 36 [Storable] 36 // BackwardsCompatibility3.4 for allowing deserialization & serialization of old models 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 format 39 40 [Storable(Name = "models")] 41 private IList<IRegressionModel> __persistedModels { 42 set { 43 this.isCompatibilityLoaded = true; 44 this.models.Clear(); 45 foreach (var m in value) this.models.Add(m); 46 } 47 get { if (this.isCompatibilityLoaded) return models; else return null; } 48 } 49 [Storable(Name = "weights")] 50 private IList<double> __persistedWeights { 51 set { 52 this.isCompatibilityLoaded = true; 53 this.weights.Clear(); 54 foreach (var w in value) this.weights.Add(w); 55 } 56 get { if (this.isCompatibilityLoaded) return weights; else return null; } 57 } 58 #endregion 59 37 60 private readonly IList<IRegressionModel> models; 38 61 public IEnumerable<IRegressionModel> Models { get { return models; } } 39 62 40 [Storable]41 63 private readonly IList<double> weights; 42 64 public IEnumerable<double> Weights { get { return weights; } } 43 65 44 66 [StorableConstructor] 45 private GradientBoostedTreesModel(bool deserializing) : base(deserializing) { } 67 private GradientBoostedTreesModel(bool deserializing) 68 : base(deserializing) { 69 models = new List<IRegressionModel>(); 70 weights = new List<double>(); 71 } 46 72 private GradientBoostedTreesModel(GradientBoostedTreesModel original, Cloner cloner) 47 73 : base(original, cloner) { 48 74 this.weights = new List<double>(original.weights); 49 75 this.models = new List<IRegressionModel>(original.models.Select(m => cloner.Clone(m))); 76 this.isCompatibilityLoaded = original.isCompatibilityLoaded; 50 77 } 51 78 public GradientBoostedTreesModel(IEnumerable<IRegressionModel> models, IEnumerable<double> weights) … … 64 91 // allocate target array go over all models and add up weighted estimation for each row 65 92 if (!rows.Any()) return Enumerable.Empty<double>(); // return immediately if rows is empty. This prevents multiple iteration over lazy rows enumerable. 66 93 // (which essentially looks up indexes in a dictionary) 67 94 var res = new double[rows.Count()]; 68 95 for (int i = 0; i < models.Count; i++) {
Note: See TracChangeset
for help on using the changeset viewer.