Changeset 15679


Ignore:
Timestamp:
01/30/18 17:28:46 (19 months ago)
Author:
fholzing
Message:

#2883: Removed backwardscompatibility and changed the level of the decision if surrogate or not into the algorithm (so one level up)

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  
    286286      // produce solution
    287287      if (CreateSolution == ModelStorage.Parameter || CreateSolution == ModelStorage.Complete) {
    288         IRegressionModel model = null;
     288        IRegressionModel model = state.GetModel();
    289289
    290290        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);
    296292        }
    297293
  • branches/2883_GBTModelStorage/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesAlgorithmStatic.cs

    r15678 r15679  
    3333
    3434    public interface IGbmState {
    35       IRegressionModel GetModel(bool shallow = true);
     35      IRegressionModel GetModel();
    3636      double GetTrainLoss();
    3737      double GetTestLoss();
     
    100100      }
    101101
    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
    114106      }
    115107      public IEnumerable<KeyValuePair<string, double>> GetVariableRelevance() {
  • branches/2883_GBTModelStorage/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesModel.cs

    r15678 r15679  
    3636    // BackwardsCompatibility3.4 for allowing deserialization & serialization of old models
    3737    #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     internal bool IsCompatibilityLoaded { get { return this.isCompatibilityLoaded; } set { this.isCompatibilityLoaded = value; } }
    4038
    4139    [Storable(Name = "models")]
    42     private IList<IRegressionModel> __persistedModels {
    43       set {
    44         this.isCompatibilityLoaded = true;
     40    private IList<IRegressionModel> __persistedModels
     41    {
     42      set
     43      {
    4544        this.models.Clear();
    4645        foreach (var m in value) this.models.Add(m);
    4746      }
    48       get { if (this.isCompatibilityLoaded) return models; else return null; }
     47      get { return models; }
    4948    }
    5049    [Storable(Name = "weights")]
    51     private IList<double> __persistedWeights {
    52       set {
    53         this.isCompatibilityLoaded = true;
     50    private IList<double> __persistedWeights
     51    {
     52      set
     53      {
    5454        this.weights.Clear();
    5555        foreach (var w in value) this.weights.Add(w);
    5656      }
    57       get { if (this.isCompatibilityLoaded) return weights; else return null; }
     57      get { return weights; }
    5858    }
    5959    #endregion
    6060
    61     public override IEnumerable<string> VariablesUsedForPrediction {
     61    public override IEnumerable<string> VariablesUsedForPrediction
     62    {
    6263      get { return models.SelectMany(x => x.VariablesUsedForPrediction).Distinct().OrderBy(x => x); }
    6364    }
     
    7980      this.weights = new List<double>(original.weights);
    8081      this.models = new List<IRegressionModel>(original.models.Select(m => cloner.Clone(m)));
    81       this.isCompatibilityLoaded = original.isCompatibilityLoaded;
    8282    }
    8383    [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  
    3939    // the actual model is only recalculated when necessary
    4040    private readonly Lazy<IGradientBoostedTreesModel> actualModel;
    41     private IGradientBoostedTreesModel ActualModel {
     41    private IGradientBoostedTreesModel ActualModel
     42    {
    4243      get { return actualModel.Value; }
    4344    }
     
    6162
    6263
    63     public override IEnumerable<string> VariablesUsedForPrediction {
    64       get {
     64    public override IEnumerable<string> VariablesUsedForPrediction
     65    {
     66      get
     67      {
    6568        return ActualModel.Models.SelectMany(x => x.VariablesUsedForPrediction).Distinct().OrderBy(x => x);
    6669      }
     
    134137    }
    135138
    136     public IEnumerable<IRegressionModel> Models {
    137       get {
     139    public IEnumerable<IRegressionModel> Models
     140    {
     141      get
     142      {
    138143        return ActualModel.Models;
    139144      }
    140145    }
    141146
    142     public IEnumerable<double> Weights {
    143       get {
     147    public IEnumerable<double> Weights
     148    {
     149      get
     150      {
    144151        return ActualModel.Weights;
    145152      }
Note: See TracChangeset for help on using the changeset viewer.