output_analysis.OnlineStatistics

Computes running sample mean and variance using Welford’s algorithm.

Usage

Source

output_analysis.OnlineStatistics()

This is a robust and numerically stable approach first described in the 1960s and popularised in Donald Knuth’s The Art of Computer Programming (Vol. 2).

The term “online” means each new data point is processed immediately to update statistics, without storing or reprocessing the entire dataset.

This implementation additionally supports computation of: - Confidence intervals (CIs). - Percentage deviation of CI half-widths from the mean.

Attributes

n: int

Number of data points processed so far.

x_i: float

Most recent data point.

mean: float

Current running mean.

_sq: float

Sum of squared differences from the current mean (used for variance).

alpha: float

Significance level for confidence interval calculations

observer: list
Registered observers notified upon updates.

Attributes

Name Description
deviation Precision of the confidence interval expressed as the percentage
half_width Half-width of the confidence interval.
lci Lower bound of the confidence interval.
std Standard deviation of data.
std_error Standard error of the mean.
uci Upper bound of the confidence interval.
variance Sample variance of the data.

deviation

Precision of the confidence interval expressed as the percentage

deviation: float

deviation of the half width from the mean.


half_width

Half-width of the confidence interval.

half_width: float


lci

Lower bound of the confidence interval.

lci: float


std

Standard deviation of data.

std: float


std_error

Standard error of the mean.

std_error: float


uci

Upper bound of the confidence interval.

uci: float


variance

Sample variance of the data.

variance: float

Methods

Name Description
__init__() Initialise a new OnlineStatistics object.
notify() Notify all registered observers that an update has occurred.
register_observer() Register an observer to be notified on each statistics update.
update() Update statistics with a new observation using Welford’s algorithm.

__init__()

Initialise a new OnlineStatistics object.

Usage

Source

__init__(data=None, alpha=0.1, observer=None)
Parameters
data: Optional[np.ndarray] = None

Initial dataset to process.

alpha: Optional[float] = 0.1

Significance level for confidence interval calculations (CI level = 100 * (1 - alpha) %).

observer: Optional[ReplicationObserver] = None
A user may optionally track the updates to the statistics using a ReplicationObserver (e.g. ReplicationTabuliser). This allows further tabular or visual analysis or saving results to file if required.
Raises
ValueError
If data is provided but is not a NumPy array.

notify()

Notify all registered observers that an update has occurred.

Usage

Source

notify()

register_observer()

Register an observer to be notified on each statistics update.

Usage

Source

register_observer(observer)
Parameters
observer: ReplicationObserver
Object implementing the observer interface.
Raises
ValueError
If observer is not an instance of ReplicationObserver.

update()

Update statistics with a new observation using Welford’s algorithm.

Usage

Source

update(x)

See Knuth. D The Art of Computer Programming Vol 2. 2nd ed. Page 216.

Parameters
x: float
New observation.