| logsumexp | R Documentation |
For each row l of a matrix x, calculate log(sum(exp(l))).
logsumexp(x)
x |
matrix, the values in x a all logged. If x is a numeric vector, it will be converted to a matrix with 1 row. |
numeric, the logsumexp of each row of x.
## Normalize the rows of x to make them sum up to 1 x <- matrix(runif(6,-1000,-20),nrow=2) x <- x-logsumexp(x) x <- exp(x) rowSums(x)