1#ifndef STAN_MATH_PRIM_PROB_CATEGORICAL_LPMF_HPP
2#define STAN_MATH_PRIM_PROB_CATEGORICAL_LPMF_HPP
15template <
bool propto,
typename T_prob,
16 require_eigen_col_vector_t<T_prob>* =
nullptr>
18 static constexpr const char* function =
"categorical_lpmf";
21 check_bounded(function,
"Number of categories", n, 1, theta.size());
26 return log(theta_ref.coeff(n - 1));
31template <
bool propto,
typename T_prob,
34 const T_prob& theta) {
35 static constexpr const char* function =
"categorical_lpmf";
37 check_bounded(function,
"element of outcome array", ns, 1, theta.size());
49 Eigen::Matrix<value_type_t<T_prob>, Eigen::Dynamic, 1> log_theta
51 Eigen::Matrix<return_type_t<T_prob>, Eigen::Dynamic, 1> log_theta_ns(
53 for (
size_t i = 0; i < ns.size(); ++i) {
54 log_theta_ns(i) = log_theta(ns[i] - 1);
57 return sum(log_theta_ns);
60template <
typename T_n,
typename T_prob, require_st_
integral<T_n>* =
nullptr,
61 require_eigen_col_vector_t<T_prob>* =
nullptr>
63 const T_prob& theta) {
64 return categorical_lpmf<false>(ns, theta);
require_t< is_eigen_col_vector< std::decay_t< T > > > require_eigen_col_vector_t
Require type satisfies is_eigen_col_vector.
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.
return_type_t< T_prob > categorical_lpmf(int n, const T_prob &theta)
T value_of(const fvar< T > &v)
Return the value of the specified variable.
fvar< T > log(const fvar< T > &x)
void check_simplex(const char *function, const char *name, const T &theta)
Throw an exception if the specified vector is not a simplex.
auto sum(const std::vector< T > &m)
Return the sum of the entries of the specified standard vector.
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...