1#ifndef STAN_MATH_PRIM_PROB_YULE_SIMON_LCCDF_HPP
2#define STAN_MATH_PRIM_PROB_YULE_SIMON_LCCDF_HPP
33template <
typename T_n,
typename T_alpha>
35 const T_alpha& alpha) {
39 static constexpr const char* function =
"yule_simon_lccdf";
48 T_alpha_ref alpha_ref = alpha;
53 const size_t max_size_seq_view =
max_size(n_ref, alpha_ref);
58 if (n_vec.val(i) < 1.0) {
61 if (n_vec.val(i) == std::numeric_limits<int>::max()) {
66 T_partials_return log_ccdf(0.0);
68 for (
size_t i = 0; i < max_size_seq_view; i++) {
69 auto np1 = n_vec.val(i) + 1.0;
70 auto ap1 = alpha_vec.val(i) + 1.0;
71 auto nap1 = n_vec.val(i) + ap1;
74 if constexpr (is_autodiff_v<T_alpha>) {
79 return ops_partials.build(log_ccdf);
scalar_seq_view provides a uniform sequence-like wrapper around either a scalar or a sequence of scal...
return_type_t< T_alpha > yule_simon_lccdf(const T_n &n, const T_alpha &alpha)
Returns the log CCDF of the Yule-Simon distribution with shape parameter.
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
int64_t size(const T &m)
Returns the size (number of the elements) of a matrix_cl or var_value<matrix_cl<T>>.
static constexpr double negative_infinity()
Return negative infinity.
bool size_zero(const T &x)
Returns 1 if input is of length 0, returns 0 otherwise.
void check_consistent_sizes(const char *)
Trivial no input case, this function is a no-op.
fvar< T > lgamma(const fvar< T > &x)
Return the natural logarithm of the gamma function applied to the specified argument.
int64_t max_size(const T1 &x1, const Ts &... xs)
Calculate the size of the largest input.
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 > digamma(const fvar< T > &x)
Return the derivative of the log gamma function at the specified argument.
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 ...