Automatic Differentiation
 
Loading...
Searching...
No Matches

◆ softmax() [4/5]

template<typename ColVec , require_eigen_col_vector_vt< std::is_arithmetic, ColVec > * = nullptr>
plain_type_t< ColVec > stan::math::softmax ( const ColVec &  v)
inline

Return the softmax of the specified vector.

\( \mbox{softmax}(y) = \frac{\exp(y)} {\sum_{k=1}^K \exp(y_k)}, \)

The entries in the Jacobian of the softmax function are given by \( \begin{array}{l} \displaystyle \frac{\partial}{\partial y_m} \mbox{softmax}(y)[k] \\[8pt] \displaystyle \mbox{ } \ \ \ = \left\{ \begin{array}{ll} \mbox{softmax}(y)[k] \times (1 - \mbox{softmax}(y)[m]) & \mbox{ if } m = k, \mbox{ and} \\[6pt] -\mbox{softmax}(y)[k] \times \mbox{softmax}(y)[m] & \mbox{ if } m \neq k. \end{array} \right. \end{array} \)

Template Parameters
ColVectype of elements in the vector
Parameters
[in]vVector to transform.
Returns
Unit simplex result of the softmax transform of the vector.

Definition at line 47 of file softmax.hpp.