fips.Posterior#

class fips.Posterior(problem, solution, options)[source]#

The solution of an inverse problem, labeled.

fips.solve() builds it; there is no need to build one by hand. It keeps what the method kept from the solve (its Solution), and each output is computed from it when first asked for, labeled with the problem’s spaces, then kept. For the "analytic" method the posterior is Gaussian: estimate is its mean (so mean is the same object), and the posterior covariance is \(\hat{S} = (H^T S_z^{-1} H + S_0^{-1})^{-1}\), with \(S_z\) divided by the regularization factor \(\gamma\). It holds what depends on the solve or on the m x m innovation covariance (innovation_cov); what needs neither is on the Problem (predict()).

Every member works for every method, except four that need more of the method than a Solution gives: mean (where the estimate is the mean), with_gamma() and with_data() (where the method can answer without solving again), and recovery() (where the estimate is linear in the observations). The analytic method has all four.

Parameters:
  • problem (Problem) – The problem that was solved.

  • solution (Solution) – What the method kept from the solve, which gives the unlabeled arrays (for the analytic method, a factorization: fips.methods.analytic.Whitened or Information).

  • options (Options) – The options of the method, such as fips.methods.analytic.AnalyticOptions.

See also

fips.solve

Solve a problem and return its posterior.

Examples

>>> import numpy as np
>>> import pandas as pd
>>> import fips
>>> cells = pd.Index(["a", "b"], name="cell")
>>> obs_id = pd.Index(["o1", "o2", "o3"], name="obs_id")
>>> prior = fips.Vector.from_series(pd.Series(0.0, index=cells), block="flux")
>>> obs = fips.Vector.from_series(
...     pd.Series([1.0, 2.0, 3.0], index=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, 0.0], [0.0, 1.0], [1.0, 1.0]]), obs.space, prior.space
...     ),
... )
>>> post = fips.solve(problem)
>>> post.estimate.values.round(3)
array([0.997, 1.906])
>>> round(post.dofs, 3)
1.877

Attributes

chi2

the sum of the data and the state misfits.

dofs

Degrees of freedom for signal, the trace of averaging_kernel().

dofs_per_element

the diagonal of averaging_kernel(), on the prior's space.

estimate

The posterior state estimate, \(\hat{x}\), on the prior's space.

information_content

The Shannon information content of the observations about the state, in nats.

innovation_cov

The covariance of the innovation, \(H S_0 H^T + S_z / \gamma\), dense.

kalman_gain

The gain \(K\), state by observations, dense.

mean

The posterior mean, estimate itself.

modeled_obs

The observations the estimate models, \(H \hat{x} + c\).

options

The options the method solved with (gamma).

problem

The problem that was solved.

r2

The R² of the enhancement, \(\operatorname{corr}(z - c, H\hat{x})^2\).

reduced_chi2

chi2 divided by the number of observations; near 1 when the covariances are right.

rmse

The root mean square of the observations minus modeled_obs.

uncertainty_reduction

One minus the ratio of the posterior to the prior total error.

variances

The posterior error variances, the diagonal of \(\hat{S}\).

Methods

averaging_kernel([W])

Return the averaging kernel, of the state or of aggregates of it.

candidate_worth(forward, obs_cov, by, W)

Return what each group of candidate observations, not in the problem, would add to the certainty of each aggregate.

chi2_tests()

Test whether the innovation, the residual and the increment are as large as the covariances say: Rodgers' four chi-squared tests.

cov([W])

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

data_worth(by, W)

Return what each group of observations adds to the certainty of each aggregate, and its share of DOFS.

desroziers([by])

Compare the observation error variances Desroziers et al. (2005) diagnose with those the solve used.

leverage(x)

Return the leverage matrix of the state x: which observations weigh most on it.

recovery([world, truth, W, level])

Return how well the estimate recovers the truth when the data come from world: exactly, without sampling.

summary()

Return the diagnostics of the solve as a table of one row.

uncertainty([W])

Return the prior and posterior uncertainty of each aggregate, and how much the observations reduce it.

with_data(obs)

Return the posterior of the same problem with other observations.

with_gamma(gamma)

Return the posterior of the same problem with another regularization factor.