StochTree
0.0.1
Loading...
Searching...
No Matches
include
stochtree
ig_sampler.h
1
2
#ifndef STOCHTREE_IG_SAMPLER_H_
3
#define STOCHTREE_IG_SAMPLER_H_
4
5
#include <random>
6
7
namespace
StochTree
{
8
9
class
InverseGammaSampler
{
10
public
:
11
InverseGammaSampler
() {}
12
~InverseGammaSampler
() {}
13
double
Sample(
double
a,
double
b, std::mt19937& gen,
bool
scale_param =
true
) {
14
// C++ standard library provides a gamma distribution with scale
15
// parameter, but the correspondence between gamma and IG is that
16
// 1 / gamma(a,b) ~ IG(a,b) when b is a __rate__ parameter.
17
// Before sampling, we convert ig_scale to a gamma scale parameter by
18
// taking its multiplicative inverse.
19
double
gamma_scale = scale_param ? 1./b : b;
20
gamma_dist_ = std::gamma_distribution<double>(a, gamma_scale);
21
return
(1/gamma_dist_(gen));
22
}
23
private
:
25
std::gamma_distribution<double> gamma_dist_;
26
};
27
28
}
// namespace StochTree
29
30
#endif
// STOCHTREE_IG_SAMPLER_H_
StochTree::InverseGammaSampler
Definition
ig_sampler.h:9
StochTree
Definition
category_tracker.h:40
Generated by
1.9.8