1 #ifndef STAN_MATH_PRIM_SCAL_PROB_BERNOULLI_LOGIT_LPMF_HPP 2 #define STAN_MATH_PRIM_SCAL_PROB_BERNOULLI_LOGIT_LPMF_HPP 28 template <
bool propto,
typename T_n,
typename T_prob>
30 const T_prob& theta) {
31 static const char*
function =
"bernoulli_logit_lpmf";
40 T_partials_return logp(0.0);
43 check_not_nan(
function,
"Logit transformed probability parameter", theta);
45 "Probability parameter", theta);
55 for (
size_t n = 0; n < N; n++) {
56 const T_partials_return theta_dbl =
value_of(theta_vec[n]);
58 const int sign = 2 * n_vec[n] - 1;
59 const T_partials_return ntheta = sign * theta_dbl;
60 const T_partials_return exp_m_ntheta =
exp(-ntheta);
63 static const double cutoff = 20.0;
66 else if (ntheta < -cutoff)
69 logp -=
log1p(exp_m_ntheta);
73 ops_partials.
edge1_.partials_[n] -= exp_m_ntheta;
74 else if (ntheta < -cutoff)
77 ops_partials.
edge1_.partials_[n]
78 += sign * exp_m_ntheta / (exp_m_ntheta + 1);
81 return ops_partials.
build(logp);
84 template <
typename T_n,
typename T_prob>
86 const T_n& n,
const T_prob& theta) {
87 return bernoulli_logit_lpmf<false>(n, theta);
boost::math::tools::promote_args< double, typename partials_type< typename scalar_type< T >::type >::type, typename partials_return_type< T_pack... >::type >::type type
void check_bounded(const char *function, const char *name, const T_y &y, const T_low &low, const T_high &high)
Check if the value is between the low and high values, inclusively.
T value_of(const fvar< T > &v)
Return the value of the specified variable.
Extends std::true_type when instantiated with zero or more template parameters, all of which extend t...
scalar_seq_view provides a uniform sequence-like wrapper around either a scalar or a sequence of scal...
This template builds partial derivatives with respect to a set of operands.
bool size_zero(T &x)
Returns 1 if input is of length 0, returns 0 otherwise.
Template metaprogram to calculate whether a summand needs to be included in a proportional (log) prob...
boost::math::tools::promote_args< double, typename scalar_type< T >::type, typename return_type< Types_pack... >::type >::type type
fvar< T > exp(const fvar< T > &x)
void check_not_nan(const char *function, const char *name, const T_y &y)
Check if y is not NaN.
size_t max_size(const T1 &x1, const T2 &x2)
T_return_type build(double value)
Build the node to be stored on the autodiff graph.
fvar< T > log1p(const fvar< T > &x)
return_type< T_prob >::type bernoulli_logit_lpmf(const T_n &n, const T_prob &theta)
Returns the log PMF of the logit-parametrized Bernoulli distribution.
void check_consistent_sizes(const char *function, const char *name1, const T1 &x1, const char *name2, const T2 &x2)
Check if the dimension of x1 is consistent with x2.
internal::ops_partials_edge< double, Op1 > edge1_