Polygamma function .
The n-th derivative of the digamma function. Polygamma
functions appear in the derivatives of log-partition functions of
the Gamma / Beta / Dirichlet families and are needed for evaluating
Fisher information matrices for these distributions analytically.
Parameters
nintn = 0 recovers
lucid.digamma, n = 1 is the trigamma function. Any
order is accepted, though grows like
and overflows float32 for large n — see Notes.Returns
Tensor element-wise, same shape and dtype as
x.
Notes
Definition (for n >= 1):
Implementation: for x >= 0 shift x upward by
using the recurrence
accumulate the per-step corrections, then evaluate the Bernoulli
asymptotic series at the shifted argument where it is
well-conditioned. For x < 0 the n-th derivative of the
reflection formula,
maps the argument onto the right half. The non-positive integers
(and -inf) are poles: n = 0 gives NaN there, except
psi(+0) = -inf and psi(-0) = +inf; n >= 1 gives
.
Raises ValueError for n < 0.
Accuracy was checked against an independent direct summation for and : the worst relative disagreement was 7e-11, which is the reference's own truncation floor rather than this routine's error, and is far below what float32 can represent anyway.
Note that , so the result itself exceeds the float32 range somewhere around ; that is the dtype's limit, not the method's.
Examples
>>> import lucid
>>> from lucid.special import polygamma
>>> polygamma(1, lucid.tensor([1.0, 2.0, 5.0]))
tensor([1.645, 0.6449, 0.2213])