Stan Math Library  2.20.0
reverse mode automatic differentiation
bernoulli_logit_rng.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_PROB_BERNOULLI_LOGIT_RNG_HPP
2 #define STAN_MATH_PRIM_SCAL_PROB_BERNOULLI_LOGIT_RNG_HPP
3 
7 #include <boost/random/bernoulli_distribution.hpp>
8 #include <boost/random/variate_generator.hpp>
9 
10 namespace stan {
11 namespace math {
12 
27 template <typename T_t, class RNG>
29  const T_t& t, RNG& rng) {
30  using boost::bernoulli_distribution;
31  using boost::variate_generator;
32 
33  check_finite("bernoulli_logit_rng", "Logit transformed probability parameter",
34  t);
35 
36  scalar_seq_view<T_t> t_vec(t);
37  size_t N = length(t);
39 
40  for (size_t n = 0; n < N; ++n) {
41  variate_generator<RNG&, bernoulli_distribution<> > bernoulli_rng(
42  rng, bernoulli_distribution<>(inv_logit(t_vec[n])));
43  output[n] = bernoulli_rng();
44  }
45 
46  return output.data();
47 }
48 
49 } // namespace math
50 } // namespace stan
51 #endif
void check_finite(const char *function, const char *name, const T_y &y)
Check if y is finite.
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...
scalar_seq_view provides a uniform sequence-like wrapper around either a scalar or a sequence of scal...
fvar< T > inv_logit(const fvar< T > &x)
Returns the inverse logit function applied to the argument.
Definition: inv_logit.hpp:20
size_t length(const std::vector< T > &x)
Returns the length of the provided std::vector.
Definition: length.hpp:16
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...
VectorBuilder allocates type T1 values to be used as intermediate values.

     [ Stan Home Page ] © 2011–2018, Stan Development Team.