logsumexp {bbricks}R Documentation

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


## 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)


[Package bbricks version 0.1.4 Index]