fix: SE cumulative and EUR missing gamma(1/n) factor#20
Conversation
|
Review — verified, the math is correct. Traced the derivation and confirmed numerically against Notes:
Nit: three trailing blank lines added in |
SE._Nfn returned qi*tau/n * P(1/n, (t/tau)^n) using the regularised lower incomplete gamma (scipy gammainc = P), but the closed-form integral of qi*exp(-(t/tau)^n) is qi*tau/n * gamma(1/n) * P(1/n, (t/tau)^n). The missing gamma(1/n) made cumulative volume and EUR wrong by that factor - e.g. +33% at n=0.4, -9% at n=0.8. Verified against adaptive quadrature of the rate (new test_SE_cum_matches_integral, which the old finite-only check missed). For very small n gamma(1/n) overflows (the closed-form EUR genuinely diverges there); guard on a finite coefficient and fall back to the bounded numerical integral. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
dsfulf
left a comment
There was a problem hiding this comment.
Verified the math: the closed-form SE cumulative requires the gamma(1/n) factor (scipy gammainc is the regularised P). Confirmed new/quad = 1.00000 across n in [0.3, 0.8]; the small-n overflow fallback to the numerical integrator matches quadrature to ~5e-9. Rebased onto main (post-#21) so the mypy unreachable-statement lint passes; full matrix green. Approving.
Follow-up to #20 (SE gamma fix) and #21 (n_grid), landing changes that weren't part of either contributor PR: - base.py: n_grid < 2 now raises ValueError (was a degenerate grid); validated before the empty-t early return. Document n_grid on cum() and the sibling volume methods (were stale "currently unused"); pass **kwargs through monthly_vol_equiv's prepend for consistency. - test/test_perf.py: add coverage for the n_grid guard and the SE small-n gamma-overflow fallback path. - docs/versions.rst: 2.1.0 entry (SE fix flagged as a breaking numerical change; n_grid; THM cleanup). - docs/numerical_integration.rst + integration_validation.py: n_grid convergence analysis (second-order; 10k -> ~2e-6, 2000 -> ~5e-5), SE small-n fallback note, print_ngrid_convergence(). - ci.yml + pyproject.toml + .gitignore: upload coverage to Coveralls via coverallsapp/github-action (ubuntu/3.12 cell, continue-on-error). - Bump version 2.0.0 -> 2.1.0. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
SE._Nfnreturnsqi*tau/n * gammainc(1/n, (t/tau)^n). Sincescipy.special.gammaincis the regularised lower incomplete gamma P(a,x), the closed-form integral of the SE rateqi*exp(-(t/tau)^n)needs the extragamma(1/n)factor:Without it, SE cumulative volume and EUR are off by a factor of
Γ(1/n): understated for n < 0.5 (about 25% at n=0.4, 64% at n=0.3), exact at n=0.5, overstated by about 10% for n > 0.5.Verified against adaptive quadrature of the rate (
scipy.integrate.quad); a regression testtest_SE_cum_matches_integralis added, since the previouscheck_modelassertions only tested thatcumwas finite, so a constant-factor error passed silently.For very small n,
gamma(1/n)overflows (the closed-form EUR genuinely diverges there); the code guards on a finite coefficient and falls back to the existing numerical integrator.🤖 Generated with Claude Code