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
anddim_1
by default, but this can be customized using thedims
argument. The returned data array does not have any coordinates, attributes, or masks (except for an attributen-samples
).Methods
__init__
(*[, dims])Initialize a CovarianceAccum instance.
add
(sample)Register a single sample.
add_from
(other)Merge results from
other
intoself
.get
()Return the current result.
new
()Return a new CovarianceAccum.