softmax {mclust} | R Documentation |
Softmax function
Description
Efficient implementation (via Fortran) of the softmax (aka multinomial logistic) function converting a set of numerical values to probabilities summing to 1.
Usage
softmax(x, v = NULL)
Arguments
x |
a matrix of dimension |
v |
an optional vector of length |
Details
Given the matrix x
, for each row (with
), the softmax function calculates
Value
Returns a matrix of the same dimension as x
with values in the range that sum to 1 along the rows.
Author(s)
Luca Scrucca
References
Blanchard P., Higham D. J., Higham N. J. (2021). Accurately computing the log-sum-exp and softmax functions. IMA Journal of Numerical Analysis, 41/4:2311–2330. doi:10.1093/imanum/draa038
See Also
Examples
x = matrix(rnorm(15), 5, 3)
v = log(c(0.5, 0.3, 0.2))
(z = softmax(x, v))
rowSums(z)