1 #ifndef __STAN__PROB__DISTRIBUTIONS__UNIVARIATE__CONTINUOUS__EXPONENTIAL_HPP__
2 #define __STAN__PROB__DISTRIBUTIONS__UNIVARIATE__CONTINUOUS__EXPONENTIAL_HPP__
41 template <
bool propto,
42 typename T_y,
typename T_inv_scale,
47 static const char*
function =
"stan::prob::exponential_log(%1%)";
60 if(!
check_not_nan(
function, y,
"Random variable", &logp, Policy()))
62 if(!
check_finite(
function, beta,
"Inverse scale parameter", &logp, Policy()))
64 if(!
check_positive(
function, beta,
"Inverse scale parameter", &logp, Policy()))
69 "Random variable",
"Inverse scale parameter",
79 for (
size_t n = 0; n < N; n++) {
81 logp +=
log(beta_vec[n]);
83 logp -= beta_vec[n] * y_vec[n];
88 template <
bool propto,
89 typename T_y,
typename T_inv_scale>
96 template <
typename T_y,
typename T_inv_scale,
101 return exponential_log<false>(y,beta,Policy());
104 template <
typename T_y,
typename T_inv_scale>
126 template <
typename T_y,
127 typename T_inv_scale,
129 typename boost::math::tools::promote_args<T_y,T_inv_scale>::type
131 const T_inv_scale& beta,
134 static const char*
function =
"stan::prob::exponential_cdf(%1%)";
139 using boost::math::tools::promote_args;
141 typename promote_args<T_y,T_inv_scale>::type lp;
142 if(!
check_not_nan(
function, y,
"Random variable", &lp, Policy()))
144 if(!
check_finite(
function, beta,
"Inverse scale parameter", &lp, Policy()))
146 if(!
check_positive(
function, beta,
"Inverse scale parameter", &lp, Policy()))
152 return 1.0 -
exp(-beta * y);
155 template <
typename T_y,
156 typename T_inv_scale>
158 typename boost::math::tools::promote_args<T_y,T_inv_scale>::type
160 const T_inv_scale& beta) {
var log(const var &a)
Return the natural log of the specified variable (cmath).
var exp(const var &a)
Return the exponentiation of the specified variable (cmath).
bool check_not_nan(const char *function, const T_y &y, const char *name, T_result *result, const Policy &)
Checks if the variable y is nan.
bool check_consistent_sizes(const char *function, const T1 &x1, const T2 &x2, const char *name1, const char *name2, T_result *result, const Policy &)
bool check_positive(const char *function, const T_y &y, const char *name, T_result *result, const Policy &)
bool check_finite(const char *function, const T_y &y, const char *name, T_result *result, const Policy &)
Checks if the variable y is finite.
boost::math::policies::policy default_policy
Default error-handling policy from Boost.
return_type< T_y, T_inv_scale >::type exponential_log(const T_y &y, const T_inv_scale &beta, const Policy &)
The log of an exponential density for y with the specified inverse scale parameter.
boost::math::tools::promote_args< T_y, T_inv_scale >::type exponential_cdf(const T_y &y, const T_inv_scale &beta, const Policy &)
Calculates the exponential cumulative distribution function for the given y and beta.
Probability, optimization and sampling library.
size_t length(const T &x)
size_t max_size(const T1 &x1, const T2 &x2)
Template metaprogram to calculate whether a summand needs to be included in a proportional (log) prob...
boost::math::tools::promote_args< typename scalar_type< T1 >::type, typename scalar_type< T2 >::type, typename scalar_type< T3 >::type, typename scalar_type< T4 >::type, typename scalar_type< T5 >::type, typename scalar_type< T6 >::type >::type type