nessai.utils.stats

Utilities related to statistics.

Module Contents

Functions

effective_sample_size(log_w)

Compute Kish's effective sample size.

rolling_mean(x[, N])

Compute the rolling mean with a given window size.

weighted_quantile(values, quantiles[, log_weights, ...])

Compute quantiles for an array of values.

nessai.utils.stats.effective_sample_size(log_w)

Compute Kish’s effective sample size.

Parameters:
log_warray_like

Log-weights.

Returns:
float

The effective sample size.

nessai.utils.stats.rolling_mean(x, N=10)

Compute the rolling mean with a given window size.

Based on this answer from StackOverflow: https://stackoverflow.com/a/47490020

Parameters:
xnumpy.ndarray

Array of samples

Nint

Size of the window over which the rolling mean is computed.

Returns:
numpy.ndarray

Array containing the moving average.

nessai.utils.stats.weighted_quantile(values, quantiles, log_weights=None, values_sorted=False)

Compute quantiles for an array of values.

Uses the Harrell-Davis quantile estimator.

Parameters:
valuesarray_like

Array of values

quantilesfloat or array_like

Quantiles to compute

log_weightsarray_like, optional

Array of log-weights

values_sortedbool

If the values are pre-sorted or not

Returns:
np.ndarray

Array of values for each quantile.

Raises:
ValueError

If the effective sample size is not finite.