1 #ifndef __STAN__PROB__DISTRIBUTIONS__UNIVARIATE__CONTINUOUS__TRUNC_NORMAL_HPP__
2 #define __STAN__PROB__DISTRIBUTIONS__UNIVARIATE__CONTINUOUS__TRUNC_NORMAL_HPP__
41 template <
bool propto,
42 typename T_y,
typename T_loc,
typename T_scale,
typename T_alpha,
typename T_beta,
44 typename boost::math::tools::promote_args<T_y,T_loc,T_scale,T_alpha,T_beta>::type
46 const T_alpha& alpha,
const T_beta& beta,
48 static const char*
function =
"stan::prob::trunc_normal_log(%1%)";
53 using boost::math::tools::promote_args;
57 typename promote_args<T_y,T_loc,T_scale,T_alpha,T_beta>::type lp(0.0);
69 if (y < alpha || y > beta) {
73 lp = normal_log<propto>(y,mu,sigma,Policy());
76 lp -=
log(beta - alpha);
78 lp -=
log(
Phi((beta - mu)/sigma) -
Phi((alpha - mu)/sigma));
86 template <
bool propto,
87 typename T_y,
typename T_loc,
typename T_scale,
typename T_alpha,
typename T_beta>
89 typename boost::math::tools::promote_args<T_y,T_loc,T_scale,T_alpha,T_beta>::type
90 trunc_normal_log(
const T_y& y,
const T_loc& mu,
const T_scale& sigma,
const T_alpha& alpha,
const T_beta& beta) {
94 template <
typename T_y,
typename T_loc,
typename T_scale,
typename T_alpha,
typename T_beta,
97 typename boost::math::tools::promote_args<T_y,T_loc,T_scale,T_alpha,T_beta>::type
98 trunc_normal_log(
const T_y& y,
const T_loc& mu,
const T_scale& sigma,
const T_alpha& alpha,
const T_beta& beta,
100 return trunc_normal_log<false>(y,mu,sigma,alpha,beta,Policy());
103 template <
typename T_y,
typename T_loc,
typename T_scale,
typename T_alpha,
typename T_beta>
105 typename boost::math::tools::promote_args<T_y,T_loc,T_scale,T_alpha,T_beta>::type
106 trunc_normal_log(
const T_y& y,
const T_loc& mu,
const T_scale& sigma,
const T_alpha& alpha,
const T_beta& beta) {
bool isinf(const stan::agrad::var v)
Checks if the given number is infinite.
var Phi(const stan::agrad::var &a)
The unit normal cumulative density function for variables (stan).
var log(const var &a)
Return the natural log of the specified variable (cmath).
boost::math::tools::promote_args< T >::type Phi(T x)
The unit normal cumulative distribution function.
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_greater(const char *function, const T_y &y, const T_low &low, const char *name, T_result *result, const Policy &)
boost::math::policies::policy default_policy
Default error-handling policy from Boost.
boost::math::tools::promote_args< T_y, T_loc, T_scale, T_alpha, T_beta >::type trunc_normal_log(const T_y &y, const T_loc &mu, const T_scale &sigma, const T_alpha &alpha, const T_beta &beta, const Policy &)
The log of the truncated normal density for the given y, mean, and standard deviation.
Probability, optimization and sampling library.
int isinf(const stan::agrad::var &a)
Checks if the given number is infinite.
Template metaprogram to calculate whether a summand needs to be included in a proportional (log) prob...