1#ifndef STAN_MATH_PRIM_PROB_BETA_LPDF_HPP
2#define STAN_MATH_PRIM_PROB_BETA_LPDF_HPP
43template <
bool propto,
typename T_y,
typename T_scale_succ,
44 typename T_scale_fail,
46 T_y, T_scale_succ, T_scale_fail>* =
nullptr>
48 const T_y& y,
const T_scale_succ& alpha,
const T_scale_fail&
beta) {
53 static constexpr const char* function =
"beta_lpdf";
55 "First shape parameter", alpha,
56 "Second shape parameter",
beta);
62 T_alpha_ref alpha_ref = alpha;
63 T_beta_ref beta_ref =
beta;
73 T_scale_fail>::value) {
81 T_partials_return logp(0);
89 logp +=
sum((alpha_val - 1.0) * log_y) * N /
max_size(y, alpha);
96 if constexpr (is_autodiff_v<T_y>) {
97 edge<0>(ops_partials).partials_
98 = (alpha_val - 1) / y_val + (beta_val - 1) / (y_val - 1);
102 const auto& alpha_beta
103 = to_ref_if<is_any_autodiff_v<T_scale_succ, T_scale_fail>>(alpha_val
106 if constexpr (is_any_autodiff_v<T_scale_succ, T_scale_fail>) {
107 const auto& digamma_alpha_beta
108 = to_ref_if<is_all_autodiff_v<T_scale_succ, T_scale_fail>>(
110 if constexpr (is_autodiff_v<T_scale_succ>) {
111 edge<1>(ops_partials).partials_
112 = log_y + digamma_alpha_beta -
digamma(alpha_val);
114 if constexpr (is_autodiff_v<T_scale_fail>) {
115 edge<2>(ops_partials).partials_
116 = log1m_y + digamma_alpha_beta -
digamma(beta_val);
120 return ops_partials.build(logp);
123template <
typename T_y,
typename T_scale_succ,
typename T_scale_fail>
125 const T_y& y,
const T_scale_succ& alpha,
const T_scale_fail&
beta) {
126 return beta_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_cl, T_scale_succ_cl, T_scale_fail_cl > beta_lpdf(const T_y_cl &y, const T_scale_succ_cl &alpha, const T_scale_fail_cl &beta)
The log of the beta density for the specified scalar(s) given the specified sample stan::math::size(s...
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.
void check_bounded(const char *function, const char *name, const T_y &y, const T_low &low, const T_high &high)
Check if the value is between the low and high values, inclusively.
T value_of(const fvar< T > &v)
Return the value of the specified variable.
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.
fvar< T > lgamma(const fvar< T > &x)
Return the natural logarithm of the gamma function applied to the specified argument.
auto sum(const std::vector< T > &m)
Return the sum of the entries of the specified standard vector.
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
int64_t max_size(const T1 &x1, const Ts &... xs)
Calculate the size of the largest input.
fvar< T > log1m(const fvar< T > &x)
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.
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< is_autodiff_v< T >, 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 ...
Template metaprogram to calculate whether a summand needs to be included in a proportional (log) prob...