Skip to content

NPE-A: multi-round proposal correction is wrong for mixture proposals (default num_components=10) #2108

Closed

Description

@janfb

From round 2 on, NPE-A corrects the trained mixture density by the proposal: posterior ∝ q(θ|x) p(θ) / p̃(θ). correct_for_proposal divides each density component by each proposal component and mixes the results. This is exact only when the proposal is a single Gaussian. For a mixture proposal, the denominator is the sum of its components, and the result is no mixture of Gaussians.

Since PR #1724 (MDN port), NPE-A trains num_components components (default 10) in every round. The round-1 posterior is the round-2 proposal, so it has 10 components. Default multi-round NPE-A is therefore wrong from round 2 on, since v0.26.0 and on main. It often fails outright, because a narrow proposal component makes a corrected precision matrix negative.

Two rounds on a 2D linear Gaussian, 2000 simulations per round:

import torch
from torch import eye, ones, zeros
from torch.distributions import MultivariateNormal

from sbi.inference import NPE_A
from sbi.simulators.linear_gaussian import (
    linear_gaussian,
    true_posterior_linear_gaussian_mvn_prior,
)

prior = MultivariateNormal(zeros(2), eye(2))
shift, cov = zeros(2), 0.1 * eye(2)
x_o = 0.8 * ones(1, 2)
true_samples = true_posterior_linear_gaussian_mvn_prior(
    x_o[0], shift, cov, zeros(2), eye(2)
).sample((5000,))

for num_components in (1, 10):
    torch.manual_seed(1)
    inference = NPE_A(prior=prior, num_components=num_components)
    proposal = prior
    try:
        for _ in range(2):
            theta = proposal.sample((2000,))
            x = linear_gaussian(theta, shift, cov)
            inference.append_simulations(theta, x, proposal=proposal).train()
            proposal = inference.build_posterior().set_default_x(x_o)
        samples = proposal.sample((5000,))
    except ValueError as error:
        print(f"num_components={num_components}: {error}")
        continue
    mean_error = (samples.mean(0) - true_samples.mean(0)).abs().max()
    std_ratio = samples.std(0) / true_samples.std(0)
    print(f"num_components={num_components}: mean error {mean_error:.2f}, std ratio {std_ratio}")
num_components Result after round 2
1 mean error 0.03, std ratio 1.01 to 1.08
10 (default) raises "Posterior precision matrix is not positive definite"

The paper avoids this (Papamakarios & Murray 2016, sections 2.3 and 2.4). It trains a single Gaussian (K = 1) in every round but the last, so the proposal stays a single Gaussian and the correction stays analytic. For the last round, it copies that component K times with small noise and corrects once. sbi did this before PR #1724 with train(final_round=True).

I will fix this in a follow-up PR to PR #2045:

  • Restore final_round and train one component in the earlier rounds.
  • Raise a clear error when the proposal has more than one component.
  • Fix the docstrings that say the components grow as L × K. That is the NPE-C formula, which multiplies by the proposal instead of dividing.
  • Test two rounds against the true posterior, with mean and std.

Activity

  1. self-assigned this
    on Oct 27, 2026
  2. added a commit that references this issue on Oct 28, 2026
    9f08a32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions