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: 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. Accuracy is roughly seven decimal digits across the positive-real regime.
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])