Skip to content

feat(kernels): nonstationary kernels for climate data (amplitude, Gibbs/Paciorek, Gneiting) #812

Open

Description

@thomaspinder

Feature Request

Describe the Feature Request

Climate fields are not stationary. Variability is larger over land than over sea, correlation lengths are shorter over mountains, and on the globe the structure changes with latitude. GPJax's nonstationary kernels (Linear, Polynomial, ArcCosine) are not the ones climate scientists use. The xarray example (#808) shows its largest errors at coastlines and over the Andes, which is a stationary kernel's typical failure.

Describe Preferred Solution

In order of priority:

  1. Changing amplitude. $k(x, y) = \sigma(x),\sigma(y),k_0(x, y)$, where $\sigma(\cdot)$ is a positive function, for example a softplus or exp of a mean function or of a linear model in covariates. It is a wrapper around any kernel.
  2. Gibbs / Paciorek–Schervish kernel. The lengthscale changes with location. For an isotropic $\ell(x)$ in $d$ dimensions:
    $$k(x, y) = \left(\frac{2,\ell(x),\ell(y)}{\ell(x)^2 + \ell(y)^2}\right)^{d/2} k_0!\left(\frac{\sqrt{2},\lVert x - y\rVert}{\sqrt{\ell(x)^2 + \ell(y)^2}}\right).$$
    • This is valid for any isotropic correlation that is positive definite on $\mathbb{R}^d$ for all $d$: RBF, the Matérn family, rational quadratic (Paciorek & Schervish, 2006).
    • An anisotropic version with a matrix $\Sigma(x)$ could come later.
    • $\log \ell(x)$ can be a parametric function of covariates (Risser & Calder, 2015), or a latent GP (Heinonen et al., 2016) as a later step.
  3. Axially symmetric use on the sphere. On the UnitSphere columns, make $\ell$ and $\sigma$ functions of latitude only (Jun & Stein, 2007, 2008). A kernel that is positive definite on $\mathbb{R}^3$ stays positive definite on the sphere. This could be documentation and a helper, not a new kernel.
  4. Gneiting space–time kernel (Gneiting, 2002). This is the standard nonseparable space–time covariance:
    $$C(h, u) = \frac{\sigma^2}{\psi(u^2)^{d/2}},\varphi!\left(\frac{\lVert h\rVert^2}{\psi(u^2)}\right),$$
    with $\varphi$ completely monotone and $\psi$ positive with a completely monotone derivative, for example $\varphi(t) = e^{-c t^{\gamma}}$ and $\psi(t) = (a t^{\alpha} + 1)^{\beta}$. Strictly it is stationary, but it is often requested with the kernels above.

API sketch:

kernel = gpx.kernels.Gibbs(
    base=gpx.kernels.Matern32(),
    lengthscale_fn=gpx.mean_functions.Linear(...),   # log-lengthscale over inputs
    active_dims=[0, 1, 2],                           # where the distance is taken
)
kernel = gpx.kernels.Amplitude(base=kernel, amplitude_fn=...)

Open design point: the lengthscale or amplitude function often depends on covariates (elevation, land fraction), while the distance is taken over spatial columns. The kernel must read different columns for these two roles, for example with active_dims for the distance and a separate column selection for the functions.

Describe Alternatives

  • Input warping / deep kernels. Already possible, and it covers the spatial-deformation method (Sampson & Guttorp, 1992). It is less interpretable, and it is harder to constrain.
  • SPDE/INLA nonstationary Matérn (Lindgren, Rue & Lindström, 2011). Very common in climate work, but it is a separate solver. Consider it after the Vecchia work.
  • Mixtures of local stationary processes (Fuentes, 2001). This is possible with sums of kernels and weights, but it has boundary artefacts.

Related Code

  • gpjax/kernels/base.py
  • gpjax/kernels/stationary/
  • gpjax/kernels/computations/
  • gpjax/mean_functions.py
  • gpjax/xarray.py (UnitSphere)

Additional Context

Acceptance criteria:

  • Positive-definiteness tests (hypothesis) for random lengthscale functions.
  • Gibbs reduces to the base kernel when $\ell$ is constant.
  • The kernels work with jit, grad and the existing compute engines.
  • An example on real data: a covariate-driven lengthscale over complex terrain, or latitude-dependent structure on the globe.

References:

  • Gibbs (1997), PhD thesis, University of Cambridge.
  • Paciorek & Schervish (2006), Spatial modelling using a new class of nonstationary covariance functions, Environmetrics 17:483–506.
  • Risser & Calder (2015), Regression-based covariance functions for nonstationary spatial modeling, Environmetrics 26:284–297.
  • Heinonen et al. (2016), Non-stationary Gaussian process regression with Hamiltonian Monte Carlo, AISTATS.
  • Jun & Stein (2007), An approach to producing space–time covariance functions on spheres, Technometrics 49:468–479; Jun & Stein (2008), Nonstationary covariance models for global data, Annals of Applied Statistics 2:1271–1289.
  • Gneiting (2002), Nonseparable, stationary covariance functions for space–time data, JASA 97:590–600.

If the feature request is approved, would you be willing to submit a PR?
Yes

