Learn R Programming

bbricks (version 0.1.4)

logsumexp: log sum exp

Description

For each row l of a matrix x, calculate log(sum(exp(l))).

Usage

logsumexp(x)

Arguments

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.

Value

numeric, the logsumexp of each row of x.

Examples

Run this code
# NOT RUN {
## 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)
# }

Run the code above in your browser using DataLab