fn

xlog1py

Tensor
xlog1py(x: Tensor, y: Tensor)
source

Safe product xlog(1+y)x \log(1 + y) with limit-convention zero handling.

Computes xlog(1+y)x \log(1 + y) element-wise but enforces the convention 0log(1+0)=00 \cdot \log(1 + 0) = 0, and more generally propagates the zero whenever x=0x = 0 regardless of y. Mirrors lucid.xlogy but uses log(1+y)\log(1 + y) instead of logy\log y, which is the right primitive for log-densities of distributions expressed in terms of small offsets (Negative Binomial log-likelihood, Beta survival functions, etc.).

Parameters

xTensor
Multiplier tensor.
yTensor
Argument of log1p; broadcast-compatible with x.

Returns

Tensor

xlog(1+y)x \log(1 + y) element-wise, broadcast to the common shape of x and y.

Notes

Mathematical definition with the limit convention:

xlog1py(x,y)={0,x=0xlog(1+y),otherwise.\text{xlog1py}(x, y) = \begin{cases} 0, & x = 0 \\[2pt] x \log(1 + y), & \text{otherwise}. \end{cases}

Using log(1+y)\log(1 + y) avoids precision loss for small y where 1 + y would round to 1.0.

Examples

>>> import lucid
>>> from lucid.special import xlog1py
>>> x = lucid.tensor([0.0, 1.0, 2.0])
>>> y = lucid.tensor([0.0, 1.0, 3.0])
>>> xlog1py(x, y)
Tensor([0.0000, 0.6931, 2.7726])