1#ifndef STAN_MATH_PRIM_PROB_CATEGORICAL_LOGIT_LPMF_HPP
2#define STAN_MATH_PRIM_PROB_CATEGORICAL_LOGIT_LPMF_HPP
16template <
bool propto,
typename T_prob, require_col_vector_t<T_prob>* =
nullptr>
18 static constexpr const char* function =
"categorical_logit_lpmf";
19 check_bounded(function,
"categorical outcome out of support", n, 1,
29 return beta_ref.coeff(n - 1)
33template <
bool propto,
typename T_prob, require_col_vector_t<T_prob>* =
nullptr>
36 static constexpr const char* function =
"categorical_logit_lpmf";
38 check_bounded(function,
"categorical outcome out of support", ns, 1,
54 Eigen::Matrix<return_type_t<T_prob>, Eigen::Dynamic, 1>
results(ns.size());
55 for (
size_t i = 0; i < ns.size(); ++i) {
56 results[i] = log_softmax_beta(ns[i] - 1);
61template <
typename T_n,
typename T_prob, require_st_
integral<T_n>* =
nullptr,
62 require_col_vector_t<T_prob>* =
nullptr>
65 return categorical_logit_lpmf<false>(ns,
beta);
results_cl< T_results... > results(T_results &&... results)
Deduces types for constructing results_cl object.
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
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.
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.
auto sum(const std::vector< T > &m)
Return the sum of the entries of the specified standard vector.
auto log_softmax(const T &x)
Return the log softmax of the specified vector or container of vectors.
return_type_t< T_prob > categorical_logit_lpmf(int n, const T_prob &beta)
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)
typename ref_type_if< true, T >::type ref_type_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...