1#ifndef STAN_MATH_PRIM_PROB_FRECHET_LCCDF_HPP
2#define STAN_MATH_PRIM_PROB_FRECHET_LCCDF_HPP
17#include <boost/random/weibull_distribution.hpp>
18#include <boost/random/variate_generator.hpp>
25template <
typename T_y,
typename T_shape,
typename T_scale,
27 T_y, T_shape, T_scale>* =
nullptr>
30 const T_scale& sigma) {
35 static constexpr const char* function =
"frechet_lccdf";
37 T_alpha_ref alpha_ref = alpha;
38 T_sigma_ref sigma_ref = sigma;
44 if (
size_zero(y_ref, alpha_ref, sigma_ref)) {
48 T_partials_return ccdf_log(0.0);
54 size_t N =
max_size(y_ref, sigma_ref, alpha_ref);
56 for (
size_t n = 0; n < N; n++) {
57 const T_partials_return y_dbl = y_vec.val(n);
58 const T_partials_return sigma_dbl = sigma_vec.val(n);
59 const T_partials_return alpha_dbl = alpha_vec.val(n);
60 const T_partials_return pow_n =
pow(sigma_dbl / y_dbl, alpha_dbl);
61 const T_partials_return exp_n =
exp(-pow_n);
63 ccdf_log +=
log1m(exp_n);
65 const T_partials_return rep_deriv = pow_n / (1.0 / exp_n - 1);
67 partials<0>(ops_partials)[n] -= alpha_dbl / y_dbl * rep_deriv;
70 partials<1>(ops_partials)[n] -=
log(y_dbl / sigma_dbl) * rep_deriv;
73 partials<2>(ops_partials)[n] += alpha_dbl / sigma_dbl * rep_deriv;
76 return ops_partials.build(ccdf_log);
scalar_seq_view provides a uniform sequence-like wrapper around either a scalar or a sequence of scal...
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_cl, T_shape_cl, T_scale_cl > frechet_lccdf(const T_y_cl &y, const T_shape_cl &alpha, const T_scale_cl &sigma)
Returns the frechet log complementary cumulative distribution function for the given location,...
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.
auto pow(const T1 &x1, const T2 &x2)
fvar< T > log(const fvar< T > &x)
void check_positive(const char *function, const char *name, const T_y &y)
Check if y is positive.
int64_t max_size(const T1 &x1, const Ts &... xs)
Calculate the size of the largest input.
fvar< T > log1m(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.
fvar< T > exp(const fvar< T > &x)
typename ref_type_if< true, T >::type ref_type_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...