Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add x batch dim in sbc loop. #838

Merged
merged 1 commit into from
Apr 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions sbi/analysis/sbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ def sbc_on_batch(
dap_samples = torch.zeros_like(thetas)
ranks = torch.zeros((thetas.shape[0], len(reduce_fns)))

for idx, (tho, xo) in enumerate(zip(thetas, xs)):
for idx in range(thetas.shape[0]):
# unsqueeze for potential higher-dimensional data.
xo = xs[idx].unsqueeze(0)
# VI posterior needs to be trained on the current xo.
if isinstance(posterior, VIPosterior):
posterior.set_default_x(xo)
Expand All @@ -184,7 +186,9 @@ def sbc_on_batch(
# rank for each posterior dimension as in Talts et al. section 4.1.
for i, reduce_fn in enumerate(reduce_fns):
ranks[idx, i] = (
(reduce_fn(ths, xo) < reduce_fn(tho.unsqueeze(0), xo)).sum().item()
(reduce_fn(ths, xo) < reduce_fn(thetas[idx].unsqueeze(0), xo))
.sum()
.item()
)

return ranks, dap_samples
Expand Down