Weighted statistics¶
Functions performing statistical operations on weighted points generated via importance sampling.

pyabc.weighted_statistics.
effective_sample_size
(weights)[source]¶ Compute the effective sample size of weighted points sampled via importance sampling according to the formula
\[n_\text{eff} = \frac{(\sum_{i=1}^nw_i)^2}{\sum_{i=1}^nw_i^2}\]

pyabc.weighted_statistics.
resample
(points, weights, n)[source]¶ Resample from weighted samples.
 Parameters
points – The random samples.
weights – Weights of each sample point.
n – Number of samples to resample.
 Returns
A total of n points sampled from points with putting back according to weights.
 Return type
resampled

pyabc.weighted_statistics.
resample_deterministic
(points, weights, n, enforce_n=False)[source]¶ Resample from weighted samples in a deterministic manner. Essentially, multiplicities are picked as follows: The weights are multiplied by the target number n and rounded to the nearest integer, potentially with correction if enforce_n.
 Parameters
points – The random samples.
weights – Weights of each sample point.
n – Number of samples to resample.
enforce_n – Whether to enforce the returned array to have length n. If not, its length can be slightly off, but it may be more representative.
 Returns
A total of (roughly) n points resampled from points deterministically using a rational representation of the weights.
 Return type
resampled

pyabc.weighted_statistics.
weight_checked
(function)[source]¶ Function decorator to check normalization of weights.

pyabc.weighted_statistics.
weighted_mean
(points, weights=None, **kwargs)[source]¶ Compute the weighted mean.

pyabc.weighted_statistics.
weighted_median
(points, weights=None, **kwargs)[source]¶ Compute the weighted median (i.e. 0.5 quantile).