Changeset 13898


Ignore:
Timestamp:
06/15/16 21:51:14 (3 years ago)
Author:
gkronber
Message:

#1795: GBM now sets the seed of the base learner in each iteration

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GBM/GradientBoostingRegressionAlgorithm.cs

    r13889 r13898  
    286286          IRegressionModel model;
    287287          IRun run;
     288
    288289          // try to find a model. The algorithm might fail to produce a model. In this case we just retry until the iterations are exhausted
    289           if (TryExecute(alg, RegressionAlgorithmResult, out model, out run)) {
     290          if (TryExecute(alg, rand.Next(), RegressionAlgorithmResult, out model, out run)) {
    290291            int row = 0;
    291292            // update predictions for training and test
     
    419420    }
    420421
    421     private static bool TryExecute(IAlgorithm alg, string regressionAlgorithmResultName, out IRegressionModel model, out IRun run) {
     422    private static bool TryExecute(IAlgorithm alg, int seed, string regressionAlgorithmResultName, out IRegressionModel model, out IRun run) {
    422423      model = null;
     424      SetSeed(alg, seed);
    423425      using (var wh = new AutoResetEvent(false)) {
    424426        Exception ex = null;
     
    464466      return model != null;
    465467    }
     468
     469    private static void SetSeed(IAlgorithm alg, int seed) {
     470      // no common interface for algs that use a PRNG -> use naming convention to set seed
     471      var paramItem = alg as IParameterizedItem;
     472
     473      if (paramItem.Parameters.ContainsKey("SetSeedRandomly")) {
     474        ((BoolValue)paramItem.Parameters["SetSeedRandomly"].ActualValue).Value = false;
     475        ((IntValue)paramItem.Parameters["Seed"].ActualValue).Value = seed;
     476      } else {
     477        throw new ArgumentException("Base learner does not have a seed parameter (algorithm {0})", alg.Name);
     478      }
     479
     480    }
    466481  }
    467482}
Note: See TracChangeset for help on using the changeset viewer.