1 #ifndef STAN_MATH_PRIM_MAT_PROB_CATEGORICAL_LOGIT_LOG_HPP
2 #define STAN_MATH_PRIM_MAT_PROB_CATEGORICAL_LOGIT_LOG_HPP
11 #include <boost/math/tools/promotion.hpp>
19 template <
bool propto,
21 typename boost::math::tools::promote_args<T_prob>::type
23 const Eigen::Matrix<T_prob, Eigen::Dynamic, 1>&
25 static const char*
function(
"stan::math::categorical_logit_log");
31 check_bounded(
function,
"categorical outcome out of support", n,
42 template <
typename T_prob>
44 typename boost::math::tools::promote_args<T_prob>::type
46 const Eigen::Matrix<T_prob, Eigen::Dynamic, 1>&
48 return categorical_logit_log<false>(n, beta);
51 template <
bool propto,
53 typename boost::math::tools::promote_args<T_prob>::type
55 const Eigen::Matrix<T_prob, Eigen::Dynamic, 1>&
57 static const char*
function(
"stan::math::categorical_logit_log");
64 for (
size_t k = 0; k < ns.size(); ++k)
66 ns[k], 1, beta.size());
75 Eigen::Matrix<T_prob, Eigen::Dynamic, 1> log_softmax_beta
79 Eigen::Matrix<typename boost::math::tools::promote_args<T_prob>::type,
80 Eigen::Dynamic, 1> results(ns.size());
81 for (
size_t i = 0; i < ns.size(); ++i)
82 results[i] = log_softmax_beta(ns[i] - 1);
86 template <
typename T_prob>
88 typename boost::math::tools::promote_args<T_prob>::type
90 const Eigen::Matrix<T_prob, Eigen::Dynamic, 1>&
92 return categorical_logit_log<false>(ns, beta);
fvar< T > sum(const std::vector< fvar< T > > &m)
Return the sum of the entries of the specified standard vector.
boost::math::tools::promote_args< T_prob >::type categorical_logit_log(int n, const Eigen::Matrix< T_prob, Eigen::Dynamic, 1 > &beta)
bool check_bounded(const char *function, const char *name, const T_y &y, const T_low &low, const T_high &high)
Return true if the value is between the low and high values, inclusively.
Eigen::Matrix< fvar< T >, Eigen::Dynamic, 1 > log_softmax(const Eigen::Matrix< fvar< T >, Eigen::Dynamic, 1 > &alpha)
fvar< T > log_sum_exp(const std::vector< fvar< T > > &v)
Template metaprogram to calculate whether a summand needs to be included in a proportional (log) prob...
bool check_finite(const char *function, const char *name, const T_y &y)
Return true if y is finite.