Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Pilot — a band integral with a Bayesian-quadrature error bar

A band integral with a Bayesian-quadrature error bar

Open In Colab

A band-averaged radiance is Lˉ=∫R(λ)L(λ) dλ/∫R(λ) dλ\bar L = \int R(\lambda) L(\lambda)\,\mathrm{d}\lambda / \int R(\lambda)\,\mathrm{d}\lambda, the spectral radiance LL weighted by the band’s response RR. radtrax computes it on a fine grid, which is cheap when LL is cheap. When every L(λ)L(\lambda) is an expensive run, only a few wavelengths can be afforded, and the error from using few nodes goes unreported. Bayesian quadrature (BQ, integrix.expect.bayes_quad) puts a Gaussian-process prior on LL and returns the integral with a posterior standard deviation. This pilot (radtrax#340) asks whether that standard deviation is honest on one real band before anyone relies on it.

Answer: not for line-resolved radiances on this band. The spectrum here is a smooth continuum under thousands of methane lines narrower than the node spacing. Those lines set the error: with 32 nodes every rule is still about 0.7–0.9 % off, and BQ is no more accurate than the trapezoid rule at the same nodes. Plain BQ’s 95 % interval is far too narrow (it covers the truth 6–60 % of the time). With a nugget fitted to absorb the unresolved lines, the interval is close to honest from 16 nodes upward (inside the binomial band in four of the six cases with 16 or more nodes), but BQ then adds an error bar, not accuracy. On the same atmospheres without the lines, BQ is 18 to 1,600 times more accurate than the trapezoid rule and its interval is conservative. Section 7 gives the recommendation.

To rerun. integrix and kernellib are not radtrax dependencies, and integrix’s pins (gaussx 0.8.5, functax 0.0.15) conflict with radtrax’s lock, so install them without their dependencies into radtrax’s own environment and run the notebook with that environment’s Python (integrix’s Bayesian-quadrature tests pass on radtrax’s pins: gaussx 0.6.12, functax 0.0.6):

uv sync --all-groups
uv pip install --no-deps "integrix @ git+https://github.com/jejjohnson/integrix@v0.0.14" "kernellib @ git+https://github.com/jejjohnson/kernellib@v0.0.23"
uv run --no-sync jupyter nbconvert --to notebook --execute --inplace docs/notebooks/band_integral_bq_pilot.ipynb --ExecutePreprocessor.timeout=3600

1. The band and its dense reference

The band is Landsat 8 OLI’s SWIR2 (B7, about 2050–2350 nm), which overlaps the 2.3 µm methane band. Its response comes from radtrax’s bundled USGS table, projected onto the synthetic spectrum’s 0.01 nm grid. The dense reference is radtrax’s own band integration on that grid, Lˉ=∑gRgLg/∑gRg\bar L = \sum_g R_g L_g / \sum_g R_g, over about 31,800 wavelengths: that is the line-by-line cost that a handful of nodes would replace.

B7 support: 2039.4–2349.2 nm, 31800 grid wavelengths

For Bayesian quadrature the band is a measure, dΠ(λ)=R(λ) dλ/∫R\mathrm{d}\Pi(\lambda) = R(\lambda)\,\mathrm{d}\lambda / \int R, and BQ needs its kernel means zn=∫k(λ,λn) dΠz_n = \int k(\lambda, \lambda_n)\,\mathrm{d}\Pi and its initial error ∬k dΠ dΠ\iint k\,\mathrm{d}\Pi\,\mathrm{d}\Pi. Two forms of the measure were tried:

  • an integrix.expect.WeightedBox whose density interpolates RR, with kernel means computed by a 128-point Gauss–Legendre rule split at each node;

  • an integrix.expect.Empirical measure on 0.5 nm bins of the response: 622 atoms at the bins’ response-weighted centres, carrying the bins’ summed weights, so every kernel mean and the initial error are exact finite sums over the same atoms.

The cell below compares both with the dense sum over the fine grid. The weighted box is off by about 10-4 of the kernel means’ scale, because the published response has a kink every nanometre. That error is too large for BQ on a smooth spectrum: the weights K−1zK^{-1}z amplify it, and because the kernel means and the initial error come from different rules, the small posterior variance cancels to a negative number. In a first run of this notebook with the weighted box, the control below had larger errors than the piecewise-linear rule at 16 and 32 nodes, and a standard deviation of exactly zero (clipped). The binned measure is far closer to the dense sum for every lengthscale above a few nanometres, so the rest of the notebook uses it.

622 atoms
ℓ =    5 nm: kernel-mean error 6.3e-05 (weighted box), 2.3e-05 (binned) of max z
ℓ =   20 nm: kernel-mean error 6.0e-05 (weighted box), 4.7e-06 (binned) of max z
ℓ =   80 nm: kernel-mean error 7.8e-05 (weighted box), 9.3e-07 (binned) of max z

2. Atmospheres

Each atmosphere is a top-of-atmosphere radiance on the fine grid,

L(λ)=E(λ) ρ(λ) exp⁡ ⁣(−m σ(λ) Ω),L(\lambda) = E(\lambda)\,\rho(\lambda)\,\exp\!\big(-m\,\sigma(\lambda)\,\Omega\big),

with a smooth solar shape EE (a 5778 K Planck curve per wavelength from radiomax.thermal, in relative units), a linear surface albedo ρ\rho with a random slope of up to ±30 % across the band, the two-way air-mass factor m=1/cos⁡θ0+1m = 1/\cos\theta_0 + 1 of a nadir view (radiomax.geometry.air_mass_factor) for a solar zenith angle θ0\theta_0 uniform on 0–60°, a methane column Ω\Omega uniform between 1 and 10 times a background of 0.0105 kg/m² (about 1.9 ppm), and a methane cross-section σ(λ)\sigma(\lambda) drawn by radtrax.spectroscopy.synthetic.methane_cross_section (3,000 Lorentz lines of 0.1 nm half-width in the 2.3 µm band, new line positions for every atmosphere). The spectrum holds methane only: water vapour and CO₂, which absorb more strongly in B7, are left out, so the lines here are fewer and weaker than in a real B7 spectrum. The control repeats every atmosphere with Ω=0\Omega = 0, a smooth integrand.

<Figure size 900x300 with 1 Axes>

3. Three rules at the same nodes

Every rule sees the same NN radiances L(λn)L(\lambda_n), at nodes placed either evenly over the band’s support (both ends included) or one at random in each of NN equal cells (stratified).

  • Piecewise-linear (trapezoid). Interpolate LL linearly between the nodes (constant beyond the end nodes) and integrate that against RR on the fine grid; this is the trapezoid rule weighted by the response, the rule radtrax’s hat projection applies.

  • BQ. A Matérn-5/2 prior from kernellib on L−yˉL - \bar y, with yˉ\bar y the nodes’ mean as a constant prior mean; the lengthscale (a grid of 40 values from 1 to 400 nm) and the amplitude (in closed form) are fitted by marginal likelihood. bayes_quad returns I^=z⊤K−1y\hat I = z^\top K^{-1} y and σI2=∬k dΠ dΠ−z⊤K−1z\sigma_I^2 = \iint k\,\mathrm{d}\Pi\,\mathrm{d}\Pi - z^\top K^{-1} z.

  • BQ with a nugget. The same, with a white-noise variance η σ2\eta\,\sigma^2 on the diagonal, η\eta fitted jointly (0 or 16 values from 10-4 to 10). The nugget treats the unresolved lines as noise, which widens the interval; it enters through bayes_quad’s jitter, which adds jitter times the mean prior variance to the diagonal.

4. The sweep

For NN from 4 to 32, both placements and all 100 atmospheres, record each rule’s relative error (I^−Lˉ)/Lˉ(\hat I - \bar L)/\bar L and, for BQ, the standard deviation σI/Lˉ\sigma_I / \bar L and whether the 95 % interval I^±1.96 σI\hat I \pm 1.96\,\sigma_I covers Lˉ\bar L. The stratified nodes are redrawn for every atmosphere, so their coverage is also over node placements. The control runs the even placement on the continua.

5400 estimates in 545 s

5. Error against NN

Root-mean-square relative error over the 100 atmospheres, for each rule at the same nodes.

Loading...
<Figure size 1200x340 with 3 Axes>

6. Is the error bar honest?

For each BQ variant: the mean of σI\sigma_I, the RMS of the actual error, and the coverage of the 95 % interval over the 100 atmospheres. With 100 trials, a calibrated interval’s observed coverage falls in the binomial band printed below 95 % of the time (the 2.5 % and 97.5 % quantiles of Binomial(100, 0.95), divided by 100). The Clopper–Pearson column is the 95 % interval of the observed coverage itself. The verdict is too narrow below the band, too wide above it and calibrated inside it.

binomial band for a calibrated 95 % interval: 90–99 %
Loading...

7. Recommendation

Do not adopt BQ for B7 band integrals of line-resolved radiance. Four results from the tables above support this.

  • No accuracy gain. With methane lines in the spectrum, BQ’s error stays within about 25 % of the piecewise-linear rule’s at every NN, in either direction: 2.3–2.6 % at 4 nodes and 0.7–0.9 % at 32. The lines are narrower than any affordable node spacing, so the integrand is rough at the scale of the nodes, and no rule using these nodes resolves it.

  • A plain Matérn prior gives a misleading bar. Fitted by marginal likelihood, the prior reads the line structure as smooth variation, and its 95 % interval covers the truth only 6–18 % of the time on even nodes and 35–60 % on stratified ones.

  • A nugget makes the bar nearly honest, but only with enough nodes. Treating unresolved lines as white noise brings coverage into the binomial band at 16 and 32 even nodes and at 24 and 32 stratified ones, and leaves it just below the band (0.87–0.88) at 24 even and 16 stratified nodes. With 12 or fewer nodes it stays clearly too narrow. An error bar is then the whole benefit, and a sample standard error at the same nodes would be a cheaper way to get one; that alternative was not tested here.

  • The method is sound where its prior fits. On the smooth continuum, BQ is 18–1,600 times more accurate than the trapezoid rule, and its interval is conservative (coverage 100 %, with σI\sigma_I 6–90 times the actual error). That makes it worth revisiting for band integrals of quantities that are smooth at the node scale. This pilot measured that only on the control.

Two implementation findings carry over to any adoption. First, a tabulated response needs exact kernel means: the numerical WeightedBox kernel means were too inaccurate for a smooth integrand (section 1), and the binned Empirical measure fixed that. Second, the spectrum here holds methane only; water vapour and CO₂ lines in a real B7 spectrum would make it rougher still, which would not change the conclusion.