fips.Posterior.cov#

Posterior.cov(W=None)[source]#

Return the posterior error covariance, of the state or of aggregates of it.

Parameters:

W (Operator | None) – An aggregation, k x n: one row per aggregate (a region, a month, a total), one column per state element, with the state’s labels as its columns (in any order). Row i holds the weight of each state element in aggregate i: ones for a sum, 1/count for a mean. It may be sparse.

Returns:

Without W, \(\hat{S}\), dense, n x n (formed once, the same object each time). With W, \(W \hat{S} W^T\) on the aggregation’s rows, k x k, computed without the n x n covariance.

Return type:

Covariance

Raises:

ValueError – If the columns of W do not have exactly the state’s labels.

See also

variances

The diagonal of the full covariance.

averaging_kernel

The averaging kernel, of the state or of aggregates.

Examples

>>> import numpy as np
>>> import pandas as pd
>>> import fips
>>> cells = pd.Index(["a", "b", "c"], name="cell")
>>> prior = fips.Vector.from_series(pd.Series(0.0, index=cells), block="flux")
>>> obs = fips.Vector.from_series(
...     pd.Series([1.0, 2.0], index=pd.Index(["o1", "o2"], name="obs_id")),
...     block="co2",
... )
>>> problem = fips.Problem(
...     prior=prior,
...     prior_cov=fips.Independent().with_std(1.0),
...     obs=obs,
...     obs_cov=fips.Independent().with_std(np.sqrt(0.1)),
...     forward=fips.Operator(
...         np.array([[1.0, 1.0, 0.0], [0.0, 1.0, 1.0]]), obs.space, prior.space
...     ),
... )
>>> post = fips.solve(problem)
>>> total = fips.Operator(
...     np.ones((1, 3)),
...     fips.Space({"total": pd.Index(["all"], name="region")}),
...     prior.space,
... )
>>> post.cov(total).dense().round(3)
array([[0.419]])