1 #ifndef STAN_MATH_PRIM_MAT_FUN_SOFTMAX_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_SOFTMAX_HPP
45 inline Eigen::Matrix<T, Eigen::Dynamic, 1>
46 softmax(
const Eigen::Matrix<T, Eigen::Dynamic, 1>& v) {
49 Eigen::Matrix<T, Eigen::Dynamic, 1> theta(v.size());
51 T max_v = v.maxCoeff();
52 for (
int i = 0; i < v.size(); ++i) {
53 theta(i) =
exp(v(i) - max_v);
56 for (
int i = 0; i < v.size(); ++i)
fvar< T > sum(const std::vector< fvar< T > > &m)
Return the sum of the entries of the specified standard vector.
Eigen::Matrix< fvar< T >, Eigen::Dynamic, 1 > softmax(const Eigen::Matrix< fvar< T >, Eigen::Dynamic, 1 > &alpha)
bool check_nonzero_size(const char *function, const char *name, const T_y &y)
Return true if the specified matrix/vector is of non-zero size.
fvar< T > exp(const fvar< T > &x)