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)

paolarancoita/mBPCR documentation built on Jan. 12, 2020, 6:24 p.m.