Activity

  1. thomaspinder commented on Oct 4, 2026

    @thomaspinder
    CollaboratorAuthor

    Agreed design

    A design review settled the API below. The first PR implements all three kernels.

    Findings from the code survey

    • The kernel contract (__call__(x, y) -> scalar on single points) is sufficient. All compute engines vmap over __call__, so no existing code has to change.
    • Gibbs needs no refactor of the stationary kernels. If both inputs are scaled by $c = \sqrt{2/(\ell(x)^2 + \ell(y)^2)}$, an existing radial kernel gives the correct correlation:
      $$k(x, y) = \Big(\tfrac{2\ell(x)\ell(y)}{\ell(x)^2 + \ell(y)^2}\Big)^{d/2} k_0(c,x,; c,y).$$
      This matches a direct Paciorek–Schervish formula (ARD Matern32, 300 points) to 1.3e-15, and ARD base kernels work.
    • A location function evaluated inside __call__ runs only once per row ($N + M$ times for an $N \times M$ matrix), because vmap batches only the operations that depend on the mapped input. This is also true inside sum and product kernels. A special compute engine is therefore not necessary.
    • gpjax.mean_functions has no Linear. The API sketch in the issue body is replaced by the design below.

    Location functions — gpjax/kernels/location_functions.py

    A new abstract type, separate from mean functions (ADR 0001):

    • It evaluates one point (D,) and returns a scalar on the log scale. The kernel applies exp.
    • It selects its own columns with active_dims.
    • Constant: one log value. A constant function gives back the stationary kernel exactly.
    • Linear: active_dims is required, the weights start at zero (the model starts stationary), and there is no intercept by default (the base kernel holds the overall scale).

    Kernels

    • VaryingAmplitude(base, amplitude) in kernels/nonstationary/: $k = \sigma(x)\sigma(y)k_0(x, y)$.
    • Gibbs(base, lengthscale) in kernels/nonstationary/: input scaling as above. The base must have the new class flag isotropic_radial (RBF, Matern12/32/52, RationalQuadratic, PoweredExponential). Other bases raise TypeError.
    • For both wrappers, the wrapper's own active_dims must stay slice(None). The base kernel selects the distance columns, and the location function selects the covariate columns.
    • Gneiting in kernels/stationary/, a subclass of AbstractKernel (two lengthscales, no closed-form spectral density). Gneiting (2002, eq. 14):
      $$C(h, u) = \frac{\sigma^2}{\psi(u)^{d/2}} \exp!\Big(-\frac{(\lVert h\rVert/\ell_s)^{2\gamma}}{\psi(u)^{\beta\gamma}}\Big), \qquad \psi(u) = (|u|/\ell_t)^{2\alpha} + 1.$$
      Fields: space_dims: list[int] and time_dim: int. They are column indices of any array, not only of xarray data. $\alpha, \gamma \in (0, 1]$, $\beta \in [0, 1]$ ($\beta = 0$ is separable), and $\tau = d/2$ is fixed.

    Other changes

    • sample_approx and RFF give a clearer error for kernels that have no spectral density.
    • The missing constraint on PoweredExponential.power is a separate issue.

    Tests

    • Positive-definite Gram matrices (hypothesis) with random location-function weights and random parameters. jit, grad and fit work.
    • VaryingAmplitude and Gibbs reduce to the base kernel with a constant function. Gibbs matches the direct Paciorek–Schervish formula. Invalid bases raise TypeError.
    • Gneiting: $\beta = 0$ is separable, $u = 0$ gives a powered exponential in space, and time_dim in space_dims raises an error.

    Examples (Applied modelling)

    • Nonstationary Kernels over Complex Terrain: NOAA US Climate Normals 1991–2020, annual precipitation at Colorado stations, with elevation as the covariate (public domain; cite Menne et al. 2012). This follows Paciorek & Schervish (2006).
    • Space–Time Modelling of Irish Wind: Haslett & Raftery (1989) from StatLib ("Permission granted for unlimited distribution"), as in Gneiting (2002).
    • The results show held-out log predictive density, 90% interval coverage split by region, and maps of the fitted $\ell$ and $\sigma$, with RMSE for completeness. Paciorek & Schervish found the gain in likelihood and calibration, not in RMSE, so the notebooks do not claim a large RMSE gain.
  2. thomaspinder commented on Oct 4, 2026

    @thomaspinder
    CollaboratorAuthor

    Update: implementation in #815, with one change to the examples

    The space–time example does not use the Irish wind data, as the design above said. On that data the Gneiting kernel gave no benefit over its separable version. The profile log marginal likelihood over β ∈ [0, 1] was flat (Δ ≈ 1.5 in two different 180-day windows), and the free fit went to β ≈ 0. The empirical correlations show an interaction, but it comes from westerly advection, which is asymmetric, and the Gneiting family is symmetric (Gneiting, Genton & Guttorp, 2007).

    We tested other candidates:

    Data Δ log ML (best β vs. β = 0) Held-out NLPD
    NCEP R1 monthly temperature, North Atlantic/Europe 0.0 the same
    ERSST v5, tropical Pacific, monthly 6.8 worse
    ERSST v5, North Pacific, monthly 4.1 the same
    NCEP R1 daily temperature, Europe, Jan–Feb 2019 45.6 1.033 → 0.996
    NCEP R1 daily temperature, Europe, Jan–Feb 2020 19.9 0.667 → 0.642

    The example uses the 2019 European winter. The physical reason is that large anomalies persist longer than small ones, which is a symmetric interaction that the Gneiting kernel can represent. The notebook states the advection limit.

    The other parts of the design are implemented as agreed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions