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

◆ log_softmax() [4/4]

template<typename Container , require_st_arithmetic< Container > * = nullptr, require_container_t< Container > * = nullptr>
auto stan::math::log_softmax ( const Container &  x)
inline

Return the natural logarithm of the softmax of the specified vector.

\( \log \mbox{softmax}(y) \ = \ y - \log \sum_{k=1}^K \exp(y_k) \ = \ y - \mbox{log\_sum\_exp}(y). \)

For the log softmax function, the entries in the Jacobian are \( \frac{\partial}{\partial y_m} \mbox{softmax}(y)[k] = \left\{ \begin{array}{ll} 1 - \mbox{softmax}(y)[m] & \mbox{ if } m = k, \mbox{ and} \\[6pt] \mbox{softmax}(y)[m] & \mbox{ if } m \neq k. \end{array} \right. \)

Template Parameters
Containertype of input vector to transform
Parameters
[in]xvector to transform
Returns
log unit simplex result of the softmax transform of the vector.

Definition at line 44 of file log_softmax.hpp.