1 #ifndef __STAN__PROB__DISTRIBUTIONS__WEIBULL_HPP__
2 #define __STAN__PROB__DISTRIBUTIONS__WEIBULL_HPP__
17 template <
bool propto,
18 typename T_y,
typename T_shape,
typename T_scale,
21 weibull_log(
const T_y& y,
const T_shape& alpha,
const T_scale& sigma,
23 static const char*
function =
"stan::prob::weibull_log(%1%)";
39 if(!
check_finite(
function, y,
"Random variable", &logp, Policy()))
55 "Random variable",
"Shape parameter",
"Scale parameter",
66 size_t N =
max_size(y, alpha, sigma);
68 for (
size_t n = 0; n < N; n++) {
69 const double y_dbl =
value_of(y_vec[n]);
76 for (
size_t n = 0; n < N; n++) {
78 logp +=
log(alpha_vec[n]);
84 logp -=
pow(y_vec[n] / sigma_vec[n], alpha_vec[n]);
90 template <
bool propto,
91 typename T_y,
typename T_shape,
typename T_scale>
94 weibull_log(
const T_y& y,
const T_shape& alpha,
const T_scale& sigma) {
99 template <
typename T_y,
typename T_shape,
typename T_scale,
103 weibull_log(
const T_y& y,
const T_shape& alpha,
const T_scale& sigma,
105 return weibull_log<false>(y,alpha,sigma,Policy());
109 template <
typename T_y,
typename T_shape,
typename T_scale>
112 weibull_log(
const T_y& y,
const T_shape& alpha,
const T_scale& sigma) {
119 template <
typename T_y,
typename T_shape,
typename T_scale,
121 typename boost::math::tools::promote_args<T_y,T_shape,T_scale>::type
122 weibull_cdf(
const T_y& y,
const T_shape& alpha,
const T_scale& sigma,
125 static const char*
function =
"stan::prob::weibull_cdf(%1%)";
129 using boost::math::tools::promote_args;
131 typename promote_args<T_y,T_shape,T_scale>::type lp;
147 return 1.0 -
exp(-
pow(y / sigma, alpha));
150 template <
typename T_y,
typename T_shape,
typename T_scale>
152 typename boost::math::tools::promote_args<T_y,T_shape,T_scale>::type
153 weibull_cdf(
const T_y& y,
const T_shape& alpha,
const T_scale& sigma) {
var multiply_log(const var &a, const var &b)
Return the value of a*log(b).
double value_of(const agrad::var &v)
Return the value of the specified variable.
var pow(const var &base, const var &exponent)
Return the base raised to the power of the exponent (cmath).
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).
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.
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.
boost::math::tools::promote_args< T_y, T_shape, T_scale >::type weibull_cdf(const T_y &y, const T_shape &alpha, const T_scale &sigma, const Policy &)
return_type< T_y, T_shape, T_scale >::type weibull_log(const T_y &y, const T_shape &alpha, const T_scale &sigma, const Policy &)
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