Changeset 17928 for branches/3026_IntegrationIntoSymSpace/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees
- Timestamp:
- 04/06/21 13:13:32 (4 years ago)
- Location:
- branches/3026_IntegrationIntoSymSpace
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3026_IntegrationIntoSymSpace
- Property svn:mergeinfo changed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Algorithms.DataAnalysis
- Property svn:mergeinfo changed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Algorithms.DataAnalysis/3.4
- Property svn:mergeinfo changed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesAlgorithm.cs
r17180 r17928 281 281 new AccuracyMaximizationThresholdCalculator()); 282 282 var classificationProblemData = new ClassificationProblemData(problemData.Dataset, 283 problemData.AllowedInputVariables, problemData.TargetVariable, problemData.Transformations);283 problemData.AllowedInputVariables, problemData.TargetVariable, transformations: problemData.Transformations); 284 284 classificationProblemData.TrainingPartition.Start = Problem.ProblemData.TrainingPartition.Start; 285 285 classificationProblemData.TrainingPartition.End = Problem.ProblemData.TrainingPartition.End; -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesModelSurrogate.cs
r17180 r17928 24 24 using System.Collections.Generic; 25 25 using System.Linq; 26 using HEAL.Attic; 26 27 using HeuristicLab.Common; 27 28 using HeuristicLab.Core; 28 using HEAL.Attic;29 29 using HeuristicLab.Problems.DataAnalysis; 30 30 … … 38 38 // don't store the actual model! 39 39 // the actual model is only recalculated when necessary 40 private IGradientBoostedTreesModel fullModel; 40 41 private readonly Lazy<IGradientBoostedTreesModel> actualModel; 41 42 private IGradientBoostedTreesModel ActualModel { … … 48 49 private readonly uint seed; 49 50 [Storable] 50 private ILossFunction lossFunction;51 private readonly ILossFunction lossFunction; 51 52 [Storable] 52 private double r;53 private readonly double r; 53 54 [Storable] 54 private double m;55 private readonly double m; 55 56 [Storable] 56 private double nu;57 private readonly double nu; 57 58 [Storable] 58 private int iterations;59 private readonly int iterations; 59 60 [Storable] 60 private int maxSize;61 private readonly int maxSize; 61 62 62 63 … … 69 70 [StorableConstructor] 70 71 private GradientBoostedTreesModelSurrogate(StorableConstructorFlag _) : base(_) { 71 actualModel = new Lazy<IGradientBoostedTreesModel>(() => RecalculateModel());72 actualModel = CreateLazyInitFunc(); 72 73 } 73 74 74 75 private GradientBoostedTreesModelSurrogate(GradientBoostedTreesModelSurrogate original, Cloner cloner) 75 76 : base(original, cloner) { 76 IGradientBoostedTreesModel clonedModel = null; 77 if (original.actualModel.IsValueCreated) clonedModel = cloner.Clone(original.ActualModel); 78 actualModel = new Lazy<IGradientBoostedTreesModel>(CreateLazyInitFunc(clonedModel)); // only capture clonedModel in the closure 79 77 // clone data which is necessary to rebuild the model 80 78 this.trainingProblemData = cloner.Clone(original.trainingProblemData); 81 79 this.lossFunction = cloner.Clone(original.lossFunction); … … 86 84 this.m = original.m; 87 85 this.nu = original.nu; 86 87 // clone full model if it has already been created 88 if (original.fullModel != null) this.fullModel = cloner.Clone(original.fullModel); 89 actualModel = CreateLazyInitFunc(); 88 90 } 89 91 90 private Func<IGradientBoostedTreesModel> CreateLazyInitFunc(IGradientBoostedTreesModel clonedModel) { 91 return () => { 92 return clonedModel ?? RecalculateModel(); 93 }; 92 private Lazy<IGradientBoostedTreesModel> CreateLazyInitFunc() { 93 return new Lazy<IGradientBoostedTreesModel>(() => { 94 if (fullModel == null) fullModel = RecalculateModel(); 95 return fullModel; 96 }); 94 97 } 95 98 … … 107 110 this.nu = nu; 108 111 109 actualModel = new Lazy<IGradientBoostedTreesModel>(() => RecalculateModel());112 actualModel = CreateLazyInitFunc(); 110 113 } 111 114 112 // wrap an actual model in a surrog rate115 // wrap an actual model in a surrogate 113 116 public GradientBoostedTreesModelSurrogate(IGradientBoostedTreesModel model, IRegressionProblemData trainingProblemData, uint seed, 114 117 ILossFunction lossFunction, int iterations, int maxSize, double r, double m, double nu) 115 118 : this(trainingProblemData, seed, lossFunction, iterations, maxSize, r, m, nu) { 116 actualModel = new Lazy<IGradientBoostedTreesModel>(() => model);119 fullModel = model; 117 120 } 118 121 … … 135 138 136 139 public IEnumerable<IRegressionModel> Models { 137 get { 138 return ActualModel.Models; 139 } 140 get { return ActualModel.Models; } 140 141 } 141 142 142 143 public IEnumerable<double> Weights { 143 get { 144 return ActualModel.Weights; 145 } 144 get { return ActualModel.Weights; } 146 145 } 147 146 }
Note: See TracChangeset
for help on using the changeset viewer.