1#ifndef STAN_MATH_PRIM_PROB_LOGLOGISTIC_LPDF_HPP
2#define STAN_MATH_PRIM_PROB_LOGLOGISTIC_LPDF_HPP
42template <
bool propto,
typename T_y,
typename T_scale,
typename T_shape,
44 T_y, T_scale, T_shape>* =
nullptr>
47 const T_shape&
beta) {
53 static constexpr const char* function =
"loglogistic_lpdf";
55 alpha,
"Shape parameter",
beta);
58 T_scale_ref alpha_ref = alpha;
59 T_shape_ref beta_ref =
beta;
79 = to_ref_if<!is_constant_all<T_y, T_scale>::value>(
inv(alpha_val));
80 const auto& y_div_alpha
81 = to_ref_if<!is_constant_all<T_shape>::value>(y_val * inv_alpha);
82 const auto& y_div_alpha_pow_beta
83 = to_ref_if<!is_constant_all<T_shape>::value>(
pow(y_div_alpha, beta_val));
85 = to_ref_if<!is_constant_all<T_y, T_scale, T_shape>::value>(
86 1 + y_div_alpha_pow_beta);
87 const auto& log_y = to_ref_if<!is_constant_all<T_shape>::value>(
log(y_val));
89 = to_ref_if<include_summand<propto, T_scale, T_shape>::value>(
91 const auto& beta_minus_one
98 T_partials_return logp =
sum(beta_minus_one * log_y - 2.0 *
log(log1_arg));
101 logp +=
sum(N * (
log(beta_val) - log_alpha - beta_minus_one * log_alpha)
106 const auto& two_inv_log1_arg
107 = to_ref_if<!is_constant_all<T_y>::value
110 >= 2>(2.0 *
inv(log1_arg));
112 const auto& y_pow_beta = to_ref_if<!is_constant_all<T_y, T_scale>::value>(
113 pow(y_val, beta_val));
114 const auto& inv_alpha_pow_beta
115 = to_ref_if < !is_constant_all<T_y>::value
119 const auto& inv_y =
inv(y_val);
120 const auto& y_deriv = beta_minus_one * inv_y
122 * (beta_val * inv_alpha_pow_beta)
123 * y_pow_beta * inv_y;
124 partials<0>(ops_partials) = y_deriv;
127 const auto& alpha_deriv = -beta_val * inv_alpha
128 - two_inv_log1_arg * y_pow_beta * (-beta_val)
129 * inv_alpha_pow_beta * inv_alpha;
130 partials<1>(ops_partials) = alpha_deriv;
134 const auto& beta_deriv
135 = (1.0 *
inv(beta_val)) + log_y - log_alpha
136 - two_inv_log1_arg * y_div_alpha_pow_beta *
log(y_div_alpha);
137 partials<2>(ops_partials) = beta_deriv;
140 return ops_partials.build(logp);
143template <
typename T_y,
typename T_scale,
typename T_shape>
145 const T_y& y,
const T_scale& alpha,
const T_shape&
beta) {
146 return loglogistic_lpdf<false>(y, alpha,
beta);
require_all_not_t< is_nonscalar_prim_or_rev_kernel_expression< std::decay_t< Types > >... > require_all_not_nonscalar_prim_or_rev_kernel_expression_t
Require none of the types satisfy is_nonscalar_prim_or_rev_kernel_expression.
return_type_t< T_y, T_scale, T_shape > loglogistic_lpdf(const T_y &y, const T_scale &alpha, const T_shape &beta)
The log of the loglogistic density for the specified scalar(s) given the specified scales(s) and shap...
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
bool size_zero(const T &x)
Returns 1 if input is of length 0, returns 0 otherwise.
T to_ref_if(T &&a)
No-op that should be optimized away.
auto pow(const T1 &x1, const T2 &x2)
fvar< T > log(const fvar< T > &x)
auto as_value_column_array_or_scalar(T &&a)
Extract the value from an object and for eigen vectors and std::vectors convert to an eigen column ar...
void check_consistent_sizes(const char *)
Trivial no input case, this function is a no-op.
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
auto sum(const std::vector< T > &m)
Return the sum of the entries of the specified standard vector.
int64_t max_size(const T1 &x1, const Ts &... xs)
Calculate the size of the largest input.
fvar< T > beta(const fvar< T > &x1, const fvar< T > &x2)
Return fvar with the beta function applied to the specified arguments and its gradient.
fvar< T > inv(const fvar< T > &x)
auto make_partials_propagator(Ops &&... ops)
Construct an partials_propagator.
void check_positive_finite(const char *function, const char *name, const T_y &y)
Check if y is positive and finite.
typename ref_type_if<!is_constant< T >::value, T >::type ref_type_if_not_constant_t
typename partials_return_type< Args... >::type partials_return_t
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Extends std::true_type when instantiated with zero or more template parameters, all of which extend t...
Template metaprogram to calculate whether a summand needs to be included in a proportional (log) prob...