1#ifndef STAN_MATH_PRIM_FUN_SOFTMAX_HPP
2#define STAN_MATH_PRIM_FUN_SOFTMAX_HPP
45template <
typename ColVec,
46 require_eigen_col_vector_vt<std::is_arithmetic, ColVec>* =
nullptr>
52 const auto& v_ref =
to_ref(v);
53 const auto theta = (v_ref.array() - v_ref.maxCoeff()).
exp().eval();
54 return theta.array() / theta.sum();
auto softmax(const ColVec &alpha)
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
fvar< T > exp(const fvar< T > &x)
typename plain_type< T >::type plain_type_t
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...