logAdd: Overflow-safe computation of the logarithm of a sum

Description Usage Arguments Value Examples

View source: R/mBPCR.R

Description

Function to compute the logarithm of a sum of small numbers, avoiding overflow.

Usage

1
  logAdd(x)

Arguments

x

array or matrix containing the logarithm of the terms of the sum. If x is a matrix, the function return the results by column.

Value

If x is an array, the function returns log(sum_i(e^x[i])), otherwise it returns an array containing the results by column.

Examples

1
2
3
4
5
6
x <- log(c(0.0001, 0.0003, 0.000006))
y <- logAdd(x) 
##verification that the computation is correct
z <- sum(c(0.0001, 0.0003, 0.000006))
z
exp(y)

mBPCR documentation built on Nov. 8, 2020, 8:05 p.m.

Related to logAdd in mBPCR...