LogSumExp

LogSumExp(*args)

Logarithm of a sum of exponentials.

Returns the value \log\left(\sum_{i=0}^{n-1}\exp(x_i)\right), computed without overflow or underflow.

Available usages:

LogSumExp(logA, logB)

LogSumExp(logValues)

Parameters:
logAfloat

First logarithm.

logBfloat

Second logarithm.

logValuessequence of float

Logarithms to sum.

Returns:
resultfloat

Logarithm of the sum of the exponentials. It is equal to -\infty when the collection is empty or when every term is -\infty, and to +\infty as soon as one term is +\infty. NaN is propagated.

Notes

The implementation uses \max_i x_i + \log\left(\sum_i \exp(x_i-\max_i x_i)\right). It handles infinities and propagates NaN.

Examples

>>> import math
>>> import openturns as ot
>>> print('%.6f' % ot.SpecFunc.LogSumExp(math.log(2.0), math.log(3.0)))
1.609438
>>> print('%.6f' % ot.SpecFunc.LogSumExp([math.log(2.0), math.log(3.0), -math.inf]))
1.609438