bijx.effective_sample_size

bijx.effective_sample_size(target_ld, sample_ld)[source]

Compute effective sample size from importance weights.

Measures the efficiency of importance sampling by computing the effective number of independent samples. Values close to 1 indicate efficient sampling, while values near 0 suggest poor importance weight distribution.

Uses the formula: \(\text{ESS} = \frac{(\sum_i w_i)^2}{\sum_i w_i^2}\) where importance weights are \(w_i = \frac{p(x_i)}{q(x_i)}\).

Parameters:
  • target_ld (Array) – Log likelihood of target distribution p (up to constant).

  • sample_ld (Array) – Log likelihood of proposal distribution q (up to constant).

Return type:

Array

Returns:

Effective sample size per sample (between 0 and 1).

Note

Input arrays must correspond to the same set of samples drawn from q. Uses numerically stable log-sum-exp computations.