StochTree 0.4.1
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
A collection of random number generation utilities.
Definition category_tracker.h:36
double sample_gamma(std::mt19937 &gen, double shape, double scale)
Definition distributions.h:175