Skip to content

Exact shape derivatives of the incomplete gamma's logs (#797) - #848

Merged
derrynknife merged 1 commit into
developfrom
claude/surpyval-next-steps-7uatqe
Oct 10, 2026
Merged

derrynknife merged 1 commit into
developfrom
claude/surpyval-next-steps-7uatqe

Conversation

@derrynknife

Copy link
Copy Markdown
Owner

Fixes #797.

The derivatives of log P and log Q in the shape were five-point
differences of scipy's values: 1e-10 off mpmath's typically, up to 4e-9
(at a = 0.5, x = 1), wherever the Gamma's hazard is taken from them (a
standardised time below 30; above it the hazard has its own fraction,
#786). They are now carried along the series of P (below x = a + 1)
and Legendre's continued fraction of Q (at or above it), in real
forward mode, each to rounding: within 1e-14 of mpmath, median 3e-16.
Where neither settles (a shape of millions with x near it), and at x of
0 or inf, they are differenced as before; the shape curvature a Hessian
takes is the difference of the exact first derivative.

Decided with the user: the cost is accepted. A GammaPH fit on 400 rows
takes 0.32 s where it took 0.21 s (GammaAFT 0.17 to 0.24 s, a censored
Gamma 0.04 to 0.05 s); the estimates are the same.

🤖 Generated with Claude Code

https://claude.ai/code/session_01TRhKL2fJBiAAfNo9rihwts


Generated by Claude Code

The derivatives of log P and log Q in the shape were five-point
differences of scipy's values: 1e-10 off mpmath's typically, up to 4e-9
(at a = 0.5, x = 1), wherever the Gamma's hazard is taken from them (a
standardised time below 30; above it the hazard has its own fraction,
#786). They are now carried along the series of P (below x = a + 1)
and Legendre's continued fraction of Q (at or above it), in real
forward mode, each to rounding: within 1e-14 of mpmath, median 3e-16.
Where neither settles (a shape of millions with x near it), and at x of
0 or inf, they are differenced as before; the shape curvature a Hessian
takes is the difference of the exact first derivative.

Decided with the user: the cost is accepted. A GammaPH fit on 400 rows
takes 0.32 s where it took 0.21 s (GammaAFT 0.17 to 0.24 s, a censored
Gamma 0.04 to 0.05 s); the estimates are the same.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TRhKL2fJBiAAfNo9rihwts
@derrynknife
derrynknife merged commit 0dfc060 into develop Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants