krigekit.kriging_indicator#
Python wrapper for Multiple Indicator Kriging (MIK) and Sequential Indicator Simulation (SIS) via the Fortran t_kriging_indicator type.
Each of the K categories (or threshold classes) is treated as one indicator variable (ivar = 1..K). Estimation produces K probability values per block; simulation produces a single drawn category (encoded as a one-hot binary vector).
Indicator encoding and the K x K coregionalization are built with
IndicatorVariogramSystem and transferred with its
apply(); this wrapper only allocates the engine, solves, and post-processes
probabilities.
Typical workflow — estimation#
>>> system = IndicatorVariogramSystem(categories=[1, 2, 3])
>>> system.set_categorical_obs(obs_coord, obs_cat)
>>> system.set_indicator_vgm(vtype="sph", a_major=1000,
... sill_strategy="theoretical", cross_strategy="closure")
>>> ik = IndicatorKriging(ncat=3, ndim=2)
>>> system.apply(ik) # transfers indicators + K x K structures
>>> ik.set_grid(coord=grid_coord)
>>> for k in range(1, 4): ik.set_search(ivar=k, nmax=20)
>>> ik.solve()
>>> probs, var = ik.get_results() # probs.shape == (ngrid, ncat)
>>> del ik
Typical workflow — SIS#
>>> system = IndicatorVariogramSystem(categories=[1, 2, 3])
>>> system.set_categorical_obs(obs_coord, obs_cat)
>>> system.set_indicator_vgm(vtype="sph", sill=0.2, a_major=500,
... sill_strategy="uniform", cross_strategy="uniform")
>>> ik = IndicatorKriging(ncat=3, ndim=2, nsim=100)
>>> system.apply(ik)
>>> ik.set_grid(coord=grid_coord)
>>> ik.set_sim() # generates U(0,1) draws in Python and passes to Fortran
>>> for k in range(1, 4): ik.set_search(ivar=k, nmax=20)
>>> ik.solve()
>>> sims, _ = ik.get_results() # sims.shape == (ngrid, ncat, nsim)
... # each [:, :, i] is a one-hot encoded realisation
Classes#
Multiple Indicator Kriging and Sequential Indicator Simulation, |
Module Contents#
- class krigekit.kriging_indicator.IndicatorKriging(ncat: int, nvar: int | None = None, ndim: int = 2, ndrift: int = 0, unbias: int = 1, nsim: int = 0, anisotropic_search: bool = False, weight_correction: bool = False, use_old_weight: bool = False, store_weight: bool = False, cross_validation: bool = False, write_mat: bool = False, neglect_error: bool = True, varying_vgm: bool = False, std_ck: bool = False, verbose: bool = False, pf_cache: bool = False, weight_file: str = '', bounds: tuple | None = None, seed: int | None = None)#
Bases:
krigekit.kriging.KrigingMultiple Indicator Kriging and Sequential Indicator Simulation, with optional secondary co-variate support.
Extends
Kriging— all setup, solve, and results methods are inherited unchanged. The differences are:The Fortran object is a
t_kriging_indicator(created viakrige_ind_create), which overridesprepare,sim_draw, andpost_solveto implement indicator-specific behaviour.ncatnames the K indicator categories.nvardefaults toncat(pure MIS) but can be set larger to add secondary continuous co-variates for co-kriging MIS (see below).Indicator encoding and the K x K coregionalization are built with
IndicatorVariogramSystemand transferred via itsapply(); this engine wrapper no longer owns that construction.
- Parameters:
ncat (int) – Number of categories K. Indicator variables occupy ivar = 1..ncat.
nvar (int, optional) – Total number of co-kriging variables. Defaults to
ncat(pure MIS). Setnvar = ncat + Mto include M secondary continuous variables (ivar = ncat+1 .. nvar). Secondary variables contribute to the kriging weights but are excluded from the CDF draw and probability normalisation.ndim (int) – Number of spatial dimensions (2 or 3).
nsim (int) – 0 = estimation (returns probabilities); >0 = SIS (returns one-hot draws).
**kwargs – All other keyword arguments are passed through to
Kriging.
Notes
For SIS (
nsim > 0), callset_sim()afterset_grid().Co-kriging MIS example (K=3 categories + 1 secondary variable):
system = IndicatorVariogramSystem(categories=[1, 2, 3]) system.set_categorical_obs(coord, cats) system.set_indicator_vgm(vtype="sph", a_major=1000, sill_strategy="theoretical", cross_strategy="closure") ik = IndicatorKriging(ncat=3, nvar=4, ndim=2) system.apply(ik) # indicator block (ivar 1..3) ik.set_obs(ivar=4, coord=sec_coord, value=sec_val) # secondary ik.set_vgm(ivar=4, jvar=4, ...) # secondary auto/cross models ik.set_grid(coord=grid_coord) for k in range(1, 5): ik.set_search(ivar=k, nmax=20) ik.solve() probs, var = ik.get_results() # shape (ngrid, 3) — secondary excluded
- Parameters:
ndim (int) – Number of spatial dimensions (2 or 3).
nvar (int) – Number of variables (1 for ordinary/simple kriging, >1 for cokriging).
ndrift (int) – Number of external drift functions (0 = no drift).
unbias (int) – 1 = ordinary kriging (sum-of-weights = 1 constraint); 0 = simple kriging (no constraint, uses sk_mean).
nsim (int) – Number of simulations. 0 = kriging only; >0 = SGSIM.
anisotropic_search (bool) – Use anisotropic search ellipse for neighbour lookup.
weight_correction (bool) – Force kriging weights to be non-negative and sum to 1.
use_old_weight (bool) – Read pre-computed weights from
weight_fileinstead of solving.store_weight (bool) – Write computed weights to
weight_filewhile also estimating blocks.cross_validation (bool) – Leave-one-out cross-validation mode.
write_mat (bool) – Write matrix for debugging.
neglect_error (bool) – Ignore solver errors and set failed block to NaN instead of aborting.
varying_vgm (bool) – Use a different variogram per estimation block (spatially varying anisotropy). When True, call
set_vgm_block()for each block afterset_grid(). Defaults to False (single global model).std_ck (bool) –
Co-kriging unbiasedness formulation (only relevant when
nvar > 1andunbias=1).False(default) — Isaaks & Srivastava: single combined constraint (Σw₁ + Σw₂ = 1) plus a local-mean correction applied post-solve. Matches the GSLIB/legacy behaviour.True— standard cokriging: separate per-variable constraints (Σwᵢ = 1 for own variable, Σwⱼ = 0 for others), equivalent to the gstat/ISATIS formulation. Use this to match gstat output.
verbose (bool) – Print progress messages.
pf_cache (bool) – Enable the persistent between-solve factorization cache. When
True, the Cholesky factor of K is stored after the firstsolve()and reused on subsequent calls when the neighbour set and variogram are unchanged (speeds up repeated solves on the same observation grid). Defaults toFalse; enable only when you plan to callsolve()multiple times and need the speedup.weight_file (str) – Path to the weight file (required when use_old_weight or store_weight).
bounds (tuple(float, float) or None) – (lower, upper) clipping bounds for the estimate. None means no clipping (uses Fortran defaults: [-huge, +huge]).
seed (int, optional) – Random seed.
- get_results(copy: bool = False, squeeze: bool = True)#
Return indicator results, excluding secondary covariate channels.
The kriging engine stores all
nvarestimates internally because secondary variables participate in the cokriging system. Public indicator results contain only the firstncatvariables, matching the probability or one-hot category array documented by this class.
- set_sim(randpath: numpy.ndarray | None = None, sample: numpy.ndarray | None = None)#
Set up Sequential Indicator Simulation parameters.
Overrides
set_sim(). WhensampleisNone, delegates to the parent with no sample so that the Fortranset_sim_indicatoroverride generates U(0, 1) draws directly; no sample array is created in Python. Whensampleis supplied, validates that every value lies in [0, 1] then delegates to the parent.- Parameters:
randpath (ndarray of int, shape (nblocks,), optional) – Random visiting order (1-based). Generated with a random permutation if omitted.
sample (ndarray, shape (nblocks, nvar, nsim), optional) – Pre-drawn U(0, 1) samples. Every value must lie in [0, 1]. When
None, Fortran generates U(0, 1) viaset_sim_indicator.