Nonlinear inversion¶
The end-to-end coupled inversion over the emission rate (Gaussian or lognormal), whichever blocks the transport backend declares (the source position and wind of the Tier I plume, the geometry of the column plume), the background and per-instrument biases, through each instrument's averaging kernel or a JAX radiance operator. plumax builds the forward, the prior and the quality masks; vardax solves it (ThreeDVar with L-BFGS in the whitened control) and gives the Laplace posterior (LaplaceCovariance). A column-plume solve retrieves the line density \(q = Q / U\), and CoupledResult.with_wind applies the wind after it. Needs the assim extra. Tier IV.
inversion
¶
Nonlinear end-to-end coupled inversion on vardax (implementation in plumax.coupled._src.inversion).
CoupledPrior
dataclass
¶
CoupledPrior(mean: Mapping[str, Float[Array, '*shape']], covariance: Float[Array, ' param'] | Float[Array, 'param param'])
Gaussian prior N(μ_θ, Σ_θ) on the stacked control, by named block.
The prior accepts any block name; :class:CoupledProblem checks the names
and shapes against what its transport backend declares.
Attributes:
| Name | Type | Description |
|---|---|---|
mean |
Mapping[str, Float[Array, '*shape']]
|
Prior mean μ_θ of each block. Exactly one emission block (for
the Tier I plume |
covariance |
Float[Array, ' param'] | Float[Array, 'param param']
|
Σ_θ over the flattened control, in :attr: |
Raises:
| Type | Description |
|---|---|
ValueError
|
On a covariance that does not match the control. |
layout
property
¶
(block, length) pairs in the flattened order (sorted by name).
log_emission
property
¶
Whether the emission is lognormal (controlled through log Q).
from_std
classmethod
¶
from_std(mean: Mapping[str, Float[Array, '*shape'] | float], std: Mapping[str, Float[Array, '*shape'] | float]) -> CoupledPrior
A diagonal prior from per-block means and standard deviations.
Σ_θ = diag(σ²), each block's σ broadcast to the block's shape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mean
|
Mapping[str, Float[Array, '*shape'] | float]
|
Prior mean μ_θ of each block. |
required |
std
|
Mapping[str, Float[Array, '*shape'] | float]
|
Prior standard deviation σ of each block, same keys. |
required |
Returns:
| Type | Description |
|---|---|
CoupledPrior
|
The prior. |
Raises:
| Type | Description |
|---|---|
ControlBlockError
|
If the keys differ, a deviation does not broadcast to its block's shape, or a deviation is not positive. |
Source code in src/plumax/coupled/_src/inversion.py
from_blocks
classmethod
¶
from_blocks(mean: Mapping[str, Float[Array, '*shape'] | float], covariance: Mapping[str, Float[Array, '*block'] | float]) -> CoupledPrior
A block-diagonal prior, Σ_θ = blockdiag(Σ₁, …, Σ_B).
A block's entry is a standard deviation σ (a scalar, or one per
element of the block), giving Σ_b = diag(σ²), or a dense (n, n)
covariance for a block of n elements, such as a
gauss_plume.CentrelinePrior matrix. With only standard deviations
the prior is diagonal and equals :meth:from_std.
Algorithm
- Order the blocks as :attr:
layoutdoes (by name). - Turn each standard deviation into a diagonal block.
- Place the blocks on the diagonal of Σ_θ.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mean
|
Mapping[str, Float[Array, '*shape'] | float]
|
Prior mean μ_θ of each block. |
required |
covariance
|
Mapping[str, Float[Array, '*block'] | float]
|
For each block, a standard deviation (scalar or one per element) or a dense covariance block. |
required |
Returns:
| Type | Description |
|---|---|
CoupledPrior
|
The prior. |
Raises:
| Type | Description |
|---|---|
ControlBlockError
|
If the keys differ, a dense block does not match its mean, or a standard deviation is not positive. |
Examples:
A scalar block and a dense block of two:
>>> import jax.numpy as jnp
>>> prior = CoupledPrior.from_blocks(
... mean={"background": 0.0, "centreline": jnp.zeros(2)},
... covariance={
... "background": 1e-4,
... "centreline": jnp.array([[4.0, 1.0], [1.0, 9.0]]),
... },
... )
>>> prior.covariance.shape
(3, 3)
>>> bool(jnp.allclose(prior.covariance[0, 0], 1e-8))
True
Source code in src/plumax/coupled/_src/inversion.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | |
flatten
¶
μ_θ as one vector, and the map from such a vector back to blocks.
Source code in src/plumax/coupled/_src/inversion.py
cholesky
¶
L with Σ_θ = L Lᵀ (√σ² on the diagonal for a diagonal prior).
Source code in src/plumax/coupled/_src/inversion.py
covariance_operator
¶
Σ_θ as an operator on the flat (D_θ,) control.
Source code in src/plumax/coupled/_src/inversion.py
CoupledProblem
dataclass
¶
CoupledProblem(forward: CoupledForward, prior: CoupledPrior, observations: Mapping[str, Float[Array, '*shape']], radiance_ops: Mapping[str, RadianceOperator] = dict(), radiance_variance: Mapping[str, Float[Array, '*shape'] | float] = dict())
The coupled forward, its prior and every instrument's observations.
Column instruments are observed through their averaging kernel (the
CoupledForward responses); an instrument named in radiance_ops is
observed through that operator instead, applied to its column (bias
included). Masks and variance inflation come from each instrument
(coupled.quality.apply_quality).
Attributes:
| Name | Type | Description |
|---|---|---|
forward |
CoupledForward
|
The coupled forward. A backend that is an
|
prior |
CoupledPrior
|
Prior on the control. |
observations |
Mapping[str, Float[Array, '*shape']]
|
Observations by instrument name: |
radiance_ops |
Mapping[str, RadianceOperator]
|
JAX radiance operators by instrument name. |
radiance_variance |
Mapping[str, Float[Array, '*shape'] | float]
|
Radiance error variance by instrument name, a
scalar or |
Raises:
| Type | Description |
|---|---|
ControlBlockError
|
If the prior names a block the backend does not declare, holds other than one emission block, or gives a block the wrong shape. |
ValueError
|
On missing or extra observations or a radiance operator without a variance. |
emission_block
property
¶
The emission block the prior holds, one of the backend's.
responses
¶
Unit-emission response of each instrument at this control.
Source code in src/plumax/coupled/_src/inversion.py
predict
¶
h_i(θ) for every instrument, by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
control
|
Mapping[str, Array]
|
The control, by block (as :meth: |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Array]
|
Columns |
Source code in src/plumax/coupled/_src/inversion.py
predict_stacked
¶
Every instrument's prediction, flattened and stacked, shape (D_y,).
Source code in src/plumax/coupled/_src/inversion.py
stacked_observations
¶
Observations, masks and Σ_ε stacked like :meth:predict_stacked.
A radiance pixel's mask and variance inflation apply to all its
channels. Masked values are zero, so a sum over the stacked residuals
(fit_diagnostics) needs no mask.
Source code in src/plumax/coupled/_src/inversion.py
CoupledResult
dataclass
¶
CoupledResult(map_estimate: dict[str, Array], std: dict[str, Array] | None, mean: Array, covariance: Array | None, emission_rate: Array, emission_std: Array, converged: bool, n_steps: int, cost: float, per_instrument_residuals: dict[str, Array], pixels_used: dict[str, int], prior: CoupledPrior | None = None, line_density: Array | None = None, line_density_std: Array | None = None, wind: tuple[float, float] | None = None, emission_block: str | None = None)
MAP and Laplace posterior of the coupled inversion.
emission_rate and emission_std are the posterior mean and standard
deviation of Q (population.PerEventPosterior): for a lognormal Q the
lognormal moments of the Laplace marginal on log Q,
E[Q] = exp(μ + σ²/2) and sd[Q] = E[Q] √(exp(σ²) − 1).
A column-plume solve retrieves the line density q = Q / U instead, with
the same moments in line_density and line_density_std; its
emission_rate and emission_std are NaN until :meth:with_wind
supplies the wind.
Attributes:
| Name | Type | Description |
|---|---|---|
map_estimate |
dict[str, Array]
|
MAP θ* by block ( |
std |
dict[str, Array] | None
|
Laplace posterior standard deviation by block ( |
mean |
Array
|
MAP θ* flattened, in |
covariance |
Array | None
|
Laplace covariance Σ_θ|y, |
emission_rate |
Array
|
Posterior mean of Q. |
emission_std |
Array
|
Posterior standard deviation of Q (NaN without the posterior). |
converged |
bool
|
optimistix's success flag for the L-BFGS solve. |
n_steps |
int
|
Iterations taken. |
cost |
float
|
𝒥 at the MAP, in the whitened control. |
per_instrument_residuals |
dict[str, Array]
|
y_i − h_i(θ*) by instrument, NaN where masked. |
pixels_used |
dict[str, int]
|
Pixels each instrument contributed at full weight. |
prior |
CoupledPrior | None
|
The prior the solve used ( |
line_density |
Array | None
|
Posterior mean of q [kg m⁻¹]; |
line_density_std |
Array | None
|
Posterior standard deviation of q (NaN without the posterior). |
wind |
tuple[float, float] | None
|
|
emission_block |
str | None
|
The emission block the solve fitted, as its backend
declared it; |
For a scalar Q it also carries the Tier V per-event payload
(population.PerEventPosterior): draws of Q from the Laplace marginal
of its block, N(Q, σ²) or log Q ~ N(log Q, σ²) for a lognormal Q, and the
log-density of that block's prior marginal, both exact for the Gaussian
laws on θ. For a line density these need the wind: log Q ~ N(μ_q + μ_U,
σ_q² + σ_U²) for the lognormal wind of :meth:with_wind.
with_wind
¶
The same result with the emission rate filled in, Q = q U.
For a lognormal wind independent of the fit, with σ_U² = log(1 + s_U² / U²) and μ_U = log U − σ_U² / 2, a lognormal line density gives log Q ~ N(μ_q + μ_U, σ_q² + σ_U²). The moments are those of the product of independent q and U, which equal that law's:
E[Q] = E[q] U,
Var[Q] = sd[q]² s_U² + sd[q]² U² + E[q]² s_U².
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
speed
|
float
|
Mean wind speed U [m s⁻¹]. |
required |
speed_std
|
float
|
Its standard deviation s_U [m s⁻¹]. |
required |
Returns:
| Type | Description |
|---|---|
CoupledResult
|
The result with |
CoupledResult
|
set. |
Raises:
| Type | Description |
|---|---|
ParameterError
|
If |
PayloadError
|
If the result holds no line density. |
Examples:
With no spread in the wind, Q is q times the speed:
>>> import jax.numpy as jnp
>>> result = CoupledResult(
... map_estimate={"log_line_density": jnp.log(0.1)},
... std={"log_line_density": jnp.asarray(0.15)},
... mean=jnp.log(0.1)[None],
... covariance=None,
... emission_rate=jnp.asarray(jnp.nan),
... emission_std=jnp.asarray(jnp.nan),
... converged=True,
... n_steps=1,
... cost=0.0,
... per_instrument_residuals={},
... pixels_used={},
... line_density=jnp.asarray(0.1),
... line_density_std=jnp.asarray(0.015),
... )
>>> rate = result.with_wind(speed=3.5, speed_std=0.0)
>>> bool(jnp.allclose(rate.emission_rate, 0.35))
True
Source code in src/plumax/coupled/_src/inversion.py
samples
¶
n draws of Q from the Laplace marginal of its block.
For a line density, Q = q U with U from the lognormal wind of
:meth:with_wind.
Raises:
| Type | Description |
|---|---|
PayloadError
|
Without the Laplace posterior, for a vector Q, or for a line density with no wind applied. |
Source code in src/plumax/coupled/_src/inversion.py
prior_logpdf
¶
log π(Q) of the prior marginal of Q's block.
For a log line density the prior's (μ_q,0, σ²_q,0) take the place of the posterior's: log Q ~ N(μ_q,0 + μ_U, σ²_q,0 + σ_U²).
Raises:
| Type | Description |
|---|---|
PayloadError
|
Without the prior, for a vector Q, for a line density with no wind applied, or for a linear line density, whose product with a lognormal wind has no closed-form density. |
Source code in src/plumax/coupled/_src/inversion.py
RadianceOperator
¶
Bases: Protocol
A JAX radiance operator: column enhancement → per-receptor channels.
RadianceObservationOperator, LinearisedRadianceOperator and
LayeredRadianceOperator qualify.
predict
¶
plume_response
¶
plume_response(source: PlumeSource, instrument: Instrument, location: Float[Array, ' 2'], wind: Float[Array, ' 2']) -> Float[Array, ' obs']
Tier I unit-emission column at a traced source position and wind.
coupled.column_response with the horizontal position and the wind
(speed, meteorological direction) as JAX arrays, so the coupled cost can
differentiate through them. The source height, stability class and levels
stay those of source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
PlumeSource
|
The Tier I source (height, stability, levels). |
required |
instrument
|
Instrument
|
The observing instrument. |
required |
location
|
Float[Array, ' 2']
|
Source |
required |
wind
|
Float[Array, ' 2']
|
|
required |
Returns:
| Type | Description |
|---|---|
Float[Array, ' obs']
|
The unit-emission column through the averaging kernel. |
Source code in src/plumax/coupled/_src/forward.py
solve_coupled
¶
solve_coupled(problem: CoupledProblem, *, initial: Mapping[str, Float[Array, '*shape'] | float] | None = None, method: Literal['lbfgs', 'gauss_newton'] = 'lbfgs', laplace: bool = True, rtol: float = 1e-08, atol: float = 1e-10, max_steps: int = 200) -> CoupledResult
MAP and Laplace posterior of the coupled problem, on vardax.
θ = argmin 𝒥(θ), Σ_θ|y = (Σ_θ⁻¹ + J_hᵀ Σ_ε⁻¹ J_h)⁻¹ at θ.
Algorithm
- Flatten the prior to μ_θ, factor Σ_θ = L Lᵀ.
- Stack observations, masks and Σ_ε over the instruments.
vardax.ThreeDVarwith the stacked forward as aCallableObson the flat(D_θ,)control."lbfgs"minimises 𝒥 in the whitened control θ = μ_θ + L χ from χ₀ = L⁻¹ (θ₀ − μ_θ), where θ₀ isinitial(μ_θ by default);"gauss_newton"solves the whitened residuals withargminax.solve.GaussNewtonCGfrom μ_θ.vardax.LaplaceCovarianceat θ*, materialised.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
CoupledProblem
|
The coupled problem. |
required |
initial
|
Mapping[str, Float[Array, '*shape'] | float] | None
|
Control the minimiser starts from, by block; blocks left out start at the prior mean. The prior is not changed, so the cost is the same from every start. L-BFGS only. |
None
|
method
|
Literal['lbfgs', 'gauss_newton']
|
|
'lbfgs'
|
laplace
|
bool
|
Also compute the Laplace posterior. |
True
|
rtol
|
float
|
Relative tolerance of the minimiser. |
1e-08
|
atol
|
float
|
Absolute tolerance of the minimiser. |
1e-10
|
max_steps
|
int
|
Iteration cap. |
200
|
Returns:
| Name | Type | Description |
|---|---|---|
The |
CoupledResult
|
class: |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
For |
ValueError
|
For an unknown |
ControlBlockError
|
If |
ImportError
|
Without the |
Source code in src/plumax/coupled/_src/inversion.py
752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 | |
Multistart¶
The image-fit cost has several minima in the source position, so solve_coupled_multistart runs solve_coupled(problem, initial=...) from each of several starts, with the same prior, and keeps the converged start with the lowest cost.
The coupled solve from several starting controls (implementation in plumax.coupled._src.multistart).
MultistartResult
dataclass
¶
MultistartResult(best: CoupledResult, index: int, costs: Float[ndarray, ' start'], converged: Bool[ndarray, ' start'], map_estimates: list[dict[str, Array]])
Every start's outcome, and the one that won.
Attributes:
| Name | Type | Description |
|---|---|---|
best |
CoupledResult
|
Result of the converged start with the lowest cost. |
index |
int
|
Position j* of that start. |
costs |
Float[ndarray, ' start']
|
Cost 𝒥(θ*_j) at each start's minimum. |
converged |
Bool[ndarray, ' start']
|
Whether each start converged. |
map_estimates |
list[dict[str, Array]]
|
MAP control of each start, by block. |
solve_coupled_multistart
¶
solve_coupled_multistart(problem: CoupledProblem, starts: Mapping[str, Float[Array, 'start ...']], **solve_options: Any) -> MultistartResult
The coupled solve from each start, keeping the lowest cost.
θ_j = argmin 𝒥(θ) from θ⁽⁰⁾_j; j = argmin_j 𝒥(θ*_j) over the converged j.
Algorithm
- Check that every block of
startshas the same number J of starts. - For each j, solve from the j-th start of each block; blocks not in
startsstart at the prior mean. - Keep the converged start with the lowest cost.
The starts run one after another in a Python loop; each is a full
:func:~plumax.coupled.solve_coupled.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
CoupledProblem
|
The coupled problem; its prior is the same for every start. |
required |
starts
|
Mapping[str, Float[Array, 'start ...']]
|
Starting values by block, with a leading axis of J starts. |
required |
**solve_options
|
Any
|
Passed to every :func: |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
The |
MultistartResult
|
class: |
Raises:
| Type | Description |
|---|---|
ControlBlockError
|
If |
ConvergenceError
|
If no start converges. |
ValueError
|
If |
Source code in src/plumax/coupled/_src/multistart.py
Fit diagnostics¶
fit_diagnostics reports what the data determined in a solved problem: the Fisher information at the MAP, the prior-free Cramér–Rao bound of each parameter, the share of each parameter's prior variance the data removed, the degrees of freedom for signal, how far the prior was pulled, and each instrument's residual statistics.
What the data determined in a coupled fit (implementation in plumax.coupled._src.diagnostics).
FitDiagnostics
dataclass
¶
FitDiagnostics(fisher_information: Float[ndarray, 'param param'], cramer_rao_std: dict[str, ndarray], data_fraction: dict[str, ndarray], dofs: float, prior_pull: dict[str, ndarray], reduced_chi2: dict[str, float], rms_residual: dict[str, float])
Information content and residual statistics of a coupled fit.
Attributes:
| Name | Type | Description |
|---|---|---|
fisher_information |
Float[ndarray, 'param param']
|
F = J_hᵀ Σ_ε⁻¹ J_h at θ*, in the prior's layout. |
cramer_rao_std |
dict[str, ndarray]
|
Prior-free bound √[F⁻¹]_aa by block; |
data_fraction |
dict[str, ndarray]
|
1 − [Σ_θ|y]_aa / [Σ_θ]_aa by block: 0 when the prior set the parameter, near 1 when the data did. |
dofs |
float
|
Degrees of freedom for signal d_s = tr A, with A the averaging
kernel ( |
prior_pull |
dict[str, ndarray]
|
(θ*_a − μ_θ,a) / √[Σ_θ]_aa by block. |
reduced_chi2 |
dict[str, float]
|
χ²_red = Σₙ ωₙ rₙ² / σₙ² / (N_i − d_s) by instrument. |
rms_residual |
dict[str, float]
|
√(Σₙ ωₙ rₙ² / N_i) by instrument. |
fit_diagnostics
¶
Diagnostics of a solved coupled problem.
F = J_hᵀ Σ_ε⁻¹ J_h; V[a] ≥ [F⁻¹]_aa; Σ_θ|y = (Σ_θ⁻¹ + F)⁻¹.
Algorithm
- Evaluate the Jacobian J_h of the stacked prediction at θ*.
- Form F = J_hᵀ Σ_ε⁻¹ J_h with the masked, inflated variances.
- Eigendecompose F; bound each parameter, or report inf.
- Compute the posterior and d_s with
gaussx_infer.information_diagnosticsand compare the posterior with the prior, block by block. - Compute the residual statistics of each instrument.
The posterior in step 4 is the Gauss–Newton one at θ*, the covariance
solve_coupled reports, recomputed here so a solve with
laplace=False can be diagnosed too. Each instrument's χ²_red uses the
d_s of the whole fit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
CoupledProblem
|
The coupled problem. |
required |
result
|
CoupledResult
|
Its solution, from |
required |
Returns:
| Name | Type | Description |
|---|---|---|
The |
FitDiagnostics
|
class: |
Examples:
A parameter the data never see has no prior-free bound and keeps its prior: here the bias of a second, fully masked instrument.
>>> import jax.numpy as jnp
>>> import plumax.coupled as cpl
>>> from plumax.gauss_plume import ColumnPlume, ColumnPlumeSource, PlumeGeometry
>>> receptors = jnp.stack(
... [jnp.linspace(100.0, 1000.0, 20), jnp.zeros(20)], axis=-1
... )
>>> seen = cpl.Instrument("EMIT", receptors, retrieval_variance=1e-8)
>>> masked = cpl.Instrument(
... "GHGSat", receptors, retrieval_variance=1e-8, mask=jnp.zeros(20)
... )
>>> geometry = PlumeGeometry(
... location=jnp.zeros(2),
... direction=0.0,
... reference_width=150.0,
... width_exponent=0.9,
... )
>>> source = ColumnPlumeSource(plume=ColumnPlume(), geometry=geometry)
>>> forward = cpl.build_coupled_forward(source, [seen, masked])
>>> observation = 0.1 * source.column_response(seen)
>>> prior = cpl.CoupledPrior.from_std(
... {"line_density": 0.0, "biases": jnp.zeros(2)},
... {"line_density": 1.0, "biases": 1e-3},
... )
>>> problem = cpl.CoupledProblem(
... forward=forward,
... prior=prior,
... observations={"EMIT": observation, "GHGSat": observation},
... )
>>> report = fit_diagnostics(problem, cpl.solve_coupled(problem))
>>> report.cramer_rao_std["biases"].tolist()[1]
inf
>>> float(report.data_fraction["biases"][1])
0.0
Source code in src/plumax/coupled/_src/diagnostics.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | |