Skip to content

Number of samples in sample_batched does not match actual number of samples drawn #1388

Closed

Description

@turnmanh

Describe the bug

The posterior object provides a sample_batched((n,), x) function in order to draw n samples for each conditional in x. The progress bar for drawing these samples states the number of samples n to draw per conditional but the actual number of samples is n * x.shape[0].

To Reproduce
Please add a minimal code example that reproduces the problem:

  1. Name Python version and SBI version: Python 3.12 and 0.23.3
  2. Minimal code example
    The example is based on the code run in notebook 1 after the posterior was fit.
>>> posterior.sample_batched((10,), x).shape
Drawing 10 posterior samples: 1432it [02:44,  8.70it/s]                                                                                                      
torch.Size([10, 2000, 3])

Expected behavior

State to draw n * x.shape[0] posterior samples.

Additional context

Using the example from notebook 01 to obtain a posterior on a Gaussian mixture, x.shape is [2000, 3]. Therefore, running posterior.sample_batched((10,), x) draws 20k samples but the progress bar states 10.

Image

Activity

  1. added
    bug
    on Feb 17, 2025
  2. janfb commented on Feb 20, 2025

    @janfb
    Contributor

    Thanks for raising this. I agree, it would be good to adapt the pbar to state that it is drawing N samples for each of the M x. I would disagree that it should display N*M samples because we are drawing a separate set of samples for each x.

  3. self-assigned this
    on Mar 19, 2025
  4. janfb commented on Mar 25, 2025

    @janfb
    Contributor

    fixed with #1493

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions