logsumexp | R Documentation |
Efficient implementation (via Fortran) of the log-sum-exp function.
logsumexp(x, v = NULL)
x |
a matrix of dimension |
v |
an optional vector of length |
Given the matrix x
, for each row x_{[i]} = [x_1, \dots, x_k]
(with i=1,\dots,n
), the log-sum-exp (LSE) function calculates
\text{LSE}(x_{[i]}) = \log \sum_{j=1}^k \exp(x_j + v_j) = m + \log \sum_{j=1}^k \exp(x_j + v_j - m)
where m = \max(x_1+v_1, \dots, x_k+v_k)
.
Returns a vector of values of length equal to the number of rows of x
.
Luca Scrucca
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. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1093/imanum/draa038")}
softmax
x = matrix(rnorm(15), 5, 3)
v = log(c(0.5, 0.3, 0.2))
logsumexp(x, v)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.