fn

psi

Tensor
psi(x: Tensor)
source

Digamma function ψ(x)=ddxlogΓ(x)\psi(x) = \frac{d}{dx} \log \Gamma(x).

Convenience alias for lucid.digamma. The digamma function is the logarithmic derivative of the gamma function and the fundamental building block of the polygamma family.

Parameters

xTensor
Input tensor; any floating-point dtype.

Returns

Tensor

ψ(x)\psi(x) element-wise.

Notes

Definition:

ψ(x)=ddxlogΓ(x)=Γ(x)Γ(x)=γ+k=0(1k+11k+x),\psi(x) = \frac{d}{dx} \log \Gamma(x) = \frac{\Gamma'(x)}{\Gamma(x)} = -\gamma + \sum_{k=0}^\infty \left(\frac{1}{k + 1} - \frac{1}{k + x}\right),

where γ0.5772\gamma \approx 0.5772 is the Euler–Mascheroni constant. Used in the derivatives of log-likelihoods of the Gamma / Beta / Dirichlet distributions. Has simple poles at the non-positive integers.

Examples

>>> import lucid
>>> from lucid.special import psi
>>> psi(lucid.tensor([1.0, 2.0, 10.0]))
Tensor([-0.5772, 0.4228, 2.2517])