mixle.analysis.kriging module¶
Geostatistics: variograms and kriging (best linear unbiased spatial prediction).
Kriging predicts a spatially correlated field at unobserved locations and – unlike a black-box
regressor – returns a prediction variance that grows with distance from data. The spatial
correlation is encoded by a variogram gamma(h) (how fast values decorrelate with separation h):
empirical_variogram()/fit_variogram()– estimate and fit a variogram model (spherical / exponential / gaussian / matern; the Gaussian model is also reachable as"squared_exponential"/"rbf", its covariance being the squared-exponential kernel) with nugget (measurement error / micro-scale variance), sill (total variance), and range (correlation length), plus geometric anisotropy (direction-dependent range).
ordinary_kriging()– BLUP with an unknown constant mean; exact interpolation with no nugget, smoothing with one, and heteroscedastic (per-observation) noise.
universal_kriging()– kriging with a polynomial trend / external drift.
calibrate_variance()– rescale kriging variances so their predictive intervals hit a target coverage on held-out data (generic GP/kriging recalibration).
Coordinates are (n, d) arrays (typically d = 2); values are the measured field.
- class Variogram(model, nugget, psill, rng, nu=1.5, anisotropy=None)[source]
Bases:
objectA fitted variogram model
gamma(h) = nugget + psill * shape(h).- Parameters:
- model
"spherical","exponential","gaussian"(aka"squared_exponential"/"rbf"– covariancepsill * exp(-(h/rng)**2)), or"matern".- Type:
- nugget
discontinuity at
h=0(measurement error / micro-scale variance).- Type:
- psill
partial sill (correlated variance);
nugget + psillis the total sill.- Type:
- rng
range (correlation length).
- Type:
- nu
Matern smoothness (ignored by other models).
- Type:
- anisotropy
optional
(angle_rad, ratio)geometric anisotropy – coordinates are rotated byangleand the minor axis scaled by1/ratiobefore distances are taken.
- model: str
- nugget: float
- psill: float
- rng: float
- nu: float = 1.5
- empirical_variogram(coords, values, *, n_bins=15, max_dist=None)[source]
Binned empirical (semi-)variogram: mean
0.5 (z_i - z_j)^2by separation distance.
- fit_variogram(coords, values, *, model='spherical', n_bins=15, nu=1.5)[source]
Fit a variogram model to data by least squares on the empirical variogram.
- ordinary_kriging(coords, values, variogram, query, *, noise=None)[source]
Ordinary kriging: BLUP of the field at
queryunder an unknown constant mean.- Parameters:
coords (ndarray) –
(n, d)data locations.values (ndarray) –
(n,)measured field.variogram (Variogram) – a fitted
Variogram.query (ndarray) –
(q, d)prediction locations.noise (ndarray | None) – optional
(n,)per-observation measurement variance (heteroscedastic nugget); if None the homoscedasticvariogram.nuggetis used on the diagonal.
- Returns:
{'prediction', 'variance'}arrays of lengthq.- Return type:
- universal_kriging(coords, values, variogram, query, *, degree=1, noise=None)[source]
Universal kriging: kriging with a polynomial spatial trend (drift) of the given
degree.degree=1removes a linear trend,degree=2a quadratic one. Use when the field has a large-scale drift on top of the stationary residual the variogram describes.
- calibrate_variance(predicted_var, residuals, *, target=0.9)[source]
Scale factor that makes kriging predictive intervals hit a target coverage.
Finds
cso that standardised residualsresidual / sqrt(c * predicted_var)achieve thetargetcentral coverage under a Gaussian predictive. Returns the variance multiplierc; multiplypredicted_varby it to recalibrate (generic GP/kriging variance recalibration).