fn

logaddexp

Tensor
logaddexp(input: Tensor, other: Tensor | Scalar)
source

Element-wise log-sum-exp of two operands.

Computes log(ex+ey)\log(e^{x} + e^{y}) using the log-sum-exp trick to avoid overflow when x or y is large.

Parameters

inputTensor
Left operand.
otherTensor or scalar
Right operand. Broadcasts against input following the standard broadcasting rules; Python scalars are promoted to a tensor of matching dtype.

Returns

Tensor

Element-wise result with shape broadcast(input.shape, other.shape) and dtype determined by the usual type-promotion rules.

Notes

Mathematical definition:

outi=log(einputi+eotheri)=max(x,y)+log(1+exy)\text{out}_i = \log(e^{\text{input}_i} + e^{\text{other}_i}) = \max(x, y) + \log(1 + e^{-|x - y|})

Widely used in probabilistic models for marginalizing in log-space.

Examples

>>> import lucid
>>> a = lucid.tensor([1.0, 2.0, 3.0])
>>> b = lucid.tensor([4.0, 5.0, 6.0])
>>> lucid.logaddexp(a, b)
Tensor([...])