1 #ifndef __STAN__PROB__DISTRIBUTIONS__PARETO_HPP__
2 #define __STAN__PROB__DISTRIBUTIONS__PARETO_HPP__
16 template <
bool propto,
17 typename T_y,
typename T_scale,
typename T_shape,
20 pareto_log(
const T_y& y,
const T_scale& y_min,
const T_shape& alpha,
22 static const char*
function =
"stan::prob::pareto_log(%1%)";
41 if (!
check_not_nan(
function, y,
"Random variable", &logp, Policy()))
57 "Random variable",
"Scale parameter",
"Shape parameter",
68 size_t N =
max_size(y, y_min, alpha);
70 for (
size_t n = 0; n < N; n++) {
71 if (y_vec[n] < y_min_vec[n])
80 for (
size_t n = 0; n <
length(y); n++)
84 for (
size_t n = 0; n <
length(y); n++)
89 for (
size_t n = 0; n <
length(y_min); n++)
93 for (
size_t n = 0; n <
length(alpha); n++)
98 for (
size_t n = 0; n <
length(alpha); n++)
99 inv_alpha[n] = 1 /
value_of(alpha_vec[n]);
103 for (
size_t n = 0; n < N; n++) {
104 const double alpha_dbl =
value_of(alpha_vec[n]);
107 logp += log_alpha[n];
109 logp += alpha_dbl * log_y_min[n];
111 logp -= alpha_dbl * log_y[n] + log_y[n];
115 operands_and_partials.
d_x1[n] -= alpha_dbl * inv_y[n] + inv_y[n];
117 operands_and_partials.
d_x2[n] += alpha_dbl /
value_of(y_min_vec[n]);
119 operands_and_partials.
d_x3[n] += 1 / alpha_dbl + log_y_min[n] - log_y[n];
121 return operands_and_partials.
to_var(logp);
125 template <
bool propto,
126 typename T_y,
typename T_scale,
typename T_shape>
129 pareto_log(
const T_y& y,
const T_scale& y_min,
const T_shape& alpha) {
133 template <
typename T_y,
typename T_scale,
typename T_shape,
137 pareto_log(
const T_y& y,
const T_scale& y_min,
const T_shape& alpha,
139 return pareto_log<false>(y,y_min,alpha,Policy());
142 template <
typename T_y,
typename T_scale,
typename T_shape>
145 pareto_log(
const T_y& y,
const T_scale& y_min,
const T_shape& alpha) {
double value_of(const agrad::var &v)
Return the value of the specified variable.
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.
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_scale, T_shape >::type pareto_log(const T_y &y, const T_scale &y_min, const T_shape &alpha, const Policy &)
Probability, optimization and sampling library.
size_t length(const T &x)
size_t max_size(const T1 &x1, const T2 &x2)
A variable implementation that stores operands and derivatives with respect to the variable.
VectorView< double *, is_vector< T1 >::value > d_x1
VectorView< double *, is_vector< T2 >::value > d_x2
T_return_type to_var(double logp)
VectorView< double *, is_vector< T3 >::value > d_x3
Metaprogram to determine if a type has a base scalar type that can be assigned to type double.
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