logsumexp: log sum exp

Description Usage Arguments Value Examples

View source: R/Bayesian_Bricks.r

Description

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

Usage

1

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

1
2
3
4
5
## 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)

bbricks documentation built on July 8, 2020, 7:29 p.m.