Repository navigation
Reject: distinguish non-finite LL from too-aggressive rejsig (#127) - #129
Conversation
Both backends' _reject_outliers raised "removed all N samples (rejsig too aggressive)" whenever every sample was dropped. But for finite log-likelihoods with the construction-validated rejsig>0, the max sample is always kept, so the only way the good set empties is a non-finite per-sample LL (one NaN poisons mean/std, making every comparison False) -- i.e. upstream numerical instability (singular W / overflow), which the user cannot fix by tuning rejsig. On an empty keep-mask, both backends now count the non-finite entries and raise an accurate instability message; the old rejsig message is kept only as a defensive (now unreachable for finite LL) backstop. Tests updated in both backends to inject a single NaN and assert the non-finite message.
Silent-failure review noted the new non-finite-LL branch is effectively unreachable from a normal fit(): both backends' earlier aggregate non-finite-LL guard (the LL sum is non-finite iff a per-sample term is) stops the loop first, so this branch mainly serves direct callers of _reject_outliers and is defense in depth. Note that scope in the comment. Also make the message actionable (matching the sibling singular-W message's house style): name a likely remedy (rank-deficient/average-referenced data, lower learning rate) rather than only what is NOT wrong.
/review-pr summary (2 Sonnet reviewers: code + silent-failure)No Critical/Important correctness issues in either review; both verified the change end-to-end (including +inf/overflow edge cases, single-NaN poisoning, raise-before-mutate, cross-backend consistency, and that the backstop
Not changed (accepted): the mismatched test names (code review, confidence ~30, 'not worth a revision') and the theoretical astronomically-large-finite-LL overflow gap (silent-failure Low, not physically reachable in this pipeline). Validation: |
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #129 +/- ##
==========================================
- Coverage 80.34% 79.82% -0.52%
==========================================
Files 14 14
Lines 2096 2102 +6
Branches 355 357 +2
==========================================
- Hits 1684 1678 -6
- Misses 300 311 +11
- Partials 112 113 +1
🚀 New features to boost your workflow:
|
Summary
Closes #127. Makes both backends'
_reject_outliersreport the real cause whenoutlier rejection would drop every sample.
Builds on #126 (now merged); rebased onto
main.Problem
Both
AMICATorchNG._reject_outliersandAMICA_NumPy._reject_outliersraised:whenever the keep-mask was empty. But for finite log-likelihoods with the
construction-validated
rejsig > 0, the maximum sample is always>= mean >= mean - rejsig*std, so it is always kept -- the good set can only empty when theper-sample LL is non-finite (a single NaN poisons
mean/std, making everycomparison
False). That is upstream numerical instability (singularW/overflow), which a user cannot fix by tuning
rejsig; the old messagemisdiagnosed it.
Change
On an empty keep-mask, both backends now count the non-finite entries and raise
an accurate instability message naming the real cause. The old
rejsigmessageis kept only as a defensive backstop (now unreachable for finite LL with
rejsig > 0). The two backends raise the same message style, fixed together toavoid cross-backend divergence.
Tests
Both backends' degenerate-LL tests now inject a single NaN (demonstrating one
non-finite entry poisons the whole reject decision) and assert the
non-finitemessage:
test_numpy_reject.py::test_rejection_nonfinite_ll_raises_instability_errortest_ng_backend.py::test_rejection_degenerate_ll_raises_clear_errorValidation
uv run ty check .-> 0 diagnostics; ruff clean.