FEAT: Use nested sampling weights in plot_corner and quantiles#1075
Open
christianescamilla15-cell wants to merge 1 commit intobilby-dev:mainfrom
Open
FEAT: Use nested sampling weights in plot_corner and quantiles#1075christianescamilla15-cell wants to merge 1 commit intobilby-dev:mainfrom
christianescamilla15-cell wants to merge 1 commit intobilby-dev:mainfrom
Conversation
Adds an `use_nested_samples` option to `Result.plot_corner` which uses the weighted nested samples rather than the resampled posterior. This reduces the Monte-Carlo noise from resampling in the marginal distributions and produces smoother corner plots when the underlying sampler provides nested samples with weights. Also extends `Result.get_one_dimensional_median_and_error_bar` with optional `samples` and `weights` arguments and introduces a `_weighted_quantile` helper (linear interpolation of the weighted empirical CDF) so the 1D title quantiles use the same weights as the plot when `use_nested_samples=True`. Closes bilby-dev#563 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
Closes #563.
use_nested_sampleskeyword toResult.plot_corner. When enabled, the full nested-sampling chain is passed tocorner.corneralong with the per-sampleweightscolumn, rather than using the resampled posterior. This avoids the Monte-Carlo tail noise introduced by resampling and produces smoother marginal distributions.Result.get_one_dimensional_median_and_error_barwith optionalsamplesandweightsarguments so the 1D title quantiles can be computed from the same weighted samples that are plotted._weighted_quantilehelper that computes quantiles via linear interpolation of the weighted empirical CDF. With uniform weights it reproducesnumpy.percentileto within floating-point precision.Raises a clear
ValueErrorwhenuse_nested_samples=Trueis passed but the result has no nested samples or noweightscolumn in the nested samples data frame.Test plan
test_plot_corner_use_nested_samplescovering successful use.weightscolumn._weighted_quantile(uniform weights matchnp.percentile, edge cases, shape validation).get_one_dimensional_median_and_error_baracceptssamples/weightsand returns sensible medians.