stats — Statistical tools#

This module contains…

Module documentation#

Statistical tools.

class hexsample.stats.RunningStats(shape: int | Tuple[int, ...] = ())[source]#

Small convenience class to accumulate running statistics (mean and variance) of a stream of data.

This is designed to work both for scalar values and for arrays of arbitrary shape, and uses the Welford algorithm to perform the computation.

Arguments#

shapeint or tuple of ints, optional

The shape of the underlying arrays for accumulating the statistics.

size() int[source]#

Return the total number of samples accumulated across all indices.

update(val: ndarray, offset: int | Tuple[int, ...] = None, mask: bool | ndarray = None) None[source]#

Update the running statistics.

Arguments#

valarray-like

The new value(s) to incorporate into the running statistics. This is a numpy array with the same rank of the running stats, but with a a shape that can be smaller than the underlying arrays (in which case the precise region to be updated is determined by the offset parameter).

offsetint or tuple of ints, optional

The offset for the update region in the underlying arrays.

maskarray-like of bool, optional

An optional boolean mask to specify which elements of val should be included in the update. This should have the same shape as val.

counts() ndarray[source]#

Return the current value for the counts.

mean() ndarray[source]#

Return the current value for the mean.

var(ddof: int = 1)[source]#

Return the current value for the variance.

Arguments#

ddofint

Delta degrees of freedom (default is 1 for the unbiased sample variance.)

std(ddof: int = 1)[source]#

Return the current value for the standard deviation.

Arguments#

ddofint

Delta degrees of freedom (default is 1.)