1#ifndef STAN_MATH_PRIM_PROB_MULTINOMIAL_LOGIT_LPMF_HPP
2#define STAN_MATH_PRIM_PROB_MULTINOMIAL_LOGIT_LPMF_HPP
23template <
bool propto,
typename T_beta,
typename T_prob = scalar_type_t<T_beta>,
24 require_eigen_col_vector_t<T_beta>* =
nullptr>
27 static constexpr const char* function =
"multinomial_logit_lpmf";
29 "rows of log-probabilities parameter",
beta.rows());
32 check_finite(function,
"log-probabilities parameter", beta_ref);
39 lp +=
lgamma(1 + ns_map.sum()) -
lgamma(1 + ns_map).sum();
44 for (
unsigned int i = 0; i < ns.size(); ++i) {
46 lp += ns[i] * (beta_ref.coeff(i) - alpha);
54template <
typename T_beta, require_eigen_col_vector_t<T_beta>* =
nullptr>
57 return multinomial_logit_lpmf<false>(ns,
beta);
return_type_t< T_prob > multinomial_logit_lpmf(const std::vector< int > &ns, const T_beta &beta)
Multinomial log PMF in log parametrization.
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
T as_array_or_scalar(T &&v)
Returns specified input value.
void check_nonnegative(const char *function, const char *name, const T_y &y)
Check if y is non-negative.
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
void check_finite(const char *function, const char *name, const T_y &y)
Return true if all values in y are finite.
fvar< T > lgamma(const fvar< T > &x)
Return the natural logarithm of the gamma function applied to the specified argument.
void check_size_match(const char *function, const char *name_i, T_size1 i, const char *name_j, T_size2 j)
Check if the provided sizes match.
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 > log_sum_exp(const fvar< T > &x1, const fvar< T > &x2)
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...