Repository navigation
FEAT: log densities for the spin models - #145
Merged
Merged
Conversation
Add ln_ versions of gaussian_chi_eff, gaussian_chi_p, the beta spin magnitude models (iid and independent), the isotropic + Gaussian orientation mixtures and iid_spin, and GaussianChiEffChiP.ln_prob. hyperpe.Model uses these, so in single precision the densities no longer underflow to zero far from narrow peaks: in a float32 survey (10k samples x 10 draws per model), gaussian_chi_eff and GaussianChiEffChiP lost 6% of points to underflow and now lose none. - utils.ln_beta_dist, with beta_dist now exp(ln_beta_dist). It uses xlogy, so a Beta(1, b) density at a = 0 (and Beta(a, 1) at a = amax) is now finite rather than 0; elsewhere values agree to rounding. - utils.ln_unnormalized_2d_gaussian, the exponent of unnormalized_2d_gaussian, which is now its exp. GaussianChiEffChiP's log density is this minus the log of the unchanged grid normalization. - The orientation mixtures use logaddexp; as in the linear model, the isotropic component is not truncated. test/ln_model_test.py checks each log density against the log of the density (numpy and jax backends) and -inf outside the support, and the jit-compiled float32 log density against float64 on the same rounded inputs. It also checks that the linear float32 density loses points for the hyperparameters used, so the comparison covers underflow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #145 +/- ##
==========================================
+ Coverage 95.12% 95.21% +0.10%
==========================================
Files 14 14
Lines 1085 1107 +22
==========================================
+ Hits 1032 1054 +22
Misses 53 53
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.
Add ln_ versions of gaussian_chi_eff, gaussian_chi_p, the beta spin magnitude models (iid and independent), the isotropic + Gaussian orientation mixtures and iid_spin, and GaussianChiEffChiP.ln_prob. hyperpe.Model uses these, so in single precision the densities no longer underflow to zero far from narrow peaks: in a float32 survey (10k samples x 10 draws per model), gaussian_chi_eff and GaussianChiEffChiP lost 6% of points to underflow and now lose none.
test/ln_model_test.py checks each log density against the log of the density (numpy and jax backends) and -inf outside the support, and the jit-compiled float32 log density against float64 on the same rounded inputs. It also checks that the linear float32 density loses points for the hyperparameters used, so the comparison covers underflow.