Skip to content

Covariance Matrix from Structure Fucntion #21

Closed

Description

@jbphyswx

It should be possible to estimate the covriance matrix from structure functions (check under what conditions).
We should offer this fucntionality

Activity

  1. self-assigned this
    on Jun 11, 2026
  2. jbphyswx commented on Sep 6, 2026

    @jbphyswx
    OwnerAuthor

    Implemented, and "check under what conditions" is the substantive part of the answer.

    r, C = covariance(result, variance)          # C(r) = C(0) − D(r)/2
    Σ    = covariance_matrix(points, r, C)       # C(‖xᵢ − xⱼ‖), positive-definiteness checked

    The condition is second-order stationarity. A structure function is twice the variogram, so D(r) = 2[C(0) − C(r)] and C(r) = C(0) − D(r)/2. A field that is merely intrinsically stationary has a variogram but need not have a finite variance — and then no covariance exists to compute, whatever number is supplied. Documented on the function rather than left implicit.

    variance is required and cannot be recovered from D. This is the exact complement of the spectral transform, where a variance argument would be wrong to accept: the k ≠ 0 spectrum follows from D(r) alone (verified to 2.3e-16 — adding a constant offset of 137 to a field leaves D unchanged to 4.6e-14 and the recovered spectrum unchanged to 1.3e-12), and only the k = 0 mode is lost. Same blindness, opposite consequence.

    Positive-definiteness is checked, not assumed — and measuring it changed the design. The first test asserted "a Gaussian kernel is positive definite, so the matrix is", and it failed: interpolating a positive-definite kernel does not preserve positive-definiteness.

    samples of C(r) over [0,6] spacing most negative eigenvalue
    60 0.102 −1.2e−03
    1 000 0.006 −3.8e−07
    5 000 0.0012 +8.0e−08
    the kernel itself, uninterpolated — +1.6e−09
    an oscillating function (no kernel at all) — −9.7

    Error falls as the square of the spacing and turns positive once resolved, while an invalid kernel is off by the scale of the matrix itself — nine orders apart. The error message therefore distinguishes the two causes, because "sampled too coarsely" and "not a covariance kernel" need different fixes. Tripping on a coarse C is useful output, not a nuisance.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions