Skip to content

Fix entropy_AIC_weights overflow when a model fits far better than baseline - #10

Merged
annmoel merged 1 commit into
masterfrom
fix/entropy-overflow-far-better-than-baseline
Jul 28, 2026
Merged

annmoel merged 1 commit into
masterfrom
fix/entropy-overflow-far-better-than-baseline

Conversation

@annmoel

@annmoel annmoel commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

Found while doing a smoke test for the figure3 SLURM recompute on real MIBI-TOF data: entropy_AIC_weights can come back NaN when a model fits far better than the ConstantFit baseline (large N + clean signal -- an entirely normal case, not a contrived edge case).

Root cause: relative_likelihood_over_baseline is referenced against baseline_fit.AIC specifically, so it correctly overflows to +inf when a model's AIC is far below baseline's (a legitimate result -- "infinitely more likely than the null model"). But _set_entropy_weights fed these same (possibly inf) values straight into calculate_AIC_weight_entropy's normalization, where inf/inf or x/inf corrupts the result into NaN.

Fix: since entropy is shift-invariant, _set_entropy_weights now references relative likelihood against the minimum AIC among the compared fits rather than baseline_fit.AIC -- mathematically identical result whenever no overflow occurs, but every exponent stays <= 0, so it can never overflow. relative_likelihood_over_baseline itself (the reported per-fit value) is unchanged -- still legitimately inf in this case -- but its overflow warning is now silenced at the source (np.errstate) since it's an expected, not erroneous, outcome.

Test plan

  • Reproduced with N=5000, a clean exponential-saturation signal -- entropy_AIC_weights was NaN before, ~0 (correctly confident) after
  • pytest tests/ -- 118 passed, 1 skipped (1 new regression test: test_entropy_finite_when_far_better_than_baseline)

🤖 Generated with Claude Code

…seline

Discovered while running compute_fits.py on real MIBI-TOF data (large N,
clean signal), a case entirely plausible in normal use.
relative_likelihood_over_baseline is referenced against baseline_fit.AIC,
so it overflows to +inf when a model's AIC is far below baseline's (a
real, meaningful result on its own, not a bug). But _set_entropy_weights
fed these same values into calculate_AIC_weight_entropy, so an inf
relative likelihood corrupted the weight normalization (inf/inf or x/inf),
producing NaN entropy.

Entropy is shift-invariant, so _set_entropy_weights now references
against the minimum AIC among the compared fits instead of baseline_fit's
-- mathematically identical result when no overflow occurs, but every
exponent stays <= 0 so it never overflows. relative_likelihood_over_baseline
itself is unchanged (still legitimately inf in this case); its overflow
warning is now silenced at the source since it's an expected outcome, not
an error.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@annmoel
annmoel merged commit 85325c0 into master Jul 28, 2026
3 checks passed
@annmoel
annmoel deleted the fix/entropy-overflow-far-better-than-baseline branch July 28, 2026 13:50
@annmoel annmoel mentioned this pull request Jul 28, 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.

1 participant