27 #ifndef LBANN_UTILS_BETA_HPP 28 #define LBANN_UTILS_BETA_HPP 50 template <
typename RealType =
double>
62 :
m_a(param_a),
m_b(param_b)
64 if (param_a <= RealType(0) || param_b <= RealType(0)) {
65 LBANN_ERROR(
"Beta distribution parameters must be positive");
69 constexpr RealType
a()
const {
return m_a; }
70 constexpr RealType
b()
const {
return m_b; }
105 template <
typename Generator>
110 template <
typename Generator>
135 template <
typename Generator>
146 template <
typename Generator>
185 template <
typename Generator>
189 const result_type U = random_uniform<result_type>(g);
190 const result_type V = random_uniform<result_type>(g);
205 return std::exp(logX - std::log(std::exp(logX) + std::exp(logY)));
217 template <
typename Generator>
223 return Ga / (Ga + Gb);
227 template <
typename CharT,
typename RealType>
228 std::basic_ostream<CharT>& operator<<(std::basic_ostream<CharT>& os,
231 os <<
"~Beta(" << d.
a() <<
"," << d.b() <<
")";
235 template <
typename CharT,
typename RealType>
236 std::basic_istream<CharT>&
operator>>(std::basic_istream<CharT>& is,
241 if (std::getline(is, s,
'(') && s ==
"~Beta" && is >> a && is.get() ==
',' &&
242 is >> b && is.get() ==
')') {
246 is.setstate(std::ios::failbit);
253 #endif // LBANN_UTILS_BETA_HPP param_type(RealType param_a, RealType param_b)
result_type generate_johnk(Generator &g, result_type a, result_type b)
result_type generate(Generator &g)
constexpr RealType b() const
constexpr RealType a() const
result_type operator()(Generator &g)
beta_distribution(const param_type &p)
void param(const param_type &p)
beta_distribution(RealType a, RealType b)
std::basic_istream< CharT > & operator>>(std::basic_istream< CharT > &is, beta_distribution< RealType > &d)
bool operator!=(const beta_distribution< result_type > &other) const
result_type generate_gamma(Generator &g, gamma_dist &gamma_a, gamma_dist &gamma_b)
bool operator==(const param_type &other) const
result_type generate(Generator &g, const param_type &p)
bool operator!=(const param_type &other) const
std::gamma_distribution< RealType > gamma_dist
bool operator==(const beta_distribution< result_type > &other) const
result_type operator()(Generator &g, const param_type &p)