scippuncertainty.mc.accumulator.VarianceAccum#

class scippuncertainty.mc.accumulator.VarianceAccum(*, keep_samples=False)[source]#

Compute the mean and variance of bootstrap samples.

The mean \(\mu_i\) and variance \(\sigma_i^2\) for array element \(i\) are defined as

\[\begin{split}\mu_i &= \frac{1}{N} \sum_{s=1}^{N} x_{i s} \\ \sigma_i^2 &= \frac{1}{N-1} \sum_{s=1}^{N} (x_{i s} - \mu_i)^2, \\\end{split}\]

where the sums run over the Monte-Carlo samples.

The computation of variances uses an algorithm based on [Wel62] and [CGL82]. This reduces the risk of catastrophic cancellations from sums of squares compared to a naive implementation.

__init__(*, keep_samples=False)[source]#

Initialize a CovarianceAccum instance.

Parameters:

keep_samples (bool, default: False) – If True, all samples are kept and returned as an attribute called samples with dimension monte_carlo.

Methods

__init__(*[, keep_samples])

Initialize a CovarianceAccum instance.

add(sample)

Register a single sample.

add_from(other)

Merge results from other into self.

get()

Return the current result.

new()

Return a new VarianceAccum.

add(sample)[source]#

Register a single sample.

Return type:

None

add_from(other)[source]#

Merge results from other into self.

Return type:

None

get()[source]#

Return the current result.

Return type:

Accumulated

new()[source]#

Return a new VarianceAccum.

The new instance does not contain any samples even if self does.

Return type:

VarianceAccum