scippuncertainty.mc.accumulator.CovarianceAccum#

class scippuncertainty.mc.accumulator.CovarianceAccum(*, dims=None)[source]#

Compute the covariance matrix of a 1d array with itself.

The covariance \(\Sigma_{ij}^2\) of array element \(i\) with element \(j\) is defined as

\[\Sigma_{ij}^2 = \frac{1}{N-1} \sum_{s=1}^N (x_{i s} - \mu_i) (x_{j s} - \mu_j)\]

where the sums run over the Monte-Carlo samples and \(\mu_i\) is the mean of element \(i\).

The computation uses an algorithm based on [SG18] which reduces the risk of catastrophic cancellations from sums of squares compared to a naive implementation.

The covariance matrix is encoded as the values of a 2d data array. Dimensions are named dim_0 and dim_1 by default, but this can be customized using the dims argument. The returned data array does not have any coordinates, attributes, or masks (except for an attribute n-samples).

__init__(*, dims=None)[source]#

Initialize a CovarianceAccum instance.

Parameters:

dims (Union[list[str], tuple[str, str], None], default: None) – Dimension names for the covariance matrix. Must be length-2.

Methods

__init__(*[, dims])

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 CovarianceAccum.

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 CovarianceAccum.

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

Return type:

CovarianceAccum