Repository navigation
FEAT: log densities for the smoothed and spline models - #148
Merged
Merged
Conversation
BaseSmoothedMassDistribution gains ln_prob, ln_p_m1, ln_p_q and ln_smoothing, and an ln_primary_model class attribute, the log of primary_model taking the same arguments (the log of primary_model if unset); its four subclasses and InterpolatedPowerlaw set it. The terms for each sample are computed in log space, the smoothing window as a log-sigmoid, -logaddexp(0, exponent); the normalizations are computed as for __call__. InterpolatedNoBaseModelIdentical, and so the spline spin models, gains ln_prob, ln_p_x_identical and ln_p_x_unnormed: the spline perturbation minus the log of its normalization. The linear path is refactored, with identical values: - the mmin/mmax check moves to _check_mass_limits, and its error messages are now f-strings (they were printed unformatted); - the cached mass ratio normalization moves to _norm_p_q_at, shared by p_q and ln_p_q, which also re-caches when the cached interpolant's shape differs from mass_1 (before, a shape that still broadcast silently used stale normalizations); - the smoothing exponent moves to _smoothing_exponent. In a float32 survey (10k samples x 10 draws per model), the points lost to underflow drop from 0.3-2.6% to almost none. The exception is primary masses within ~delta_m / 87 of mmin, where the linear mass ratio normalization itself underflows (7 of 500k points, all with ln p below -170). Close to mmin the float32 error grows like (ln p)^2, as the smoothing is evaluated at m - mmin; it is below 5e-3 where ln p > -84. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## ln-mass-models #148 +/- ##
==================================================
+ Coverage 95.50% 95.61% +0.11%
==================================================
Files 14 14
Lines 1156 1230 +74
==================================================
+ Hits 1104 1176 +72
- Misses 52 54 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
BaseSmoothedMassDistribution gains ln_prob, ln_p_m1, ln_p_q and ln_smoothing, and an ln_primary_model class attribute, the log of primary_model taking the same arguments (the log of primary_model if unset); its four subclasses and InterpolatedPowerlaw set it. The terms for each sample are computed in log space, the smoothing window as a log-sigmoid, -logaddexp(0, exponent); the normalizations are computed as for call. InterpolatedNoBaseModelIdentical, and so the spline spin models, gains ln_prob, ln_p_x_identical and ln_p_x_unnormed: the spline perturbation minus the log of its normalization.
The linear path is refactored, with identical values:
In a float32 survey (10k samples x 10 draws per model), the points lost to underflow drop from 0.3-2.6% to almost none. The exception is primary masses within ~delta_m / 87 of mmin, where the linear mass ratio normalization itself underflows (7 of 500k points, all with ln p below -170). Close to mmin the float32 error grows like (ln p)^2, as the smoothing is evaluated at m - mmin; it is below 5e-3 where ln p > -84.