Skip to content

Fix prior curvature in shrinkage Hessian - #470

Open
Intron7 wants to merge 1 commit into
scverse:mainfrom
Intron7:codex/fix-shrinkage-hessian
Open

Intron7 wants to merge 1 commit into
scverse:mainfrom
Intron7:codex/fix-shrinkage-hessian

Conversation

@Intron7

@Intron7 Intron7 commented Sep 23, 2026

Copy link
Copy Markdown
Member

nbinomGLM constructs the prior curvature as a diagonal matrix, then calls np.diag on that matrix again when adding it to the likelihood Hessian. The second call extracts a vector, which broadcasts across rows and introduces off-diagonal prior curvature. The resulting inverse Hessian is generally nonsymmetric and does not represent the curvature of nbinomFn.

Add the diagonal matrix directly. This corrects the returned shrinkage covariance and the Hessian supplied to Newton-CG; the default L-BFGS-B objective and gradient are unchanged.

The regression compares the inverse of the returned covariance with central finite differences of the objective for two- and four-coefficient designs, shrinking either the first or last coefficient. All four cases fail before the fix and pass afterward.

Validation: full upstream suite passes (69 tests); Ruff lint, formatting, and mypy pass.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.05%. Comparing base (95ace12) to head (e3bac65).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #470   +/-   ##
=======================================
  Coverage   86.05%   86.05%           
=======================================
  Files          15       15           
  Lines        1276     1276           
=======================================
  Hits         1098     1098           
  Misses        178      178           
Files with missing lines Coverage Δ
src/pydeseq2/distributions.py 98.18% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
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