The column is already a weighted sum¶
A methane retrieval does not hand out a continuous profile . It reports the mole fraction on a few model levels and, next to it, a pressure weighting function , so that the column average is
where and . So the integral of chapter 1, , has become a dot product, and the weighting function is the part of the product that holds the numerics. Anyone who compares two retrievals, or a retrieval against a model, has to apply the same to both, or the comparison picks up a difference in the weights instead of a difference in methane.
This is the whole idea of the section. Every integral integrix computes ends up as samples of the integrand times weights, summed, and the different modules are different ways of choosing those weights.
Rules: nodes and weights¶
A rule with nodes is a set of points and weights , . It approximates (1.1) by
where holds the weights and the samples . The error of the rule is . The measure of chapter 1 goes into the weights: a rule for is a rule for divided by , which is how the of (2.1) come about.
There are only a few ways to choose the weights, and the six modules of integrix use all of them (Table 2.1).
Table 2.1:How each integrix module chooses the weights of (2.2), with a geoscience example of each.
| Module | How the weights are chosen | Geoscience example |
|---|---|---|
rule | in advance, from the nodes: interpolation, Gauss, or cell areas | the of a latitude band, a pressure weighting function |
scan | the same weights, summed up to every node | optical depth from the top of the atmosphere to each level |
march | the weights of a Runge–Kutta or Adams method, on samples the stepper computes itself | an ocean model stepping its tracers |
adapt | after looking at : more nodes where the local error is large | a narrow absorption line |
expect | random nodes, with weights or importance ratios | an ensemble of emission rates |
adjoint | the same weights, read backwards, since | the sensitivity of a column to each level |
The rest of this chapter is about the first row of Table 2.1, because the others are built from it.
Interpolatory weights¶
The oldest way to get weights is to interpolate the samples and integrate the interpolant. Take distinct nodes on an interval and the polynomial of degree through the samples. Integrating it gives a weighted sum of the samples, with weights that depend only on the nodes, and those weights are the ones that integrate every monomial of degree exactly:
These are the moment equations. In matrix form they are , where is the transposed Vandermonde matrix with , and holds the moments . On with the ordinary length, .
We solve them below for equally spaced nodes on (the Newton–Cotes rules). With three nodes we get Simpson’s rule, and with eleven we get something we should not use.
import jax
jax.config.update("jax_enable_x64", True)
import einx
import jax.numpy as jnp
import lineax as lx
from jaxtyping import Array, Float
# Shapes: N nodes on [0, 1]
# user
def newton_cotes_weights(
n_nodes: int,
) -> tuple[Float[Array, "node"], Float[Array, "node"]]:
"""Solve the moment equations V w = b for N equally spaced nodes."""
# sₙ = (n − 1)/(N − 1)
nodes = jnp.linspace(0.0, 1.0, n_nodes) # → (N,)
# Aₙₘ = sₙᵐ
vandermonde = jnp.vander(nodes, increasing=True) # (N,) → (N, N)
# Vₘₙ = Aₙₘ
moment_matrix = einx.id("n m -> m n", vandermonde) # (N, N) → (N, N)
# m + 1 for m = 0, …, N − 1
exponents = jnp.arange(1.0, n_nodes + 1.0) # → (N,)
# bₘ = ∫₀¹ sᵐ ds = 1/(m + 1)
moments = 1.0 / exponents # (N,) → (N,)
# today (lineax)
# V as a linear operator
operator = lx.MatrixLinearOperator(moment_matrix) # (N, N) → (N, N) op
# today (lineax)
# w = V⁻¹ b, by a solve
solution = lx.linear_solve(operator, moments) # (N,) → (N,)
return nodes, solution.value
# the Simpson and Newton–Cotes weights, from the solves
simpson_nodes, simpson = newton_cotes_weights(3)
print("N = 3: ", jnp.round(simpson * 6.0, 10).tolist(), "/ 6")
eleven_nodes, eleven = newton_cotes_weights(11)
print(f"N = 11: min w = {float(eleven.min()):.3f}")
print(f"N = 11: sum |w| = {float(jnp.abs(eleven).sum()):.3f}")N = 3: [1.0, 4.0, 1.0] / 6
N = 11: min w = -0.435
N = 11: sum |w| = 3.065Exactness¶
A rule has degree of exactness when it integrates every polynomial of degree exactly and fails for some polynomial of degree . The moment equations give an interpolatory rule with nodes a degree of at least , and sometimes one more for free: Simpson’s three nodes are symmetric, so the odd moment about the midpoint also cancels and .
from integrix import rule
# Shapes: N = 3 nodes of Simpson's rule
for degree in (2, 3, 4):
# fₙ = sₙᵐ
powers = simpson_nodes**degree # (N,) → (N,)
# today (integrix)
# Î = ∑ₙ wₙ sₙᵐ
estimate = rule.integrate(simpson, powers).value # → ()
# I = ∫₀¹ sᵐ ds = 1/(m + 1)
exact = 1.0 / (degree + 1) # → ()
# E = Î − I
error = float(estimate) - exact # → ()
# round-off below 10⁻¹² counts as exact
verdict = "exact" if abs(error) < 1e-12 else f"error = {error:.2e}"
print(f"m = {degree}: {verdict}")m = 2: exact
m = 3: exact
m = 4: error = 8.33e-03Exactness is the language in which rules are compared. With nodes fixed in advance, is what the moment equations can promise. If we are also free to place the nodes, we have unknowns and can match moments, and that is the Gauss rule, with (chapter 3). A high degree is only useful when the integrand looks like a polynomial on the whole domain, though, and this is where the global and local thread starts.
Positive weights and noise¶
The eleven-node weights above sum to one, as they must, since they integrate the constant exactly. However, several of them are negative and the sum of their absolute values is about 3. That number matters for real data, because samples are never exact. If each sample carries an error (instrument noise, a retrieval error, round-off), the rule passes it on as
so is the amplification factor of the rule. With positive weights it equals , the size of the domain, which is the smallest it can be. With negative weights it grows, and for equally spaced nodes it grows without bound as increases (the Runge phenomenon, seen through the weights). Negative weights also break the positivity of chapter 1: a positive methane profile can come out with a negative column.
So we have three practical rules for weights, which the later chapters keep returning to.
Prefer positive weights. Gauss, Clenshaw–Curtis, the composite trapezoid and Simpson rules, cell areas and Monte Carlo all have them.
Never raise the degree by adding equally spaced nodes to one polynomial. Either move the nodes (Gauss, chapter 3) or cut the domain into pieces and use a low-degree rule on each (composite rules, chapter 3).
Keep the weights next to the data they came from. A pressure weighting function, a cell-area grid or a spectral response is part of the dataset, and integrix takes it as a plain array for exactly that reason.