Add convergence helper and error tracking to nested sampling #41
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.
Summary
This PR introduces two key improvements to the nested sampling implementation:
Convergence helper function - Adds a
converged()utility function (discussed with @zwei-beiner) that properly handles the "full plateau" case where all live points have identical likelihoods. This addresses an edge case where our zero-weight check in the delete function doesn't prevent the algorithm from continuing - it just spreads the selection more fairly due tojax.random.choice's surprising behavior with zero/NaN weights.Error tracking and information metrics - Extends
NSStateto track:logZ_error: Error estimate on the log evidenceH: Information (negative entropy) in natsi_eff: Effective number of iterationsn_eff: Effective sample sizeChanges
blackjax/ns/base.pyNSState:logZ_error,H,i_eff,n_effinit()to initialize these fieldsupdate_ns_runtime_info()to compute error estimates and information metricsblackjax/ns/utils.pyconverged()function that checks:docs/examples/nested_sampling.pyconverged()utility functionTesting
The changes maintain backward compatibility and all existing tests pass. The convergence helper provides a cleaner termination condition that handles edge cases more robustly.
🤖 Generated with Claude Code
Co-Authored-By: Claude [email protected]