Stan Math Library  2.20.0
reverse mode automatic differentiation
log_softmax.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_LOG_SOFTMAX_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_LOG_SOFTMAX_HPP
3 
7 
8 namespace stan {
9 namespace math {
10 
39 template <typename T>
40 inline Eigen::Matrix<T, Eigen::Dynamic, 1> log_softmax(
41  const Eigen::Matrix<T, Eigen::Dynamic, 1>& v) {
42  check_nonzero_size("log_softmax", "v", v);
43  return v.array() - log_sum_exp(v);
44 }
45 
46 } // namespace math
47 } // namespace stan
48 #endif
void check_nonzero_size(const char *function, const char *name, const T_y &y)
Check if the specified matrix/vector is of non-zero size.
Eigen::Matrix< fvar< T >, Eigen::Dynamic, 1 > log_softmax(const Eigen::Matrix< fvar< T >, Eigen::Dynamic, 1 > &alpha)
Definition: log_softmax.hpp:14
fvar< T > log_sum_exp(const std::vector< fvar< T > > &v)
Definition: log_sum_exp.hpp:12

     [ Stan Home Page ] © 2011–2018, Stan Development Team.