1 #ifndef __STAN__PROB__DISTRIBUTIONS__UNIVARIATE__CONTINUOUS__SCALED_INV_CHI_SQUARE_HPP__
2 #define __STAN__PROB__DISTRIBUTIONS__UNIVARIATE__CONTINUOUS__SCALED_INV_CHI_SQUARE_HPP__
34 template <
bool propto,
35 typename T_y,
typename T_dof,
typename T_scale,
40 static const char*
function
41 =
"stan::prob::scaled_inv_chi_square_log(%1%)";
56 if (!
check_not_nan(
function, y,
"Random variable", &logp, Policy()))
58 if (!
check_finite(
function, nu,
"Degrees of freedom parameter", &logp, Policy()))
60 if (!
check_positive(
function, nu,
"Degrees of freedom parameter", &logp, Policy()))
62 if (!
check_finite(
function, s,
"Scale parameter", &logp, Policy()))
64 if (!
check_positive(
function, s,
"Scale parameter", &logp, Policy()))
68 "Random variable",
"Degrees of freedom parameter",
"Scale parameter",
81 for (
size_t n = 0; n < N; n++) {
89 for (
size_t n = 0; n < N; n++) {
95 logp += nu_vec[n] *
log(s_vec[n]);
99 logp -= nu_vec[n] * 0.5 *
square(s_vec[n]) / y_vec[n];
104 template <
bool propto,
105 typename T_y,
typename T_dof,
typename T_scale>
109 return scaled_inv_chi_square_log<propto>(y,nu,s,
113 template <
typename T_y,
typename T_dof,
typename T_scale,
119 return scaled_inv_chi_square_log<false>(y,nu,s,Policy());
122 template <
typename T_y,
typename T_dof,
typename T_scale>
126 return scaled_inv_chi_square_log<false>(y,nu,s,
var multiply_log(const var &a, const var &b)
Return the value of a*log(b).
var square(const var &x)
Return the square of the input variable.
double value_of(const agrad::var &v)
Return the value of the specified variable.
var lgamma(const stan::agrad::var &a)
The log gamma function for variables (C99).
var log(const var &a)
Return the natural log of the specified variable (cmath).
boost::math::tools::promote_args< T_a, T_b >::type multiply_log(T_a a, T_b b)
double value_of(T x)
Return the value of the specified scalar argument converted to a double value.
T square(T x)
Return the square of the specified argument.
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_dof, T_scale >::type scaled_inv_chi_square_log(const T_y &y, const T_dof &nu, const T_scale &s, const Policy &)
The log of a scaled inverse chi-squared density for y with the specified degrees of freedom parameter...
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