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>
18 template <
bool propto,
20 typename boost::math::tools::promote_args<T_prob>::type
22 const Eigen::Matrix<T_prob, Eigen::Dynamic, 1>&
24 static const char*
function(
"categorical_logit_log");
26 check_bounded(
function,
"categorical outcome out of support", n,
37 template <
typename T_prob>
39 typename boost::math::tools::promote_args<T_prob>::type
41 const Eigen::Matrix<T_prob, Eigen::Dynamic, 1>&
43 return categorical_logit_log<false>(n, beta);
46 template <
bool propto,
48 typename boost::math::tools::promote_args<T_prob>::type
50 const Eigen::Matrix<T_prob, Eigen::Dynamic, 1>&
52 static const char*
function(
"categorical_logit_log");
54 for (
size_t k = 0; k < ns.size(); ++k)
56 ns[k], 1, beta.size());
65 Eigen::Matrix<T_prob, Eigen::Dynamic, 1> log_softmax_beta
69 Eigen::Matrix<typename boost::math::tools::promote_args<T_prob>::type,
70 Eigen::Dynamic, 1> results(ns.size());
71 for (
size_t i = 0; i < ns.size(); ++i)
72 results[i] = log_softmax_beta(ns[i] - 1);
76 template <
typename T_prob>
78 typename boost::math::tools::promote_args<T_prob>::type
80 const Eigen::Matrix<T_prob, Eigen::Dynamic, 1>&
82 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.