Skip to content

SMCABC: distance_based_decay picks the wrong epsilon — cumsum(distances)/sum(distances) is not a CDF #2117

Closed

Description

@BHARATH0153

Bug description

What happens. With distance_based_decay=True, SMCABC is supposed to set the next acceptance threshold ε to the epsilon_decay-th quantile of the previous population's distances (so epsilon_decay=0.5 ≈ halving, 0.1 ≈ 10th percentile). Instead, _get_next_epsilon() computes

distances = torch.unique(distances)
distances_cdf = torch.cumsum(distances, dim=0) / distances.sum()
qidx = torch.where(distances_cdf >= quantile)[0][0]

cumsum(d)/sum(d) is the CDF of a distribution whose mass is proportional to the distance value, not the empirical CDF of the samples. Because the largest distances dominate the sum, the >= quantile crossing happens near the end of the array. So ε is biased high, and whenever the distance distribution is heavy-tailed it simply returns the maximum distance — i.e. ε does not tighten at all.

How it differs from expected. Expected: next ε = empirical epsilon_decay quantile of the previous distances. Actual: next ε ≈ 60th–100th percentile regardless of epsilon_decay. MCABC already does the right thing by rank (int(num_simulations * quantile)), which shows the intended semantics.
Impact: with a fixed num_simulations budget, ε decays far too slowly, so you get fewer useful refinement populations and a broader ε-ABC posterior than the epsilon_decay you asked for. It fails silently — no warning, no exception.

Minimal code example

import torch, types
from sbi.inference.abc.smcabc import SMCABC

d = torch.tensor([0.0, 0.1, 0.2, 100.0])   
for q in (0.1, 0.5, 0.9):
    got = SMCABC._get_next_epsilon(types.SimpleNamespace(), d, q)
    print(f"q={q}: sbi={got:<6} correct~{torch.quantile(d, q).item():.4f}")

Error message or traceback

q=0.1: sbi=100.0  correct~0.0300
q=0.5: sbi=100.0  correct~0.1500
q=0.9: sbi=100.0  correct~70.0600

decay=0.1: eps=[0.3793, 0.1769], next eps is the 22th percentile (wanted 10th)
decay=0.5: eps=[0.3793, 0.2952, 0.2329], next eps is the 63th percentile (wanted 50th)

sbi version

0.27.0 (at 585841b)

Python version

3.14.5 (also torch 2.12.1)

Device

CPU

Inference method

ABC (MCABC / SMCABC)

Single-round or multi-round

Multi-round (sequential)

Additional context

I also found a couple of unrelated candidates while reading (e.g. ImportanceSamplingPosterior doesn't invalidate _normalization_constant after set_default_x), but this SMC-ABC one is the clean, self-contained, reproducible defect.

Activity

  1. added
    bug
    on Oct 29, 2026
  2. BHARATH0153 commented on Oct 29, 2026

    @BHARATH0153
    ContributorAuthor

    @janfb Fix is simple take the real empirical quantile of the unique sorted distances
    Nothing changes for distance_based_decay=False since that path is separate.
    I'll add a small test asserting _get_next_epsilon == torch.quantile(distances, q) for a few q, then open a PR.

  3. janfb commented on Oct 29, 2026

    @janfb
    Contributor

    @BHARATH0153 thanks for the clear report, and for proposing the fix here first. I can confirm it: the cumulative sum of the sorted distances is not their empirical CDF, so with uniform distances epsilon_decay=0.1 picks about the 32nd percentile and 0.5 about the 71st.

    Please go ahead with the PR as you describe it. Please also update the docstring of distance_based_decay, so that it says that epsilon_decay is then the quantile of the previous population's distances.

    The ImportanceSamplingPosterior normalization after set_default_x is part of PR #2107.

    cheers, Jan

  4. added 7 commits that reference this issue on Oct 29, 2026
    93878e5
    6cd83b2
    592cd13
    9345abf
    c32e483
    445a699
    76e6e0e
  5. added a commit that references this issue on Nov 15, 2026
    799e324
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions