StochTree 0.5.0.9000
Loading...
Searching...
No Matches
ig_sampler.h
1
2#ifndef STOCHTREE_IG_SAMPLER_H_
3#define STOCHTREE_IG_SAMPLER_H_
4
5#include <stochtree/distributions.h>
6#include <random>
7
8namespace StochTree {
9
11 public:
14 double Sample(double a, double b, std::mt19937& gen, bool scale_param = true) {
15 // C++ standard library provides a gamma distribution with scale
16 // parameter, but the correspondence between gamma and IG is that
17 // 1 / gamma(a,b) ~ IG(a,b) when b is a __rate__ parameter.
18 // Before sampling, we convert ig_scale to a gamma scale parameter by
19 // taking its multiplicative inverse.
20 double gamma_scale = scale_param ? 1. / b : b;
21 return (1 / sample_gamma(gen, a, gamma_scale));
22 }
23};
24
25} // namespace StochTree
26
27#endif // STOCHTREE_IG_SAMPLER_H_
Definition ig_sampler.h:10
static void GFRSampleOneIter(TreeEnsemble &active_forest, ForestTracker &tracker, ForestContainer &forests, LeafModel &leaf_model, ForestDataset &dataset, ColumnVector &residual, TreePrior &tree_prior, std::mt19937 &gen, std::vector< double > &variable_weights, std::vector< int > &sweep_update_indices, double global_variance, std::vector< FeatureType > &feature_types, int cutpoint_grid_size, bool keep_forest, bool pre_initialized, bool backfitting, int num_features_subsample, int num_threads, LeafSuffStatConstructorArgs &... leaf_suff_stat_args)
Definition tree_sampler.h:816
A collection of random number generation utilities.
Definition bart.h:15
double sample_gamma(std::mt19937 &gen, double shape, double scale)
Definition distributions.h:193