logAdd {mBPCR}R Documentation

Overflow-safe computation of the logarithm of a sum

Description

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

Usage

  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

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)

[Package mBPCR version 1.42.0 Index]