Automatic Differentiation
 
Loading...
Searching...
No Matches
bernoulli_logit_rng.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_PROB_BERNOULLI_LOGIT_RNG_HPP
2#define STAN_MATH_PRIM_PROB_BERNOULLI_LOGIT_RNG_HPP
3
9#include <boost/random/bernoulli_distribution.hpp>
10#include <boost/random/variate_generator.hpp>
11
12namespace stan {
13namespace math {
14
29template <typename T_t, class RNG>
31 const T_t& t, RNG& rng) {
32 using boost::bernoulli_distribution;
33 using boost::variate_generator;
34 ref_type_t<T_t> t_ref = t;
35 check_finite("bernoulli_logit_rng", "Logit transformed probability parameter",
36 t_ref);
37
38 scalar_seq_view<T_t> t_vec(t_ref);
39 size_t N = stan::math::size(t);
41
42 for (size_t n = 0; n < N; ++n) {
43 variate_generator<RNG&, bernoulli_distribution<> > bernoulli_rng(
44 rng, bernoulli_distribution<>(inv_logit(t_vec[n])));
45 output[n] = bernoulli_rng();
46 }
47
48 return output.data();
49}
50
51} // namespace math
52} // namespace stan
53#endif
typename helper::type type
VectorBuilder allocates type T1 values to be used as intermediate values.
scalar_seq_view provides a uniform sequence-like wrapper around either a scalar or a sequence of scal...
VectorBuilder< true, int, T_theta >::type bernoulli_rng(const T_theta &theta, RNG &rng)
Return a Bernoulli random variate with specified chance of success parameter using the specified rand...
VectorBuilder< true, int, T_t >::type bernoulli_logit_rng(const T_t &t, RNG &rng)
Return a Bernoulli random variate with logit-parameterized chance of success using the specified rand...
size_t size(const T &m)
Returns the size (number of the elements) of a matrix_cl or var_value<matrix_cl<T>>.
Definition size.hpp:18
void check_finite(const char *function, const char *name, const T_y &y)
Return true if all values in y are finite.
fvar< T > inv_logit(const fvar< T > &x)
Returns the inverse logit function applied to the argument.
Definition inv_logit.hpp:20
typename ref_type_if< true, T >::type ref_type_t
Definition ref_type.hpp:55
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Definition fvar.hpp:9