logsumexp: Log Sum of Exponentials

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/logsumexp.R

Description

Compute log( exp(x)+exp(y) ) without floating overflow or underflow

Usage

1
logsumexp(x, y)

Arguments

x

a numeric vector or matrix.

y

a numeric vector or matrix of same size as x.

Details

The computation uses logcosh().

Value

Numeric vector or matrix of same dimensions as x.

Author(s)

Gordon K Smyth

See Also

logcosh

Examples

1
2
3
x <- y <- c(1e-8,1e-7,1e-6,1e-5,1e-4,1,3,50,800)
logsumexp(x,y)
log( exp(x)+exp(y) )

Example output

[1]   0.6931472   0.6931473   0.6931482   0.6931572   0.6932472   1.6931472
[7]   3.6931472  50.6931472 800.6931472
[1]  0.6931472  0.6931473  0.6931482  0.6931572  0.6932472  1.6931472  3.6931472
[8] 50.6931472        Inf

limma documentation built on Nov. 8, 2020, 8:28 p.m.