1 #ifndef STAN__PROB__DISTRIBUTIONS__MULTIVARIATE__DISCRETE__CATEGORICAL_LOGIT_LOG_HPP
2 #define STAN__PROB__DISTRIBUTIONS__MULTIVARIATE__DISCRETE__CATEGORICAL_LOGIT_LOG_HPP
5 #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>& beta) {
23 static const char*
function =
"stan::prob::categorical_logit_log(%1%)";
31 "categorical outcome out of support",
43 template <
typename T_prob>
45 typename boost::math::tools::promote_args<T_prob>::type
47 const Eigen::Matrix<T_prob,Eigen::Dynamic,1>& beta) {
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>& beta) {
56 static const char*
function =
"stan::prob::categorical_logit_log(%1%)";
64 for (
size_t k = 0; k < ns.size(); ++k)
66 "categorical outcome out of support",
77 Eigen::Matrix<T_prob,Eigen::Dynamic,1> log_softmax_beta
81 Eigen::Matrix<typename boost::math::tools::promote_args<T_prob>::type,
82 Eigen::Dynamic,1> results(ns.size());
83 for (
size_t i = 0; i < ns.size(); ++i)
84 results[i] = log_softmax_beta(ns[i] - 1);
88 template <
typename T_prob>
90 typename boost::math::tools::promote_args<T_prob>::type
92 const Eigen::Matrix<T_prob,Eigen::Dynamic,1>& beta) {
93 return categorical_logit_log<false>(ns,beta);
bool check_bounded(const char *function, const T_y &y, const T_low &low, const T_high &high, const char *name, T_result *result)
fvar< T > log_sum_exp(const fvar< T > &x1, const fvar< T > &x2)
boost::math::tools::promote_args< T1, T2 >::type log_sum_exp(const T2 &a, const T1 &b)
Calculates the log sum of exponetials without overflow.
boost::math::tools::promote_args< T_prob >::type categorical_logit_log(int n, const Eigen::Matrix< T_prob, Eigen::Dynamic, 1 > &beta)
bool check_finite(const char *function, const T_y &y, const char *name, T_result *result)
Checks if the variable y is finite.
Eigen::Matrix< fvar< T >, Eigen::Dynamic, 1 > log_softmax(const Eigen::Matrix< fvar< T >, Eigen::Dynamic, 1 > &alpha)
fvar< T > sum(const Eigen::Matrix< fvar< T >, R, C > &m)
Template metaprogram to calculate whether a summand needs to be included in a proportional (log) prob...
Eigen::Matrix< T, Eigen::Dynamic, 1 > log_softmax(const Eigen::Matrix< T, Eigen::Dynamic, 1 > &v)
Return the natural logarithm of the softmax of the specified vector.
double sum(std::vector< double > &x)