/libkriging:libkrigingfrom libkriging
Guides selection of libKriging classes and options for Gaussian-process/Kriging models in C++, Python, R, Julia, Octave, or MATLAB. Covers plain GP, noisy data, mixed/categorical inputs, and large-n approximations.
Ships in libkriging. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
libKriging is a C++ Gaussian-process (Kriging) library with equivalent
bindings in Python, R, Julia, Octave and MATLAB. This skill tells an
assistant which class and options fit a given modelling problem; for the
exact call syntax in one language, open references/<language>.md.
All bindings expose the same concepts under the same names (kernel,
regmodel/trend, objective, optim, noise, parameters), so the
decision guide below is language-agnostic — only the syntax differs.
Ask, in order:
Is the response noise-free (deterministic simulator, e.g. a CFD/FEM
code)?
→ Kriging (interpolates the data exactly). See
Kriging.md for the model/objectives math.
Is the response noisy?
→ still Kriging, not a separate class (see
Noise.md for the math):
noise (a vector).
The noise of new points (update(y_u, noise_u, X_u) and
update_simulate(y_u, noise_u, X_u), both required for this model: the
forms without noise_u raise) and simulate's with_noise are variances too (same for
WarpKriging / MLPKriging's simulate(..., will_update, with_noise), in
C++ and every binding).noise="nugget" (estimates one
shared nugget term).NuggetKriging or NoiseKriging. These used to be
separate classes; both have been merged into Kriging's noise
argument. The old class names only still exist to load models saved
by older libKriging versions (see load() / load_kriging()), never
to fit new ones.Do inputs include categorical, ordinal, or otherwise non-linearly-scaled
variables, or do you want a learned input transform (Box-Cox, embeddings,
a small monotone network, …) instead of hand-picked features?
→ WarpKriging. It fits a per-variable warp jointly with the GP
hyperparameters by maximum likelihood; the public API mirrors Kriging
(fit, predict, simulate, update, summary, logLikelihood). Its
noise is a per-observation variance vector only (there is no
"nugget" mode), and it always fits with the "LL" objective.
Do you want a single deep/joint feature map across all inputs
(deep-kernel learning), rather than one warp per variable?
→ MLPKriging, a thin facade over WarpKriging with a joint MLP feature
map. Prefer plain WarpKriging when a per-variable warp is enough —
it's cheaper to fit and easier to interpret.
Is n (number of observations) too large for an O(n³) fit — say,
more than a few thousand points? (See
Scalability.md for the full method
inventory and combinability notes.)
→ Keep Kriging (not WarpKriging / MLPKriging: they accept
method but only implement "exact"), any objective
("LL" by default; "LOO" and "LMP" have approximate versions too,
noise-free only; "LL" also with a noise model),
but switch the fit method to one of the two scalable approximations
(O(n·m³) / O(n·k²) instead of O(n³); each approximates the
criterion, so don't expect bit-identical results to the exact fit):
method="vecchia" or "vecchia(m)" (default m=30
conditioning neighbors). Degrades in higher dimension because nearest
neighbors become less informative (recommended for d ≲ 5). Works
with noisy data too (noise="nugget" or known noise variances:
"response" Vecchia, accurate while the noise is small to moderate
relative to the signal variance; increase m or check against an
exact fit on a subsample when the noise dominates). See
Vecchia.md.method="nystrom" or "nystrom(k)" (default k=50
landmarks): a global low-rank approximation, dimension-robust in the
same way NestedKriging's NK aggregation is, but a single model
rather than a partition. Works with noisy data too (same noise=
argument as the exact fit; simulate with method="nystrom" draws
the latent process, no with_noise; a heterogeneous model's update
needs the new points' noise). See
Nystrom.md.predict / simulate / logLikelihood / leaveOneOut /
leaveOneOutVec / logMargPost take
method="exact" (default), "vecchia" / "vecchia(m)" or
"nystrom". A Vecchia or Nystrom fit holds no exact factorization,
so pass method="vecchia" / "nystrom" there (or k.method() as
is) — "exact" raises; approximate methods give mean / stdev only.
For the exact model at the fitted θ, make a separate exact fit with
optim="none" and that theta (is_theta_estim false). update
and save / load keep the method. See the table in
bindings/README.md.objective="LLVecchia(m)" / "LLNystrom(k)" (1.2 spelling) were
removed in 2.0 and raise an error: write objective="LL" with
method="vecchia(m)" / "nystrom(k)". Migrating 1.x code means
replacing every such objective, not catching the error.Is n large enough (~10⁴–10⁶) that even Vecchia/Nystrom are too
slow, and the design can be partitioned / prediction can be
parallelized?
→ NestedKriging: splits (X, y) into groups, fits one submodel per
group (Kriging by default, WarpKriging if a warp spec is given),
unifies hyperparameters, then aggregates predictions;
method="vecchia(m)" / "nystrom(k)" estimates the common prior with
one global approximate fit instead. See §3 for the
aggregation choice. Current restrictions: no nugget/noise channel,
normalize unsupported — mention these
if a user's request would hit them. NestedKriging is exposed in
pylibkriging (alongside Kriging/WarpKriging/MLPKriging), plus
the other bindings (C++/R/Julia/Octave-MATLAB).
Don't reach for NestedKriging, Vecchia or Nystrom by default — for the common case
(n in the hundreds to low thousands), plain Kriging with default options
is both simpler and, for NestedKriging's NK aggregation, actually a
fallback target (it converges to it as group size grows).
| Option | Values | Guidance |
|---|---|---|
kernel / covType | "gauss", "exp", "matern3_2", "matern5_2" ("whitenoise" exists but is an internal building block, not a modelling choice) | "matern5_2" is the sane general-purpose default (smoother than Matérn 3/2, less rigid than Gaussian, which tends to numerical ill-conditioning). Use "gauss" only if the underlying function is known to be very smooth/analytic. See Kernels.md for formulas. |
regmodel / trend | "constant", "linear", "interactive", "quadratic" ("none" = zero mean) | "constant" (ordinary kriging) is the default and usually the right start. Move to "linear" if the response has an obvious global trend the GP should not have to explain via short-range correlation. Avoid "quadratic"/"interactive" in high dimension — parameter count grows fast and can overfit the trend, starving the covariance part. |
objective | "LL" (log-likelihood, default), "LOO" (leave-one-out, details), "LMP" (log marginal posterior, details) | "LL" by default. "LOO" is a reasonable alternative when you specifically care about predictive accuracy at the design points rather than the full likelihood. "LMP" is a good alternative with few observations, where "LL" can drift θ into a degenerate (too small/too large) range. |
method | "exact" (default), "vecchia" / "vecchia(m)", "nystrom" / "nystrom(k)" | How the covariance is evaluated, for the fit and afterwards. Approximate methods only for scaling, with any objective (see §1.5; the approximate "LOO" is the leave-one-out of the approximate joint law, not of the local Vecchia predictor); noise models (both methods) only with objective="LL", "LOO" / "LMP" noise-free — they approximate the criterion, so don't use them on small problems expecting identical results to the exact fit. |
optim | "BFGS4" (default for Kriging: 4 random starts run in parallel, the best kept), "BFGSk" for k starts (e.g. "BFGS10"), "BFGS" (single start, the Kriging default up to 1.2; still the default of WarpKriging / NestedKriging; the 1.2 MLPKriging / WarpKriging default was "BFGS+Adam"), "none" | Use "none" only when supplying fixed/known hyperparameters via parameters (e.g. reusing a fit, or a controlled experiment). A single start misses the likelihood optimum on ~18 % of the benchmark data sets against ~5 % for "BFGS4" and ~1 % for "BFGS10" (docs/dev/rationalization/T3-default-multistart.md): for a difficult/multimodal likelihood (many or inactive inputs, LOO objective) or a suspicious fit, recommend "BFGS10"+; "BFGS2" when time is short (on the benchmark it is as good as the former restarted single start at a lower cost); "BFGS" only when fit time on a single core matters more than the optimum (x 1.6–3.7 cheaper there). Since 2.0 a single start is no longer restarted on a long-range solution (Optim::set_long_range_restart / LK_LONG_RANGE_RESTART removed, #466): code that relied on it should pass "BFGS2". |
normalize | boolean, default off | Turn on when input dimensions have very different scales/units — it rescales X/y to [0,1] internally, which helps the optimizer's bounds and starting values. On Kriging everything public stays in the original scale of X/y: parameters in, theta()/sigma2()/nugget()/noise()/beta() and the *Fun(theta) objectives (values and gradients) out, so they round-trip and match a normalize=false fit (X()/y() are the internal normalized data). Not on WarpKriging/MLPKriging (warped feature space); not supported yet on NestedKriging. |
noise | vector, "nugget", or absent | See §1.2. |
parameters | dict/struct with sigma2, theta, beta, plus per-argument is_*_estim flags | Use to seed the optimizer (multistart with multiple theta rows) or to fix a hyperparameter (is_theta_estim=false with a single theta row) rather than estimate it. A fixed theta stays fixed with any optim: with "BFGS" the other hyperparameters (nugget, heterogeneous-noise sigma2) are still optimized per their own is_*_estim flags, while optim="none" optimizes nothing. An is_*_estim=false flag without the matching value is ignored (the parameter is estimated). |
NestedKriging aggregation| Aggregation | Cost | Notes |
|---|---|---|
PoE, gPoE, BCM, rBCM | cheap: O(q·n²/p) | Precision-weighted products of experts. Fast, but predictive variances are not fully consistent (can be over/under-confident, especially PoE/BCM at group boundaries). |
NK (default) | O(q·n²) worst case | Kriges the submodel predictors themselves as noisy observations of the true GP — it is a proper kriging predictor: interpolates the data and gives consistent variances. Requires a "constant" trend (simple-kriging theory); the PoE family works with any trend. |
Default to NK unless the user is explicitly optimizing for raw prediction
speed at large q and can tolerate the PoE family's known variance
inconsistency.
WarpKriging per-variable warp specsOne spec string per input column, e.g. {"kumaraswamy", "categorical(5,2)", "none"}:
| Spec | Use for | Params | Details |
|---|---|---|---|
none | leave the variable as-is | 0 | — |
affine | rescale/shift a continuous variable | 2 | Warping-Affine.md |
boxcox | stabilize variance / skew on a positive continuous variable | 1 | Warping-BoxCox.md |
kumaraswamy | flexible monotone warp of a variable already in [0,1] | 2 | Warping-Kumaraswamy.md |
neural_mono(H) | more flexible monotone warp, H hidden units (default H=8) | 3H+1 | Warping-NeuralMono.md |
knots(K) / knots(t1:...:tK) | piecewise-linear warp, non-stationarity localized to specific regions (DiceKriging-style) | K+1 | Warping-Knots.md |
mlp(h1:h2,q,act) | unconstrained (non-monotone), possibly multi-dim, per-variable warp | depends on layers | Warping-MLP.md |
categorical(L,q) / categorical(["a","b",...], q) | unordered categorical with L levels, embedded in ℝ^q | L·q | Warping-Categorical.md |
ordinal(L) / ordinal(["low","med","high"]) | ordered categorical | L−1 | Warping-Ordinal.md |
Monotone warps (boxcox, kumaraswamy, neural_mono, knots) are fit
with a guard against squeezing a sub-range of the training inputs onto one
point (the noise-free likelihood is unbounded there, #406), and
kumaraswamy has a, b ∈ [1/3, 3]. If such a warp still predicts worse than
plain Kriging with a tiny predictive stdev, compare with Kriging on held-out
data rather than trusting the higher logLikelihood().
For a genuinely deep/joint transform across several continuous variables at
once, use MLPKriging (mlp_joint(h1:h2,q,act)-style joint map, see
Warping-MLPJoint.md) instead of
stacking per-variable warps. Valid act/activation values are "selu"
(default), "relu", "tanh", "sigmoid", "elu". If a user reports an
unstable or stuck fit with a single-start optimizer (optim="BFGS", no
restarts), suggest "tanh" over the default "selu": SELU's non-smooth
kink at z=0 can make the likelihood surface locally jagged for a
gradient-based optimizer — the analytic gradient is still correct, this is
an optimization-landscape issue, not a bug.
MLPKriging's predictive stdev is calibrated by a 5-fold cross-validation
after the fit (var_scale(), shown in summary(); the mean and
logLikelihood() are unchanged; the 5 refits are single starts, run in
parallel): without it, the many network weights
overfit the training points and the 95 % intervals can cover ~1 % of new
points (#407). Pass calibration_folds = "0" in parameters to skip it
(e.g. when only the mean matters and fit time is critical).
MLPKriging's default optimizer is "BFGS4" since 2.0 (4 joint L-BFGS-B
starts in parallel; #467). The former single start ("BFGS") stopped at a
poor mean on most problems: test Q² < 0.5 on 69 % of the cases of the
15-function MLP benchmark against 29 % for "BFGS4" and 25 % for
"BFGS10", and Q² −6 / −2.5 (tanh / selu) against 0.98 / 0.99 on the
projected-Branin 10D case of #407, for x 1.6 the CPU time of the single
start on one core and x 1.04 its wall time on 4 cores (5 calibration
folds both)
(docs/dev/rationalization/mlp-default-467.md). The 1.2.2 default was
"BFGS+Adam" without variance calibration, and "BFGS+Adam" itself changed
since (#382): no setting reproduces a 1.2.2 MLPKriging fit exactly (closest:
docs/Migration-2.0.md §2). Recommend "BFGS10" for a hard fit (high dimension,
Q² on held-out data below expectations). calibration_folds defaults to 5
(2.0; 3 was tried during 2.0 development): with the multistart default, 3
folds widen the intervals more (median test NLPD +0.15) for 0.75x the CPU
time; pass "3" only when fit time matters more.
Known inconsistency (2.0, documented, not changed: maintainer decision
2026-11-27, #464). WarpKriging keeps "BFGS" as default for every warping,
mlp_joint included, although WarpKriging(y, X, ["mlp_joint(...)"], kernel)
and MLPKriging are the same model on the same code path and MLPKriging
defaults to "BFGS4". With mlp_joint, always pass optim = "BFGS4" (or
more) explicitly, or use MLPKriging; this holds in every binding. A single
mlp_joint spec is passed unchanged for any number of columns of X (in
Python and R since 2.0, #503: 1.x recycled it per column and failed for d > 1),
while a single per-variable spec is recycled to every column. See
docs/Migration-2.0.md §27.
Even well fitted, MLPKriging is not a general replacement for Kriging:
on that benchmark (n 15–120, d 1–10) plain Kriging is better (test Q²
higher by > 0.05) on ~45 % of the cases with "BFGS4" (~40 % with
"BFGS10"), at a tenth of the cost; MLPKriging wins where the response
depends on a few combinations of the inputs (projected Branin). Compare
both on held-out data before recommending it.
logLikelihood() (and leaveOneOut() / logMargPost() for Kriging) is the
fit objective at the fitted parameters, the same in every class:
logLikelihood() == logLikelihoodFun(theta()), after fit, update and
load. For noise-free gauss / matern5_2 fits that objective has a tiny fixed
jitter on the diagonal of R (chol_jitter(), 1e-9 / 1e-10) while the model
used by predict is exact (model_chol_jitter() 0): compare models by
logLikelihood() only with the same kernel and noise model (a WarpKriging /
MLPKriging adds 1e-10 where Kriging adds nothing: matern3_2, exp, noise).
Process-wide settings (Optim optimizer settings such as set_max_iteration /
set_max_restart, Parallel thread settings, moved from Optim in 2.0, LinearAlgebra.set_chol_jitter) and
the LK_* environment variables: docs/Settings.md (one table, same names in
every binding; an environment variable only sets the default, read once when the
library is loaded, and a setter call overrides it). Recommend the setter in code;
the environment variable only for a run that must not change the code. An invalid
value of a variable is ignored with a [WARNING] line. Code written for 1.x that calls
Optim.set_num_threads_percent / optim_set_num_threads_percent (or the other thread
settings) must use Parallel / parallel_* since 2.0.
references/cpp.md — C++ (the reference API; every other binding mirrors it)references/python.md — pylibkrigingreferences/r.md — rlibkrigingreferences/julia.md — jlibkrigingreferences/octave-matlab.md — mLibKriging (Octave and MATLAB share the same .m classes)For worked, end-to-end examples — fitting the same test function with
libKriging and a competitor package, then mimicking one of the
competitor's specific features (DiceKriging's knots warp, RobustGaSP's
LMP objective, SMT's KPLS reduction, OpenTURNS's joint conditional
simulation, GPy's inducing points, scikit-learn's WhiteKernel, GPflow's
HMC hyperparameters, GaussianProcesses.jl's composable kernels, GPyTorch's
iterative/GPU scalability vs. method="nystrom(k)") — see the
notebooks under docs/comparisons/libKriging_vs_*.ipynb. Each ends with an
argument-correspondence table between libKriging and the competitor's API,
and is a good source to check exact option names against if this file and
the reference files disagree.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub libkriging/libkriging --plugin libkrigingOther plugins' skills for the same job