Skip to content

FEAT: Use nested sampling weights in plot_corner and quantiles#1075

Open
christianescamilla15-cell wants to merge 1 commit intobilby-dev:mainfrom
christianescamilla15-cell:feat/corner-ns-weights
Open

FEAT: Use nested sampling weights in plot_corner and quantiles#1075
christianescamilla15-cell wants to merge 1 commit intobilby-dev:mainfrom
christianescamilla15-cell:feat/corner-ns-weights

Conversation

@christianescamilla15-cell
Copy link
Copy Markdown

Summary

Closes #563.

  • Adds a new use_nested_samples keyword to Result.plot_corner. When enabled, the full nested-sampling chain is passed to corner.corner along with the per-sample weights column, rather than using the resampled posterior. This avoids the Monte-Carlo tail noise introduced by resampling and produces smoother marginal distributions.
  • Extends Result.get_one_dimensional_median_and_error_bar with optional samples and weights arguments so the 1D title quantiles can be computed from the same weighted samples that are plotted.
  • Adds a _weighted_quantile helper that computes quantiles via linear interpolation of the weighted empirical CDF. With uniform weights it reproduces numpy.percentile to within floating-point precision.

Raises a clear ValueError when use_nested_samples=True is passed but the result has no nested samples or no weights column in the nested samples data frame.

Test plan

  • Added test_plot_corner_use_nested_samples covering successful use.
  • Added error-path tests when nested samples are absent or lack a weights column.
  • Added unit tests for _weighted_quantile (uniform weights match np.percentile, edge cases, shape validation).
  • Added test verifying get_one_dimensional_median_and_error_bar accepts samples/weights and returns sensible medians.
  • CI green on the bilby-dev CI.

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>
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.

Use NS weights for posterior plots and quantiles

1 participant