pyabc.weighted_statistics
Weighted statistics
Functions performing statistical operations on weighted points generated via importance sampling.
- pyabc.weighted_statistics.effective_sample_size(weights)[source]
Effective sample size.
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}\]- Parameters:
weights (Importance sampling weights.)
- 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.weighted_mean(points: ndarray, weights: ndarray)[source]
Compute the weighted mean.
- Parameters:
points (Parameter samples, shape (n_sample,) or (n_sample, n_par).)
weights (Weights, shape (n_sample,) or (n_sample, 1).)
- Returns:
mean
- Return type:
The mean, shape () or (n_par,).
- pyabc.weighted_statistics.weighted_median(points, weights)[source]
Compute the weighted median (i.e. 0.5 quantile).
- pyabc.weighted_statistics.weighted_mse(points, weights, refval)[source]
Compute the weighted mean square error.
- pyabc.weighted_statistics.weighted_quantile(points, weights=None, alpha=0.5)[source]
Compute the weighted alpha-quantile. E.g. alpha = 0.5 -> median.
- pyabc.weighted_statistics.weighted_rmse(points, weights, refval)[source]
Compute the weighted root mean square error.