| Title: | Kriging Modeling |
|---|---|
| Description: | An 'Eigen'-based computationally efficient 'C++' implementation for fitting various kriging models to data. This research is supported by U.S. National Science Foundation grant DMS-2310637. |
| Authors: | Chaofan Huang [aut], Difan Song [aut, cre], V. Roshan Joseph [aut] |
| Maintainer: | Difan Song <[email protected]> |
| License: | GPL (>= 2) |
| Version: | 1.1.0 |
| Built: | 2026-11-06 21:23:36 UTC |
| Source: | https://github.com/cran/rkriging |
This function adds a new design point and its corresponding output to the sequential design object and updates kriging (optionally refit the kriging hyperparameters).
Add.Next.Design(sequential, new.design, refit.kriging = TRUE)Add.Next.Design(sequential, new.design, refit.kriging = TRUE)
sequential |
a sequential design object (e.g., from ALM.Sequential, EI.Sequential, etc.) |
new.design |
a list containing:
|
refit.kriging |
a logical indicating whether to refit the kriging hyperparameters |
The new design is provided as a list containing:
Xa matrix or vector of new design point(s); if a vector, it will be converted to a 1×p matrix
ya vector of corresponding output value(s)
This function is typically used in a sequential design loop together with
Get.Next.Design, allowing fine-grained control over each iteration.
If the sequential object was created from a scaled kriging object, new.design$X
should be provided on the original input scale and is scaled internally before
updating the kriging model.
The sequential object (modified in-place).
Chaofan Huang, Difan Song, and V. Roshan Joseph
Get.Next.Design, Get.Sequential.
# one dimensional example f <- function(x) { x <- 0.5 + 2*x y <- sin(10*pi*x)/(2*x) + (x-1)^4 return (y) } set.seed(1234) n <- 10 p <- 1 X <- matrix(runif(n), ncol=p) y <- apply(X, 1, f) newX <- matrix(seq(0, 1, length=1001), ncol=p) # create sequential kriging <- Ordinary.Kriging(X, y, interpolation=TRUE, fit=TRUE, kernel.parameters=list(type="Gaussian")) design.parameters <- list(design.lower.bound=c(0), design.upper.bound=c(1)) sequential <- EI.Sequential(design.parameters, kriging) # sequential design loop with visualization for (i in 1:5) { # visualize current kriging pred <- Predict.Sequential(sequential, newX) plot(newX, f(newX), "l", main=sprintf("EI Iteration %d", i)) points(Get.Data(sequential)$X, Get.Data(sequential)$y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) # get next design and evaluate Xn <- Get.Next.Design(sequential) new.design <- list(X=Xn, y=f(Xn)) points(new.design$X, new.design$y, pch=16, col="green") # add to kriging and update sequential <- Add.Next.Design(sequential, new.design) } # final visualization pred <- Predict.Sequential(sequential, newX) plot(newX, f(newX), "l", main="EI Final") points(Get.Data(sequential)$X, Get.Data(sequential)$y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) best.design <- Get.Best.Design(sequential) points(best.design$design, best.design$objective, pch=16, col="green")# one dimensional example f <- function(x) { x <- 0.5 + 2*x y <- sin(10*pi*x)/(2*x) + (x-1)^4 return (y) } set.seed(1234) n <- 10 p <- 1 X <- matrix(runif(n), ncol=p) y <- apply(X, 1, f) newX <- matrix(seq(0, 1, length=1001), ncol=p) # create sequential kriging <- Ordinary.Kriging(X, y, interpolation=TRUE, fit=TRUE, kernel.parameters=list(type="Gaussian")) design.parameters <- list(design.lower.bound=c(0), design.upper.bound=c(1)) sequential <- EI.Sequential(design.parameters, kriging) # sequential design loop with visualization for (i in 1:5) { # visualize current kriging pred <- Predict.Sequential(sequential, newX) plot(newX, f(newX), "l", main=sprintf("EI Iteration %d", i)) points(Get.Data(sequential)$X, Get.Data(sequential)$y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) # get next design and evaluate Xn <- Get.Next.Design(sequential) new.design <- list(X=Xn, y=f(Xn)) points(new.design$X, new.design$y, pch=16, col="green") # add to kriging and update sequential <- Add.Next.Design(sequential, new.design) } # final visualization pred <- Predict.Sequential(sequential, newX) plot(newX, f(newX), "l", main="EI Final") points(Get.Data(sequential)$X, Get.Data(sequential)$y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) best.design <- Get.Best.Design(sequential) points(best.design$design, best.design$objective, pch=16, col="green")
This function creates an Active Learning MacKay (ALM) sequential design object for emulation (space-filling based on predictive uncertainty).
ALM.Sequential( design.parameters, kriging = NULL, kriging.parameters = NULL, nlopt.parameters = list() )ALM.Sequential( design.parameters, kriging = NULL, kriging.parameters = NULL, nlopt.parameters = list() )
design.parameters |
a list specifying the design space, containing:
|
kriging |
(optional if kriging.parameters provided) a fitted kriging class object (e.g., from Ordinary.Kriging or Fit.Kriging) |
kriging.parameters |
(optional if kriging provided) a list of parameters to create kriging via Fit.Kriging, must contain X, y and optionally other Fit.Kriging parameters |
nlopt.parameters |
a list of parameters for NLopt optimization (used when |
ALM selects the next design point as the one that maximizes the predictive standard deviation:
where is the kriging predictive standard deviation at .
This criterion is suitable for emulation tasks where the goal is to reduce overall prediction uncertainty.
The design space is specified via design.parameters, which must contain
design.lower.bound and design.upper.bound vectors.
During optimization, candidate points can be provided via design.candidates
in Get.Next.Design.
If the kriging object was fitted with scale=TRUE, design bounds,
candidates, new design points, predictions, returned designs, and returned data
are supplied and returned on the original input scale; scaling is handled
internally for the sequential criterion.
An ALM Sequential Class Object.
Chaofan Huang, Difan Song, and V. Roshan Joseph
MacKay, D. J. C. (1992). Information-based objective functions for active data selection. Neural computation, 4(4), 590-604.
Predict.Sequential, Get.Next.Design, Add.Next.Design.
# one dimensional example f <- function(x) { x <- 0.5 + 2*x y <- sin(10*pi*x)/(2*x) + (x-1)^4 return (y) } set.seed(1234) n <- 10 p <- 1 X <- matrix(runif(n), ncol=p) y <- apply(X, 1, f) newX <- matrix(seq(0, 1, length=1001), ncol=p) # create sequential kriging <- Ordinary.Kriging(X, y, interpolation=TRUE, fit=TRUE, kernel.parameters=list(type="Gaussian")) design.parameters <- list(design.lower.bound=c(0), design.upper.bound=c(1)) sequential <- ALM.Sequential(design.parameters, kriging) # sequential design loop with visualization n.iterations <- 5 for (i in 1:n.iterations) { # visualize current kriging pred <- Predict.Sequential(sequential, newX) plot(newX, f(newX), "l", main=sprintf("ALM Iteration %d", i)) points(Get.Data(sequential)$X, Get.Data(sequential)$y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) # get next design and evaluate Xn <- Get.Next.Design(sequential) new.design <- list(X=Xn, y=f(Xn)) points(new.design$X, new.design$y, pch=16, col="green") # add to kriging and update sequential <- Add.Next.Design(sequential, new.design) } # final visualization pred <- Predict.Sequential(sequential, newX) plot(newX, f(newX), "l", main="ALM Final") points(Get.Data(sequential)$X, Get.Data(sequential)$y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3)# one dimensional example f <- function(x) { x <- 0.5 + 2*x y <- sin(10*pi*x)/(2*x) + (x-1)^4 return (y) } set.seed(1234) n <- 10 p <- 1 X <- matrix(runif(n), ncol=p) y <- apply(X, 1, f) newX <- matrix(seq(0, 1, length=1001), ncol=p) # create sequential kriging <- Ordinary.Kriging(X, y, interpolation=TRUE, fit=TRUE, kernel.parameters=list(type="Gaussian")) design.parameters <- list(design.lower.bound=c(0), design.upper.bound=c(1)) sequential <- ALM.Sequential(design.parameters, kriging) # sequential design loop with visualization n.iterations <- 5 for (i in 1:n.iterations) { # visualize current kriging pred <- Predict.Sequential(sequential, newX) plot(newX, f(newX), "l", main=sprintf("ALM Iteration %d", i)) points(Get.Data(sequential)$X, Get.Data(sequential)$y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) # get next design and evaluate Xn <- Get.Next.Design(sequential) new.design <- list(X=Xn, y=f(Xn)) points(new.design$X, new.design$y, pch=16, col="green") # add to kriging and update sequential <- Add.Next.Design(sequential, new.design) } # final visualization pred <- Predict.Sequential(sequential, newX) plot(newX, f(newX), "l", main="ALM Final") points(Get.Data(sequential)$X, Get.Data(sequential)$y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3)
This function creates an Expected Improvement (EI) sequential design object for optimization (finding the minimum of the objective function).
EI.Sequential( design.parameters, kriging = NULL, kriging.parameters = NULL, nlopt.parameters = list() )EI.Sequential( design.parameters, kriging = NULL, kriging.parameters = NULL, nlopt.parameters = list() )
design.parameters |
a list specifying the design space, containing:
|
kriging |
(optional if kriging.parameters provided) a fitted kriging class object (e.g., from Ordinary.Kriging or Fit.Kriging) |
kriging.parameters |
(optional if kriging provided) a list of parameters to create kriging via Fit.Kriging, must contain X, y and optionally other Fit.Kriging parameters |
nlopt.parameters |
a list of parameters for NLopt optimization (used when |
EI selects the next design point as the one that maximizes the expected improvement:
where ,
and are the kriging predictive mean and standard deviation,
and and are the standard normal CDF and PDF.
This is the most popular acquisition function for Bayesian optimization.
The design space is specified via design.parameters, which must contain
design.lower.bound and design.upper.bound vectors.
During optimization, candidate points can be provided via design.candidates
in Get.Next.Design.
If the kriging object was fitted with scale=TRUE, design bounds,
candidates, new design points, predictions, returned designs, and returned data
are supplied and returned on the original input scale; scaling is handled
internally for the sequential criterion.
An EI Sequential Class Object.
Chaofan Huang, Difan Song, and V. Roshan Joseph
Jones, D. R., Schonlau, M., & Welch, W. J. (1998). Efficient global optimization of expensive black-box functions. Journal of Global optimization, 13(4), 455-492.
PI.Sequential, UCB.Sequential, UDF.Sequential, Get.Next.Design, Add.Next.Design, Get.Best.Design.
# one dimensional example f <- function(x) { x <- 0.5 + 2*x y <- sin(10*pi*x)/(2*x) + (x-1)^4 return (y) } set.seed(1234) n <- 10 p <- 1 X <- matrix(runif(n), ncol=p) y <- apply(X, 1, f) newX <- matrix(seq(0, 1, length=1001), ncol=p) # create sequential kriging <- Ordinary.Kriging(X, y, interpolation=TRUE, fit=TRUE, kernel.parameters=list(type="Gaussian")) design.parameters <- list(design.lower.bound=c(0), design.upper.bound=c(1)) sequential <- EI.Sequential(design.parameters, kriging) # sequential design loop with visualization for (i in 1:5) { # visualize current kriging pred <- Predict.Sequential(sequential, newX) plot(newX, f(newX), "l", main=sprintf("EI Iteration %d", i)) points(Get.Data(sequential)$X, Get.Data(sequential)$y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) # get next design and evaluate Xn <- Get.Next.Design(sequential) new.design <- list(X=Xn, y=f(Xn)) points(new.design$X, new.design$y, pch=16, col="green") # add to kriging and update sequential <- Add.Next.Design(sequential, new.design) } # final visualization pred <- Predict.Sequential(sequential, newX) plot(newX, f(newX), "l", main="EI Final") points(Get.Data(sequential)$X, Get.Data(sequential)$y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) best.design <- Get.Best.Design(sequential) points(best.design$design, best.design$objective, pch=16, col="green")# one dimensional example f <- function(x) { x <- 0.5 + 2*x y <- sin(10*pi*x)/(2*x) + (x-1)^4 return (y) } set.seed(1234) n <- 10 p <- 1 X <- matrix(runif(n), ncol=p) y <- apply(X, 1, f) newX <- matrix(seq(0, 1, length=1001), ncol=p) # create sequential kriging <- Ordinary.Kriging(X, y, interpolation=TRUE, fit=TRUE, kernel.parameters=list(type="Gaussian")) design.parameters <- list(design.lower.bound=c(0), design.upper.bound=c(1)) sequential <- EI.Sequential(design.parameters, kriging) # sequential design loop with visualization for (i in 1:5) { # visualize current kriging pred <- Predict.Sequential(sequential, newX) plot(newX, f(newX), "l", main=sprintf("EI Iteration %d", i)) points(Get.Data(sequential)$X, Get.Data(sequential)$y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) # get next design and evaluate Xn <- Get.Next.Design(sequential) new.design <- list(X=Xn, y=f(Xn)) points(new.design$X, new.design$y, pch=16, col="green") # add to kriging and update sequential <- Add.Next.Design(sequential, new.design) } # final visualization pred <- Predict.Sequential(sequential, newX) plot(newX, f(newX), "l", main="EI Final") points(Get.Data(sequential)$X, Get.Data(sequential)$y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) best.design <- Get.Best.Design(sequential) points(best.design$design, best.design$objective, pch=16, col="green")
This function computes the kernel (correlation) matrix.
Given the kernel class object and the input data of size n,
this function computes the corresponding kernel (correlation) matrix.
Evaluate.Kernel(kernel, X)Evaluate.Kernel(kernel, X)
kernel |
a kernel class object |
X |
input data |
The kernel (correlation) matrix of X evaluated by the kernel.
Chaofan Huang, Difan Song, and V. Roshan Joseph
n <- 5 p <- 3 X <- matrix(rnorm(n*p), ncol=p) lengthscale <- c(1:p) kernel <- Gaussian.Kernel(lengthscale) Evaluate.Kernel(kernel, X)n <- 5 p <- 3 X <- matrix(rnorm(n*p), ncol=p) lengthscale <- c(1:p) kernel <- Gaussian.Kernel(lengthscale) Evaluate.Kernel(kernel, X)
This function provides a common interface to fit various kriging models from the data. OK (Ordinary.Kriging), UK (Universal.Kriging), LK (Limit.Kriging), RK (Rational.Kriging), and GRK (Generalized.Rational.Kriging) are supported in this package.
Fit.Kriging( X, y, interpolation = TRUE, fit = TRUE, nugget = NULL, model = "OK", model.parameters = list(), kernel = NULL, kernel.parameters = list(), nlopt.parameters = list(), scale = FALSE )Fit.Kriging( X, y, interpolation = TRUE, fit = TRUE, nugget = NULL, model = "OK", model.parameters = list(), kernel = NULL, kernel.parameters = list(), nlopt.parameters = list(), scale = FALSE )
X |
a matrix for input (feature) |
y |
a vector for output (target), only one-dimensional output is supported |
interpolation |
whether to interpolate, for noisy data please set |
fit |
whether to fit the length scale parameters from data |
nugget |
an optional nugget value to add to the diagonal of the correlation matrix for numerical stability or noise modeling |
model |
choice of kriging model: OK, UK, LK, RK, GRK |
model.parameters |
a list of parameters required for the specific kriging model, e.g. basis functions for universal kriging |
kernel |
a kernel class object |
kernel.parameters |
a list of parameters required for the kernel, if no kernel class object is provided |
nlopt.parameters |
a list of parameters required for NLopt, including choice of optimization algorithm and maximum number of evaluation |
scale |
whether to scale each input dimension to |
Kriging gives the best linear unbiased predictor given the data. It can also be given a Bayesian interpretation by assuming a Gaussian process (GP) prior for the underlying function. Please see Santner et al. (2003), Rasmussen and Williams (2006), Joseph (2025), and Joseph (2026) for details.
For data from deterministic computer experiments, use interpolation=TRUE and will give an interpolator.
For noisy data, use interpolation=FALSE, which will give an approximator of the underlying function.
Currently, approximation is supported for OK (Ordinary.Kriging) and UK (Universal.Kriging).
The kernel choices are required and can be specified by
(i) providing the kernel class object to kernel
or (ii) specifying the kernel type and other parameters in kernel.parameters.
Please see examples section for detail usages.
When the lengthscale / correlation parameters are known, simply provide them in
(i) the kernel class object to kernel or (ii) in kernel.parameters,
and set fit=FALSE. The kriging model will be fitted with the user provided parameters.
When the lengthscale / correlation parameters are unknown,
they can be estimated via Maximum Likelihood method by setting fit=TRUE.
The initial / lower bound / upper bound of the lengthscale parameters can be provided in kernel.parameters,
otherwise a good initial and range would be estimated from the data.
The optimization is performed via NLopt,
a open-source library for nonlinear optimization.
All gradient-free optimization methods in NLopt
are supported and can be specified in nlopt.parameters.
See nloptr::nloptr.print.options() for the list of available derivative-free algorithms (prefix with NLOPT_GN or NLOPT_LN).
The maximum number of optimization steps can also be defined in nlopt.parameters.
Please see examples section for detail usages.
A Kriging Class Object. When scale=TRUE, the returned object stores the training input minima and maxima as scale_min and scale_max attributes.
Chaofan Huang, Difan Song, and V. Roshan Joseph
Santner, T. J., Williams, B. J., & Notz, W. I. (2003). The Design and Analysis of Computer Experiments. Springer.
Joseph, V. R. (2006). Limit kriging. Technometrics, 48(4), 458-466.
Joseph, V. R. (2025). Rational Kriging. Journal of the American Statistical Association. 120, 548-558.
Joseph, V. R. (2026). Experimental Design for Data Science and Engineering. Chapman & Hall/CRC, doi:10.1201/9781003661535.
Rasmussen, C. E. & Williams, C. K. (2006). Gaussian Processes for Machine Learning. The MIT Press.
Predict.Kriging, Get.Kriging.Parameters, Get.Kernel, Ordinary.Kriging, Universal.Kriging, Limit.Kriging, Rational.Kriging, Generalized.Rational.Kriging.
# one dimensional example f <- function(x) { x <- 0.5 + 2*x y <- sin(10*pi*x)/(2*x) + (x-1)^4 return (y) } set.seed(1234) # train set n <- 30 p <- 1 X <- matrix(runif(n),ncol=p) y <- apply(X, 1, f) newX <- matrix(seq(0,1,length=1001), ncol=p) ############################################################################# ################ Minimal Example for Fitting a Kriging Model ################ ############################################################################# # Ordinary Kriging kriging <- Fit.Kriging(X, y, interpolation=TRUE, fit=TRUE, model="OK", kernel.parameters=list(type="Gaussian")) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) Get.Kriging.Parameters(kriging) # Universal Kriging basis.function <- function(x) {c(1,x[1],x[1]^2)} kriging <- Fit.Kriging(X, y, interpolation=TRUE, fit=TRUE, model="UK", model.parameters=list(basis.function=basis.function), kernel.parameters=list(type="Gaussian")) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) Get.Kriging.Parameters(kriging) # Limit Kriging kriging <- Fit.Kriging(X, y, interpolation=TRUE, fit=TRUE, model="LK", kernel.parameters=list(type="Gaussian")) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) Get.Kriging.Parameters(kriging) # Rational Kriging kriging <- Fit.Kriging(X, y, interpolation=TRUE, fit=TRUE, model="RK", kernel.parameters=list(type="RQ",alpha=1)) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) Get.Kriging.Parameters(kriging) # Generalized Rational Kriging kriging <- Fit.Kriging(X, y, interpolation=TRUE, fit=TRUE, model="GRK", kernel.parameters=list(type="RQ",alpha=1)) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) Get.Kriging.Parameters(kriging) ############################################################################# ################ Fitting a Kriging Model with Kernel Object ################# ############################################################################# kernel <- Gaussian.Kernel(rep(1,p)) kriging <- Fit.Kriging(X, y, interpolation=TRUE, fit=TRUE, model="OK", kernel=kernel) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) Get.Kriging.Parameters(kriging) ############################################################################# ############### Creating a Kriging Model with Kernel Object ################# ############################################################################# # set fit = FALSE to create Kriging model with user provided kernel # no optimization for the length scale parameters kernel <- Gaussian.Kernel(rep(1e-1,p)) kriging <- Fit.Kriging(X, y, interpolation=TRUE, fit=FALSE, model="OK", kernel=kernel) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) Get.Kriging.Parameters(kriging) ############################################################################# ############ Fitting a Kriging Model with Range for Lengthscale ############# ############################################################################# kernel.parameters <- list( type = 'Gaussian', lengthscale = rep(1,p), # initial value lengthscale.lower.bound = rep(1e-3,p), # lower bound lengthscale.upper.bound = rep(1e3,p) # upper bound ) # if not provided, a good estimate would be computed from data kriging <- Fit.Kriging(X, y, interpolation=TRUE, fit=TRUE, model="OK", kernel.parameters=kernel.parameters) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) Get.Kriging.Parameters(kriging) ############################################################################# ########### Fitting a Kriging Model with Different Optimization ############# ############################################################################# nlopt.parameters <- list( algorithm = 'NLOPT_GN_DIRECT', # optimization method maxeval = 250 # maximum number of evaluation ) kriging <- Fit.Kriging(X, y, interpolation=TRUE, fit=TRUE, model="OK", kernel.parameters=list(type="Gaussian"), nlopt.parameters=nlopt.parameters) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) Get.Kriging.Parameters(kriging) # Global-Local Optimization nlopt.parameters <- list( algorithm = 'NLOPT_GN_MLSL_LDS', # optimization method local.algorithm = 'NLOPT_LN_SBPLX', # local algorithm maxeval = 250 # maximum number of evaluation ) kriging <- Fit.Kriging(X, y, interpolation=TRUE, fit=TRUE, model="OK", kernel.parameters=list(type="Gaussian"), nlopt.parameters=nlopt.parameters) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) Get.Kriging.Parameters(kriging) ############################################################################# ################# Fitting a Kriging Model from Noisy Data ################### ############################################################################# y <- y + 0.1 * rnorm(length(y)) kriging <- Fit.Kriging(X, y, interpolation=FALSE, fit=TRUE, model="OK", kernel.parameters=list(type="Gaussian")) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) Get.Kriging.Parameters(kriging)# one dimensional example f <- function(x) { x <- 0.5 + 2*x y <- sin(10*pi*x)/(2*x) + (x-1)^4 return (y) } set.seed(1234) # train set n <- 30 p <- 1 X <- matrix(runif(n),ncol=p) y <- apply(X, 1, f) newX <- matrix(seq(0,1,length=1001), ncol=p) ############################################################################# ################ Minimal Example for Fitting a Kriging Model ################ ############################################################################# # Ordinary Kriging kriging <- Fit.Kriging(X, y, interpolation=TRUE, fit=TRUE, model="OK", kernel.parameters=list(type="Gaussian")) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) Get.Kriging.Parameters(kriging) # Universal Kriging basis.function <- function(x) {c(1,x[1],x[1]^2)} kriging <- Fit.Kriging(X, y, interpolation=TRUE, fit=TRUE, model="UK", model.parameters=list(basis.function=basis.function), kernel.parameters=list(type="Gaussian")) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) Get.Kriging.Parameters(kriging) # Limit Kriging kriging <- Fit.Kriging(X, y, interpolation=TRUE, fit=TRUE, model="LK", kernel.parameters=list(type="Gaussian")) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) Get.Kriging.Parameters(kriging) # Rational Kriging kriging <- Fit.Kriging(X, y, interpolation=TRUE, fit=TRUE, model="RK", kernel.parameters=list(type="RQ",alpha=1)) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) Get.Kriging.Parameters(kriging) # Generalized Rational Kriging kriging <- Fit.Kriging(X, y, interpolation=TRUE, fit=TRUE, model="GRK", kernel.parameters=list(type="RQ",alpha=1)) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) Get.Kriging.Parameters(kriging) ############################################################################# ################ Fitting a Kriging Model with Kernel Object ################# ############################################################################# kernel <- Gaussian.Kernel(rep(1,p)) kriging <- Fit.Kriging(X, y, interpolation=TRUE, fit=TRUE, model="OK", kernel=kernel) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) Get.Kriging.Parameters(kriging) ############################################################################# ############### Creating a Kriging Model with Kernel Object ################# ############################################################################# # set fit = FALSE to create Kriging model with user provided kernel # no optimization for the length scale parameters kernel <- Gaussian.Kernel(rep(1e-1,p)) kriging <- Fit.Kriging(X, y, interpolation=TRUE, fit=FALSE, model="OK", kernel=kernel) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) Get.Kriging.Parameters(kriging) ############################################################################# ############ Fitting a Kriging Model with Range for Lengthscale ############# ############################################################################# kernel.parameters <- list( type = 'Gaussian', lengthscale = rep(1,p), # initial value lengthscale.lower.bound = rep(1e-3,p), # lower bound lengthscale.upper.bound = rep(1e3,p) # upper bound ) # if not provided, a good estimate would be computed from data kriging <- Fit.Kriging(X, y, interpolation=TRUE, fit=TRUE, model="OK", kernel.parameters=kernel.parameters) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) Get.Kriging.Parameters(kriging) ############################################################################# ########### Fitting a Kriging Model with Different Optimization ############# ############################################################################# nlopt.parameters <- list( algorithm = 'NLOPT_GN_DIRECT', # optimization method maxeval = 250 # maximum number of evaluation ) kriging <- Fit.Kriging(X, y, interpolation=TRUE, fit=TRUE, model="OK", kernel.parameters=list(type="Gaussian"), nlopt.parameters=nlopt.parameters) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) Get.Kriging.Parameters(kriging) # Global-Local Optimization nlopt.parameters <- list( algorithm = 'NLOPT_GN_MLSL_LDS', # optimization method local.algorithm = 'NLOPT_LN_SBPLX', # local algorithm maxeval = 250 # maximum number of evaluation ) kriging <- Fit.Kriging(X, y, interpolation=TRUE, fit=TRUE, model="OK", kernel.parameters=list(type="Gaussian"), nlopt.parameters=nlopt.parameters) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) Get.Kriging.Parameters(kriging) ############################################################################# ################# Fitting a Kriging Model from Noisy Data ################### ############################################################################# y <- y + 0.1 * rnorm(length(y)) kriging <- Fit.Kriging(X, y, interpolation=FALSE, fit=TRUE, model="OK", kernel.parameters=list(type="Gaussian")) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) Get.Kriging.Parameters(kriging)
This function specifies the Gaussian / Squared Exponential (SE) / Radial Basis Function (RBF) kernel.
Gaussian.Kernel(lengthscale)Gaussian.Kernel(lengthscale)
lengthscale |
a vector for the positive length scale parameters |
The Gaussian kernel is given by
where
is the euclidean distance between and weighted by
the length scale parameters 's.
A Gaussian Kernel Class Object.
Chaofan Huang, Difan Song, and V. Roshan Joseph
Duvenaud, D. (2014). The kernel cookbook: Advice on covariance functions.
Rasmussen, C. E. & Williams, C. K. (2006). Gaussian Processes for Machine Learning. The MIT Press.
n <- 5 p <- 3 X <- matrix(rnorm(n*p), ncol=p) lengthscale <- c(1:p) # approach 1 kernel <- Gaussian.Kernel(lengthscale) Evaluate.Kernel(kernel, X) # approach 2 kernel <- Get.Kernel(lengthscale, type="Gaussian") Evaluate.Kernel(kernel, X)n <- 5 p <- 3 X <- matrix(rnorm(n*p), ncol=p) lengthscale <- c(1:p) # approach 1 kernel <- Gaussian.Kernel(lengthscale) Evaluate.Kernel(kernel, X) # approach 2 kernel <- Get.Kernel(lengthscale, type="Gaussian") Evaluate.Kernel(kernel, X)
This functions fits the generalized rational kriging model to the data.
Generalized.Rational.Kriging( X, y, fit = TRUE, nugget = NULL, kernel = NULL, kernel.parameters = list(), nlopt.parameters = list() )Generalized.Rational.Kriging( X, y, fit = TRUE, nugget = NULL, kernel = NULL, kernel.parameters = list(), nlopt.parameters = list() )
X |
a matrix for input (feature) |
y |
a vector for output (target), only one-dimensional output is supported |
fit |
whether to fit the length scale parameters from data |
nugget |
an optional nugget value to add to the diagonal of the correlation matrix for numerical stability or noise modeling |
kernel |
a kernel class object |
kernel.parameters |
a list of parameters required for the kernel, if no kernel class object is provided |
nlopt.parameters |
a list of parameters required for NLopt, including choice of optimization algorithm and maximum number of evaluation |
Ordinary kriging and rational kriging can be obtained as special cases of generalized rational kriging. Please see Joseph (2025) for details. The Spectra library is used for fast computation of the first eigenvalues/vectors. Only interpolation is available. Noisy output is not supported for generalized rational kriging.
The kernel choices are required and can be specified by
(i) providing the kernel class object to kernel
or (ii) specifying the kernel type and other parameters in kernel.parameters.
Please see examples section of Fit.Kriging for detail usages.
When the lengthscale / correlation parameters are unknown,
all parameters including the constant mean can be estimated via Maximum Likelihood method by setting fit=TRUE.
The initial / lower bound / upper bound of the lengthscale parameters can be provided in kernel.parameters,
otherwise a good initial and range would be estimated from the data.
The optimization is performed via NLopt library,
a open-source library for nonlinear optimization.
All gradient-free optimization methods in NLopt
are supported and can be specified in nlopt.parameters.
See nloptr::nloptr.print.options() for the list of available derivative-free algorithms (prefix with NLOPT_GN or NLOPT_LN).
The maximum number of optimization steps can also be defined in nlopt.parameters.
Please see examples section of Fit.Kriging for detail usages.
A Generalized Rational Kriging Class Object.
Chaofan Huang, Difan Song, and V. Roshan Joseph
Joseph, V. R. (2025). Rational Kriging. Journal of the American Statistical Association. 120, 548-558.
Qiu, Y., Guennebaud, G., & Niesen, J. (2015). Spectra: C++ library for large scale eigenvalue problems.
Fit.Kriging, Predict.Kriging, Get.Kriging.Parameters.
# one dimensional example f <- function(x) { x <- 0.5 + 2*x y <- sin(10*pi*x)/(2*x) + (x-1)^4 return (y) } set.seed(1234) # train set n <- 30 p <- 1 X <- matrix(runif(n),ncol=p) y <- apply(X, 1, f) newX <- matrix(seq(0,1,length=1001), ncol=p) # approach 1 kriging <- Generalized.Rational.Kriging(X, y, fit=TRUE, kernel.parameters=list(type="RQ",alpha=1)) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) Get.Kriging.Parameters(kriging) # approach 2 kriging <- Fit.Kriging(X, y, interpolation=TRUE, fit=TRUE, model="GRK", kernel.parameters=list(type="RQ",alpha=1)) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) Get.Kriging.Parameters(kriging)# one dimensional example f <- function(x) { x <- 0.5 + 2*x y <- sin(10*pi*x)/(2*x) + (x-1)^4 return (y) } set.seed(1234) # train set n <- 30 p <- 1 X <- matrix(runif(n),ncol=p) y <- apply(X, 1, f) newX <- matrix(seq(0,1,length=1001), ncol=p) # approach 1 kriging <- Generalized.Rational.Kriging(X, y, fit=TRUE, kernel.parameters=list(type="RQ",alpha=1)) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) Get.Kriging.Parameters(kriging) # approach 2 kriging <- Fit.Kriging(X, y, interpolation=TRUE, fit=TRUE, model="GRK", kernel.parameters=list(type="RQ",alpha=1)) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) Get.Kriging.Parameters(kriging)
This function returns the best (minimum) objective value and its corresponding design from an optimization sequential design object (e.g., EI.Sequential, PI.Sequential, UCB.Sequential).
Get.Best.Design(sequential)Get.Best.Design(sequential)
sequential |
an optimization sequential design object |
If the sequential object was created from a scaled kriging object, the returned best design is converted back to the original input scale.
A list with components:
designthe design (input) corresponding to the best objective
objectivethe best (minimum) objective value
Chaofan Huang, Difan Song, and V. Roshan Joseph
EI.Sequential, PI.Sequential, UCB.Sequential.
# one dimensional example f <- function(x) { x <- 0.5 + 2*x y <- sin(10*pi*x)/(2*x) + (x-1)^4 return (y) } set.seed(1234) n <- 10 p <- 1 X <- matrix(runif(n), ncol=p) y <- apply(X, 1, f) newX <- matrix(seq(0, 1, length=1001), ncol=p) # fit kriging kriging <- Ordinary.Kriging(X, y, interpolation=TRUE, fit=TRUE, kernel.parameters=list(type="Gaussian")) design.parameters <- list(design.lower.bound=c(0), design.upper.bound=c(1)) sequential <- EI.Sequential(design.parameters, kriging) # sequential design loop with visualization for (i in 1:5) { # visualize current kriging pred <- Predict.Sequential(sequential, newX) plot(newX, f(newX), "l", main=sprintf("EI Iteration %d", i)) points(Get.Data(sequential)$X, Get.Data(sequential)$y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) # get next design and evaluate Xn <- Get.Next.Design(sequential) new.design <- list(X=Xn, y=f(Xn)) points(new.design$X, new.design$y, pch=16, col="green") # add to kriging and update sequential <- Add.Next.Design(sequential, new.design) } # final visualization pred <- Predict.Sequential(sequential, newX) plot(newX, f(newX), "l", main="EI Final") points(Get.Data(sequential)$X, Get.Data(sequential)$y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) best.design <- Get.Best.Design(sequential) points(best.design$design, best.design$objective, pch=16, col="green")# one dimensional example f <- function(x) { x <- 0.5 + 2*x y <- sin(10*pi*x)/(2*x) + (x-1)^4 return (y) } set.seed(1234) n <- 10 p <- 1 X <- matrix(runif(n), ncol=p) y <- apply(X, 1, f) newX <- matrix(seq(0, 1, length=1001), ncol=p) # fit kriging kriging <- Ordinary.Kriging(X, y, interpolation=TRUE, fit=TRUE, kernel.parameters=list(type="Gaussian")) design.parameters <- list(design.lower.bound=c(0), design.upper.bound=c(1)) sequential <- EI.Sequential(design.parameters, kriging) # sequential design loop with visualization for (i in 1:5) { # visualize current kriging pred <- Predict.Sequential(sequential, newX) plot(newX, f(newX), "l", main=sprintf("EI Iteration %d", i)) points(Get.Data(sequential)$X, Get.Data(sequential)$y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) # get next design and evaluate Xn <- Get.Next.Design(sequential) new.design <- list(X=Xn, y=f(Xn)) points(new.design$X, new.design$y, pch=16, col="green") # add to kriging and update sequential <- Add.Next.Design(sequential, new.design) } # final visualization pred <- Predict.Sequential(sequential, newX) plot(newX, f(newX), "l", main="EI Final") points(Get.Data(sequential)$X, Get.Data(sequential)$y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) best.design <- Get.Best.Design(sequential) points(best.design$design, best.design$objective, pch=16, col="green")
This function retrieves the current training data (X and y) from a sequential design object.
Get.Data(sequential)Get.Data(sequential)
sequential |
a sequential design object (e.g., from ALM.Sequential, EI.Sequential, etc.) |
The sequential design object maintains the current training data internally.
This function provides access to both the design matrix X and the corresponding output vector y.
If the sequential object was created from a scaled kriging object, X is
converted back to the original input scale.
A list with components:
Xthe design matrix (training inputs)
ythe output vector (training responses)
Chaofan Huang, Difan Song, and V. Roshan Joseph
# one dimensional example f <- function(x) { x <- 0.5 + 2*x y <- sin(10*pi*x)/(2*x) + (x-1)^4 return (y) } set.seed(1234) n <- 10 p <- 1 X <- matrix(runif(n), ncol=p) y <- apply(X, 1, f) newX <- matrix(seq(0, 1, length=1001), ncol=p) # create sequential kriging <- Ordinary.Kriging(X, y, interpolation=TRUE, fit=TRUE, kernel.parameters=list(type="Gaussian")) design.parameters <- list(design.lower.bound=c(0), design.upper.bound=c(1)) sequential <- EI.Sequential(design.parameters, kriging) Get.Data(sequential)# one dimensional example f <- function(x) { x <- 0.5 + 2*x y <- sin(10*pi*x)/(2*x) + (x-1)^4 return (y) } set.seed(1234) n <- 10 p <- 1 X <- matrix(runif(n), ncol=p) y <- apply(X, 1, f) newX <- matrix(seq(0, 1, length=1001), ncol=p) # create sequential kriging <- Ordinary.Kriging(X, y, interpolation=TRUE, fit=TRUE, kernel.parameters=list(type="Gaussian")) design.parameters <- list(design.lower.bound=c(0), design.upper.bound=c(1)) sequential <- EI.Sequential(design.parameters, kriging) Get.Data(sequential)
This function provides a common interface to specify various kernels. See arguments section for the available kernels in this package.
Get.Kernel(lengthscale, type, parameters = list())Get.Kernel(lengthscale, type, parameters = list())
lengthscale |
a vector for the positive length scale parameters |
type |
kernel type: Gaussian, RQ, IM, Matern12, Matern32, Matern52, Matern, UDF, MultiplicativeRQ, MultiplicativeIM, MultiplicativeMatern, MultiplicativeUDF |
parameters |
a list of parameters required for the specific kernel |
A Kernel Class Object.
Chaofan Huang, Difan Song, and V. Roshan Joseph
Duvenaud, D. (2014). The kernel cookbook: Advice on covariance functions.
Rasmussen, C. E. & Williams, C. K. (2006). Gaussian Processes for Machine Learning. The MIT Press.
Evaluate.Kernel, Gaussian.Kernel, RQ.Kernel, IM.Kernel, Matern12.Kernel, Matern32.Kernel, Matern52.Kernel Matern.Kernel, UDF.Kernel, MultiplicativeRQ.Kernel, MultiplicativeIM.Kernel, MultiplicativeMatern.Kernel, MultiplicativeUDF.Kernel.
n <- 5 p <- 3 X <- matrix(rnorm(n*p), ncol=p) lengthscale <- c(1:p) # Gaussian kernel <- Get.Kernel(lengthscale, type="Gaussian") Evaluate.Kernel(kernel, X) # Rational Quadratic (RQ) kernel <- Get.Kernel(lengthscale, type="RQ", parameters=list(alpha=1)) Evaluate.Kernel(kernel, X) # Inverse Multiquadric (IM) kernel <- Get.Kernel(lengthscale, type="IM", parameters=list(alpha=1)) Evaluate.Kernel(kernel, X) # Matern(1/2) kernel <- Get.Kernel(lengthscale, type="Matern12") Evaluate.Kernel(kernel, X) # Matern(3/2) kernel <- Get.Kernel(lengthscale, type="Matern32") Evaluate.Kernel(kernel, X) # Matern(5/2) kernel <- Get.Kernel(lengthscale, type="Matern52") Evaluate.Kernel(kernel, X) # Generalized Matern kernel <- Get.Kernel(lengthscale, type="Matern", parameters=list(nu=2.01)) Evaluate.Kernel(kernel, X) # User Defined Function (UDF) Kernel kernel.function <- function(sqdist) {return (exp(-sqrt(sqdist)))} kernel <- Get.Kernel(lengthscale, type="UDF", parameters=list(kernel.function=kernel.function)) Evaluate.Kernel(kernel, X) # Multiplicative Rational Quadratic (RQ) kernel <- Get.Kernel(lengthscale, type="MultiplicativeRQ", parameters=list(alpha=1)) Evaluate.Kernel(kernel, X) # Multiplicative Inverse Multiquadric (IM) kernel <- Get.Kernel(lengthscale, type="MultiplicativeIM", parameters=list(alpha=1)) Evaluate.Kernel(kernel, X) # Multiplicative Generalized Matern kernel <- Get.Kernel(lengthscale, type="MultiplicativeMatern", parameters=list(nu=2.01)) Evaluate.Kernel(kernel, X) # Multiplicative User Defined Function (UDF) kernel.function <- function(sqdist) {return (exp(-sqrt(sqdist)))} kernel <- Get.Kernel(lengthscale, type="MultiplicativeUDF", parameters=list(kernel.function=kernel.function)) Evaluate.Kernel(kernel, X)n <- 5 p <- 3 X <- matrix(rnorm(n*p), ncol=p) lengthscale <- c(1:p) # Gaussian kernel <- Get.Kernel(lengthscale, type="Gaussian") Evaluate.Kernel(kernel, X) # Rational Quadratic (RQ) kernel <- Get.Kernel(lengthscale, type="RQ", parameters=list(alpha=1)) Evaluate.Kernel(kernel, X) # Inverse Multiquadric (IM) kernel <- Get.Kernel(lengthscale, type="IM", parameters=list(alpha=1)) Evaluate.Kernel(kernel, X) # Matern(1/2) kernel <- Get.Kernel(lengthscale, type="Matern12") Evaluate.Kernel(kernel, X) # Matern(3/2) kernel <- Get.Kernel(lengthscale, type="Matern32") Evaluate.Kernel(kernel, X) # Matern(5/2) kernel <- Get.Kernel(lengthscale, type="Matern52") Evaluate.Kernel(kernel, X) # Generalized Matern kernel <- Get.Kernel(lengthscale, type="Matern", parameters=list(nu=2.01)) Evaluate.Kernel(kernel, X) # User Defined Function (UDF) Kernel kernel.function <- function(sqdist) {return (exp(-sqrt(sqdist)))} kernel <- Get.Kernel(lengthscale, type="UDF", parameters=list(kernel.function=kernel.function)) Evaluate.Kernel(kernel, X) # Multiplicative Rational Quadratic (RQ) kernel <- Get.Kernel(lengthscale, type="MultiplicativeRQ", parameters=list(alpha=1)) Evaluate.Kernel(kernel, X) # Multiplicative Inverse Multiquadric (IM) kernel <- Get.Kernel(lengthscale, type="MultiplicativeIM", parameters=list(alpha=1)) Evaluate.Kernel(kernel, X) # Multiplicative Generalized Matern kernel <- Get.Kernel(lengthscale, type="MultiplicativeMatern", parameters=list(nu=2.01)) Evaluate.Kernel(kernel, X) # Multiplicative User Defined Function (UDF) kernel.function <- function(sqdist) {return (exp(-sqrt(sqdist)))} kernel <- Get.Kernel(lengthscale, type="MultiplicativeUDF", parameters=list(kernel.function=kernel.function)) Evaluate.Kernel(kernel, X)
This function can be used for extracting the estimates of the kriging parameters.
Get.Kriging.Parameters(kriging)Get.Kriging.Parameters(kriging)
kriging |
a kriging class object |
loss |
the loss value of the fitted kriging model |
loss.type |
the loss type used for fitting (NLLH) |
lengthscale |
the lengthscale of the kernel |
mu |
mean of the kriging model |
nu2 |
variance of the kriging model |
sigma2 |
variance of the random noise when |
beta |
coefficients of the basis functions for universal kriging |
c |
c for the rational / generalized rational kriging, see Joseph (2025) |
c0 |
c0 for the generalized rational kriging, see Joseph (2025) |
scale |
whether the model was fitted on scaled inputs |
scale_min |
training input minima used for scaling, present when |
scale_max |
training input maxima used for scaling, present when |
Chaofan Huang, Difan Song, and V. Roshan Joseph
Joseph, V. R. (2006). Limit kriging. Technometrics, 48(4), 458-466.
Joseph, V. R. (2025). Rational Kriging. Journal of the American Statistical Association. 120, 548-558.
Joseph, V. R. (2026). Experimental Design for Data Science and Engineering. Chapman & Hall/CRC, doi:10.1201/9781003661535.
Rasmussen, C. E. & Williams, C. K. (2006). Gaussian Processes for Machine Learning. The MIT Press.
# one dimensional example f <- function(x) { x <- 0.5 + 2*x y <- sin(10*pi*x)/(2*x) + (x-1)^4 return (y) } set.seed(1234) # train set n <- 30 p <- 1 X <- matrix(runif(n),ncol=p) y <- apply(X, 1, f) newX <- matrix(seq(0,1,length=1001), ncol=p) kriging <- Fit.Kriging(X, y, interpolation=TRUE, fit=TRUE, model="OK", kernel.parameters=list(type="Gaussian")) Get.Kriging.Parameters(kriging)# one dimensional example f <- function(x) { x <- 0.5 + 2*x y <- sin(10*pi*x)/(2*x) + (x-1)^4 return (y) } set.seed(1234) # train set n <- 30 p <- 1 X <- matrix(runif(n),ncol=p) y <- apply(X, 1, f) newX <- matrix(seq(0,1,length=1001), ncol=p) kriging <- Fit.Kriging(X, y, interpolation=TRUE, fit=TRUE, model="OK", kernel.parameters=list(type="Gaussian")) Get.Kriging.Parameters(kriging)
This function selects the next design point using the sequential criterion.
Get.Next.Design(sequential, design.candidates = NULL)Get.Next.Design(sequential, design.candidates = NULL)
sequential |
a sequential design object (e.g., from ALM.Sequential, EI.Sequential, etc.) |
design.candidates |
(optional) a matrix of candidate design points; if provided, the next design is selected from this set instead of NLopt optimization |
If design.candidates is provided, the next design is selected from the candidate set
by evaluating the criterion at each candidate point.
Otherwise, NLopt optimization is used within the design space bounds
specified in design.parameters.
If the sequential object was created from a scaled kriging object,
design.candidates should be provided on the original input scale and
the returned next design is also on the original input scale.
A vector representing the next design point.
Chaofan Huang, Difan Song, and V. Roshan Joseph
Get.Sequential, Add.Next.Design.
# one dimensional example f <- function(x) { x <- 0.5 + 2*x y <- sin(10*pi*x)/(2*x) + (x-1)^4 return (y) } set.seed(1234) n <- 10 p <- 1 X <- matrix(runif(n), ncol=p) y <- apply(X, 1, f) newX <- matrix(seq(0, 1, length=1001), ncol=p) # fit kriging kriging <- Ordinary.Kriging(X, y, interpolation=TRUE, fit=TRUE, kernel.parameters=list(type="Gaussian")) design.parameters <- list(design.lower.bound=c(0), design.upper.bound=c(1)) sequential <- EI.Sequential(design.parameters, kriging) # sequential design loop with visualization for (i in 1:5) { # visualize current kriging pred <- Predict.Sequential(sequential, newX) plot(newX, f(newX), "l", main=sprintf("EI Iteration %d", i)) points(Get.Data(sequential)$X, Get.Data(sequential)$y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) # get next design and evaluate Xn <- Get.Next.Design(sequential) new.design <- list(X=Xn, y=f(Xn)) points(new.design$X, new.design$y, pch=16, col="green") # add to kriging and update sequential <- Add.Next.Design(sequential, new.design) } # final visualization pred <- Predict.Sequential(sequential, newX) plot(newX, f(newX), "l", main="EI Final") points(Get.Data(sequential)$X, Get.Data(sequential)$y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) best.design <- Get.Best.Design(sequential) points(best.design$design, best.design$objective, pch=16, col="green") # alternatively can pass a set of candidate points for finding the next design design.candidates <- matrix(seq(0,1,length=1001), ncol=p) Get.Next.Design(sequential, design.candidates=design.candidates)# one dimensional example f <- function(x) { x <- 0.5 + 2*x y <- sin(10*pi*x)/(2*x) + (x-1)^4 return (y) } set.seed(1234) n <- 10 p <- 1 X <- matrix(runif(n), ncol=p) y <- apply(X, 1, f) newX <- matrix(seq(0, 1, length=1001), ncol=p) # fit kriging kriging <- Ordinary.Kriging(X, y, interpolation=TRUE, fit=TRUE, kernel.parameters=list(type="Gaussian")) design.parameters <- list(design.lower.bound=c(0), design.upper.bound=c(1)) sequential <- EI.Sequential(design.parameters, kriging) # sequential design loop with visualization for (i in 1:5) { # visualize current kriging pred <- Predict.Sequential(sequential, newX) plot(newX, f(newX), "l", main=sprintf("EI Iteration %d", i)) points(Get.Data(sequential)$X, Get.Data(sequential)$y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) # get next design and evaluate Xn <- Get.Next.Design(sequential) new.design <- list(X=Xn, y=f(Xn)) points(new.design$X, new.design$y, pch=16, col="green") # add to kriging and update sequential <- Add.Next.Design(sequential, new.design) } # final visualization pred <- Predict.Sequential(sequential, newX) plot(newX, f(newX), "l", main="EI Final") points(Get.Data(sequential)$X, Get.Data(sequential)$y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) best.design <- Get.Best.Design(sequential) points(best.design$design, best.design$objective, pch=16, col="green") # alternatively can pass a set of candidate points for finding the next design design.candidates <- matrix(seq(0,1,length=1001), ncol=p) Get.Next.Design(sequential, design.candidates=design.candidates)
This function provides a common interface to create various sequential design objects. ALM (ALM.Sequential), EI (EI.Sequential), PI (PI.Sequential), UCB (UCB.Sequential), and UDF (UDF.Sequential) are supported.
Get.Sequential( design.parameters, kriging = NULL, kriging.parameters = NULL, method = "ALM", method.parameters = list(), nlopt.parameters = list() )Get.Sequential( design.parameters, kriging = NULL, kriging.parameters = NULL, method = "ALM", method.parameters = list(), nlopt.parameters = list() )
design.parameters |
a list specifying the design space, containing:
|
kriging |
(optional if kriging.parameters provided) a fitted kriging class object |
kriging.parameters |
(optional if kriging provided) a list of parameters to create kriging via Fit.Kriging, must contain X, y and optionally other Fit.Kriging parameters |
method |
choice of sequential design method: ALM, EI, PI, UCB, UDF |
method.parameters |
a list of parameters required for the specific method, e.g. |
nlopt.parameters |
a list of parameters for NLopt optimization (used when |
Sequential design methods select the next design point iteratively based on an acquisition criterion.
For emulation tasks (space-filling), use method="ALM" which maximizes predictive uncertainty.
For optimization tasks (finding the minimum), use method="EI", "PI", or "UCB".
A custom criterion can be specified via method="UDF".
The design space is specified via design.parameters, which must contain
design.lower.bound and design.upper.bound vectors.
During optimization, candidate points can be provided via design.candidates
in Get.Next.Design.
If the kriging object was fitted with scale=TRUE, design bounds,
candidates, new design points, predictions, returned designs, and returned data
are supplied and returned on the original input scale; scaling is handled
internally for the sequential criterion.
For method="UDF", the user-defined criterion function receives the
current training X on the original input scale.
The kriging model can be provided either as:
e.g., from Ordinary.Kriging or Fit.Kriging
as a list to pass to Fit.Kriging, must contain at least X and y
A Sequential Class Object.
Chaofan Huang, Difan Song, and V. Roshan Joseph
ALM.Sequential, EI.Sequential, PI.Sequential, UCB.Sequential, UDF.Sequential, Predict.Sequential, Get.Next.Design, Add.Next.Design.
# one dimensional example f <- function(x) { x <- 0.5 + 2*x y <- sin(10*pi*x)/(2*x) + (x-1)^4 return (y) } set.seed(1234) n <- 10 p <- 1 X <- matrix(runif(n), ncol=p) y <- apply(X, 1, f) newX <- matrix(seq(0, 1, length=1001), ncol=p) # create sequential kriging <- Ordinary.Kriging(X, y, interpolation=TRUE, fit=TRUE, kernel.parameters=list(type="Gaussian")) design.parameters <- list(design.lower.bound=c(0), design.upper.bound=c(1)) sequential <- Get.Sequential(design.parameters, kriging, method="EI") # sequential design loop with visualization for (i in 1:5) { # visualize current kriging pred <- Predict.Sequential(sequential, newX) plot(newX, f(newX), "l", main=sprintf("EI Iteration %d", i)) points(Get.Data(sequential)$X, Get.Data(sequential)$y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) # get next design and evaluate Xn <- Get.Next.Design(sequential) new.design <- list(X=Xn, y=f(Xn)) points(new.design$X, new.design$y, pch=16, col="green") # add to kriging and update sequential <- Add.Next.Design(sequential, new.design) } # final visualization pred <- Predict.Sequential(sequential, newX) plot(newX, f(newX), "l", main="EI Final") points(Get.Data(sequential)$X, Get.Data(sequential)$y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) best.design <- Get.Best.Design(sequential) points(best.design$design, best.design$objective, pch=16, col="green") # alternatively can create sequential by passing kriging parameters design.parameters <- list(design.lower.bound=c(0), design.upper.bound=c(1)) kriging.parameters <- list(X=X, y=y, interpolation=TRUE, fit=TRUE, kernel.parameters=list(type="Gaussian")) sequential <- Get.Sequential(design.parameters, kriging.parameters=kriging.parameters, method="EI")# one dimensional example f <- function(x) { x <- 0.5 + 2*x y <- sin(10*pi*x)/(2*x) + (x-1)^4 return (y) } set.seed(1234) n <- 10 p <- 1 X <- matrix(runif(n), ncol=p) y <- apply(X, 1, f) newX <- matrix(seq(0, 1, length=1001), ncol=p) # create sequential kriging <- Ordinary.Kriging(X, y, interpolation=TRUE, fit=TRUE, kernel.parameters=list(type="Gaussian")) design.parameters <- list(design.lower.bound=c(0), design.upper.bound=c(1)) sequential <- Get.Sequential(design.parameters, kriging, method="EI") # sequential design loop with visualization for (i in 1:5) { # visualize current kriging pred <- Predict.Sequential(sequential, newX) plot(newX, f(newX), "l", main=sprintf("EI Iteration %d", i)) points(Get.Data(sequential)$X, Get.Data(sequential)$y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) # get next design and evaluate Xn <- Get.Next.Design(sequential) new.design <- list(X=Xn, y=f(Xn)) points(new.design$X, new.design$y, pch=16, col="green") # add to kriging and update sequential <- Add.Next.Design(sequential, new.design) } # final visualization pred <- Predict.Sequential(sequential, newX) plot(newX, f(newX), "l", main="EI Final") points(Get.Data(sequential)$X, Get.Data(sequential)$y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) best.design <- Get.Best.Design(sequential) points(best.design$design, best.design$objective, pch=16, col="green") # alternatively can create sequential by passing kriging parameters design.parameters <- list(design.lower.bound=c(0), design.upper.bound=c(1)) kriging.parameters <- list(X=X, y=y, interpolation=TRUE, fit=TRUE, kernel.parameters=list(type="Gaussian")) sequential <- Get.Sequential(design.parameters, kriging.parameters=kriging.parameters, method="EI")
This function specifies the Inverse Multiquadric (IM) kernel.
IM.Kernel(lengthscale, alpha = 1)IM.Kernel(lengthscale, alpha = 1)
lengthscale |
a vector for the positive length scale parameters |
alpha |
a positive scalar shape parameter that controls the kernel decay |
The Inverse Multiquadric (IM) kernel is given by
where is a positive shape parameter and
is the euclidean distance between and weighted by
the length scale parameters 's.
An Inverse Multiquadric (IM) Kernel Class Object.
Chaofan Huang, Difan Song, and V. Roshan Joseph
Duvenaud, D. (2014). The kernel cookbook: Advice on covariance functions.
Hardy, R. L. & Göpfert, W. M. (1975). Least squares prediction of gravity anomalies, geoidal undulations, and deflections of the vertical with multiquadric harmonic functions. Geophysical Research Letters, 2(10), 423–426. doi:10.1029/GL002i010p00423
Rasmussen, C. E. & Williams, C. K. (2006). Gaussian Processes for Machine Learning. The MIT Press.
MultiplicativeIM.Kernel, Get.Kernel, Evaluate.Kernel.
n <- 5 p <- 3 X <- matrix(rnorm(n*p), ncol=p) lengthscale <- c(1:p) # approach 1 kernel <- IM.Kernel(lengthscale, alpha=1) Evaluate.Kernel(kernel, X) # approach 2 kernel <- Get.Kernel(lengthscale, type="IM", parameters=list(alpha=1)) Evaluate.Kernel(kernel, X)n <- 5 p <- 3 X <- matrix(rnorm(n*p), ncol=p) lengthscale <- c(1:p) # approach 1 kernel <- IM.Kernel(lengthscale, alpha=1) Evaluate.Kernel(kernel, X) # approach 2 kernel <- Get.Kernel(lengthscale, type="IM", parameters=list(alpha=1)) Evaluate.Kernel(kernel, X)
This functions fits the limit kriging model to the data.
Limit.Kriging( X, y, fit = TRUE, nugget = NULL, kernel = NULL, kernel.parameters = list(), nlopt.parameters = list() )Limit.Kriging( X, y, fit = TRUE, nugget = NULL, kernel = NULL, kernel.parameters = list(), nlopt.parameters = list() )
X |
a matrix for input (feature) |
y |
a vector for output (target), only one-dimensional output is supported |
fit |
whether to fit the length scale parameters from data |
nugget |
an optional nugget value to add to the diagonal of the correlation matrix for numerical stability or noise modeling |
kernel |
a kernel class object |
kernel.parameters |
a list of parameters required for the kernel, if no kernel class object is provided |
nlopt.parameters |
a list of parameters required for NLopt, including choice of optimization algorithm and maximum number of evaluation |
Limit kriging avoids the mean reversion issue of ordinary kriging. Please see Joseph (2006) for details. Only interpolation is available. Noisy output is not supported for limit kriging.
The kernel choices are required and can be specified by
(i) providing the kernel class object to kernel
or (ii) specifying the kernel type and other parameters in kernel.parameters.
Please see examples section of Fit.Kriging for detail usages.
When the lengthscale / correlation parameters are unknown,
all parameters including the constant mean can be estimated via Maximum Likelihood method by setting fit=TRUE.
The initial / lower bound / upper bound of the lengthscale parameters can be provided in kernel.parameters,
otherwise a good initial and range would be estimated from the data.
The optimization is performed via NLopt,
a open-source library for nonlinear optimization.
All gradient-free optimization methods in NLopt
are supported and can be specified in nlopt.parameters.
See nloptr::nloptr.print.options() for the list of available derivative-free algorithms (prefix with NLOPT_GN or NLOPT_LN).
The maximum number of optimization steps can also be defined in nlopt.parameters.
Please see examples section of Fit.Kriging for detail usages.
A Limit Kriging Class Object.
Chaofan Huang, Difan Song, and V. Roshan Joseph
Joseph, V. R. (2006). Limit kriging. Technometrics, 48(4), 458-466.
Fit.Kriging, Predict.Kriging, Get.Kriging.Parameters.
# one dimensional example f <- function(x) { x <- 0.5 + 2*x y <- sin(10*pi*x)/(2*x) + (x-1)^4 return (y) } set.seed(1234) # train set n <- 30 p <- 1 X <- matrix(runif(n),ncol=p) y <- apply(X, 1, f) newX <- matrix(seq(0,1,length=1001), ncol=p) # approach 1 kriging <- Limit.Kriging(X, y, fit=TRUE, kernel.parameters=list(type="Gaussian")) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) Get.Kriging.Parameters(kriging) # approach 2 kriging <- Fit.Kriging(X, y, interpolation=TRUE, fit=TRUE, model="LK", kernel.parameters=list(type="Gaussian")) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) Get.Kriging.Parameters(kriging)# one dimensional example f <- function(x) { x <- 0.5 + 2*x y <- sin(10*pi*x)/(2*x) + (x-1)^4 return (y) } set.seed(1234) # train set n <- 30 p <- 1 X <- matrix(runif(n),ncol=p) y <- apply(X, 1, f) newX <- matrix(seq(0,1,length=1001), ncol=p) # approach 1 kriging <- Limit.Kriging(X, y, fit=TRUE, kernel.parameters=list(type="Gaussian")) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) Get.Kriging.Parameters(kriging) # approach 2 kriging <- Fit.Kriging(X, y, interpolation=TRUE, fit=TRUE, model="LK", kernel.parameters=list(type="Gaussian")) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) Get.Kriging.Parameters(kriging)
This function specifies the (Generalized) Matern kernel with any smoothness parameter .
Matern.Kernel(lengthscale, nu = 2.01)Matern.Kernel(lengthscale, nu = 2.01)
lengthscale |
a vector for the positive length scale parameters |
nu |
a positive scalar parameter that controls the smoothness |
The Generalized Matern kernel is given by
where is the smoothness parameter,
is the modified Bessel function,
is the gamma function,
and
is the euclidean distance between and weighted by
the length scale parameters 's.
As , it converges to the Gaussian.Kernel.
A Generalized Matern Kernel Class Object.
Chaofan Huang, Difan Song, and V. Roshan Joseph
Duvenaud, D. (2014). The kernel cookbook: Advice on covariance functions.
Rasmussen, C. E. & Williams, C. K. (2006). Gaussian Processes for Machine Learning. The MIT Press.
Matern12.Kernel, Matern32.Kernel, Matern52.Kernel, MultiplicativeMatern.Kernel, Get.Kernel, Evaluate.Kernel.
n <- 5 p <- 3 X <- matrix(rnorm(n*p), ncol=p) lengthscale <- c(1:p) # approach 1 kernel <- Matern.Kernel(lengthscale, nu=2.01) Evaluate.Kernel(kernel, X) # approach 2 kernel <- Get.Kernel(lengthscale, type="Matern", parameters=list(nu=2.01)) Evaluate.Kernel(kernel, X)n <- 5 p <- 3 X <- matrix(rnorm(n*p), ncol=p) lengthscale <- c(1:p) # approach 1 kernel <- Matern.Kernel(lengthscale, nu=2.01) Evaluate.Kernel(kernel, X) # approach 2 kernel <- Get.Kernel(lengthscale, type="Matern", parameters=list(nu=2.01)) Evaluate.Kernel(kernel, X)
This function specifies the Matern kernel with smoothness parameter =1/2.
It is also known as the Exponential kernel.
Matern12.Kernel(lengthscale)Matern12.Kernel(lengthscale)
lengthscale |
a vector for the positive length scale parameters |
The Matern(1/2) kernel is given by
where
is the euclidean distance between and weighted by
the length scale parameters 's.
A Matern(1/2) Kernel Class Object.
Chaofan Huang, Difan Song, and V. Roshan Joseph
Duvenaud, D. (2014). The kernel cookbook: Advice on covariance functions.
Rasmussen, C. E. & Williams, C. K. (2006). Gaussian Processes for Machine Learning. The MIT Press.
Matern.Kernel, Get.Kernel, Evaluate.Kernel.
n <- 5 p <- 3 X <- matrix(rnorm(n*p), ncol=p) lengthscale <- c(1:p) # approach 1 kernel <- Matern12.Kernel(lengthscale) Evaluate.Kernel(kernel, X) # approach 2 kernel <- Get.Kernel(lengthscale, type="Matern12") Evaluate.Kernel(kernel, X)n <- 5 p <- 3 X <- matrix(rnorm(n*p), ncol=p) lengthscale <- c(1:p) # approach 1 kernel <- Matern12.Kernel(lengthscale) Evaluate.Kernel(kernel, X) # approach 2 kernel <- Get.Kernel(lengthscale, type="Matern12") Evaluate.Kernel(kernel, X)
This function specifies the Matern kernel with smoothness parameter =3/2.
Matern32.Kernel(lengthscale)Matern32.Kernel(lengthscale)
lengthscale |
a vector for the positive length scale parameters |
The Matern(3/2) kernel is given by
where
is the euclidean distance between and weighted by
the length scale parameters 's.
A Matern(3/2) Kernel Class Object.
Chaofan Huang, Difan Song, and V. Roshan Joseph
Duvenaud, D. (2014). The kernel cookbook: Advice on covariance functions.
Rasmussen, C. E. & Williams, C. K. (2006). Gaussian Processes for Machine Learning. The MIT Press.
Matern.Kernel, Get.Kernel, Evaluate.Kernel.
n <- 5 p <- 3 X <- matrix(rnorm(n*p), ncol=p) lengthscale <- c(1:p) # approach 1 kernel <- Matern32.Kernel(lengthscale) Evaluate.Kernel(kernel, X) # approach 2 kernel <- Get.Kernel(lengthscale, type="Matern32") Evaluate.Kernel(kernel, X)n <- 5 p <- 3 X <- matrix(rnorm(n*p), ncol=p) lengthscale <- c(1:p) # approach 1 kernel <- Matern32.Kernel(lengthscale) Evaluate.Kernel(kernel, X) # approach 2 kernel <- Get.Kernel(lengthscale, type="Matern32") Evaluate.Kernel(kernel, X)
This function specifies the Matern kernel with smoothness parameter =5/2.
Matern52.Kernel(lengthscale)Matern52.Kernel(lengthscale)
lengthscale |
a vector for the positive length scale parameters |
The Matern(5/2) kernel is given by
where
is the euclidean distance between and weighted by
the length scale parameters 's.
A Matern(5/2) Kernel Class Object.
Chaofan Huang, Difan Song, and V. Roshan Joseph
Duvenaud, D. (2014). The kernel cookbook: Advice on covariance functions.
Rasmussen, C. E. & Williams, C. K. (2006). Gaussian Processes for Machine Learning. The MIT Press.
Matern.Kernel, Get.Kernel, Evaluate.Kernel.
n <- 5 p <- 3 X <- matrix(rnorm(n*p), ncol=p) lengthscale <- c(1:p) # approach 1 kernel <- Matern52.Kernel(lengthscale) Evaluate.Kernel(kernel, X) # approach 2 kernel <- Get.Kernel(lengthscale, type="Matern52") Evaluate.Kernel(kernel, X)n <- 5 p <- 3 X <- matrix(rnorm(n*p), ncol=p) lengthscale <- c(1:p) # approach 1 kernel <- Matern52.Kernel(lengthscale) Evaluate.Kernel(kernel, X) # approach 2 kernel <- Get.Kernel(lengthscale, type="Matern52") Evaluate.Kernel(kernel, X)
This function specifies the Multiplicative Inverse Multiquadric (IM) kernel.
MultiplicativeIM.Kernel(lengthscale, alpha = 1)MultiplicativeIM.Kernel(lengthscale, alpha = 1)
lengthscale |
a vector for the positive length scale parameters |
alpha |
a positive scalar shape parameter that controls the kernel decay |
The Multiplicative Inverse Multiquadric (IM) kernel is given by
where is a positive shape parameter and
is the dimension-wise euclidean distances between and weighted by
the length scale parameters 's.
A Multiplicative Inverse Multiquadric (IM) Kernel Class Object.
Chaofan Huang, Difan Song, and V. Roshan Joseph
Duvenaud, D. (2014). The kernel cookbook: Advice on covariance functions.
Song, D. & Joseph, V. R. (2026). Efficient Active Learning Strategies for Computer Experiments. Technometrics, 68(1), 65–78. doi:10.1080/00401706.2025.2546366
Rasmussen, C. E. & Williams, C. K. (2006). Gaussian Processes for Machine Learning. The MIT Press.
IM.Kernel, Get.Kernel, Evaluate.Kernel.
n <- 5 p <- 3 X <- matrix(rnorm(n*p), ncol=p) lengthscale <- c(1:p) # approach 1 kernel <- MultiplicativeIM.Kernel(lengthscale, alpha=1) Evaluate.Kernel(kernel, X) # approach 2 kernel <- Get.Kernel(lengthscale, type="MultiplicativeIM", parameters=list(alpha=1)) Evaluate.Kernel(kernel, X)n <- 5 p <- 3 X <- matrix(rnorm(n*p), ncol=p) lengthscale <- c(1:p) # approach 1 kernel <- MultiplicativeIM.Kernel(lengthscale, alpha=1) Evaluate.Kernel(kernel, X) # approach 2 kernel <- Get.Kernel(lengthscale, type="MultiplicativeIM", parameters=list(alpha=1)) Evaluate.Kernel(kernel, X)
This function specifies the Multiplicative Generalized Matern kernel.
MultiplicativeMatern.Kernel(lengthscale, nu = 2.01)MultiplicativeMatern.Kernel(lengthscale, nu = 2.01)
lengthscale |
a vector for the positive length scale parameters |
nu |
a positive scalar parameter that controls the smoothness |
The Multiplicative Generalized Matern kernel is given by
where is the smoothness parameter,
is the modified Bessel function,
is the gamma function,
and
is the dimension-wise euclidean distances between and weighted by
the length scale parameters 's.
A Multiplicative Generalized Matern Kernel Class Object.
Chaofan Huang, Difan Song, and V. Roshan Joseph
Duvenaud, D. (2014). The kernel cookbook: Advice on covariance functions.
Rasmussen, C. E. & Williams, C. K. (2006). Gaussian Processes for Machine Learning. The MIT Press.
Matern.Kernel, Get.Kernel, Evaluate.Kernel.
n <- 5 p <- 3 X <- matrix(rnorm(n*p), ncol=p) lengthscale <- c(1:p) # approach 1 kernel <- MultiplicativeMatern.Kernel(lengthscale, nu=2.01) Evaluate.Kernel(kernel, X) # approach 2 kernel <- Get.Kernel(lengthscale, type="MultiplicativeMatern", parameters=list(nu=2.01)) Evaluate.Kernel(kernel, X)n <- 5 p <- 3 X <- matrix(rnorm(n*p), ncol=p) lengthscale <- c(1:p) # approach 1 kernel <- MultiplicativeMatern.Kernel(lengthscale, nu=2.01) Evaluate.Kernel(kernel, X) # approach 2 kernel <- Get.Kernel(lengthscale, type="MultiplicativeMatern", parameters=list(nu=2.01)) Evaluate.Kernel(kernel, X)
This function specifies the Multiplicative Rational Quadratic (RQ) kernel.
MultiplicativeRQ.Kernel(lengthscale, alpha = 1)MultiplicativeRQ.Kernel(lengthscale, alpha = 1)
lengthscale |
a vector for the positive length scale parameters |
alpha |
a positive scalar for the scale mixture parameter that controls the relative weighting of large-scale and small-scale variations |
The Multiplicative Rational Quadratic (RQ) kernel is given by
where is the scale mixture parameter and
is the dimension-wise euclidean distances between and weighted by
the length scale parameters 's.
A Multiplicative Rational Quadratic (RQ) Kernel Class Object.
Chaofan Huang, Difan Song, and V. Roshan Joseph
Song, D. and Joseph, V. R. (2026). "Efficient Active Learning Strategies for Computer Experiments." Technometrics, 68, 65-78.
RQ.Kernel, Get.Kernel, Evaluate.Kernel.
n <- 5 p <- 3 X <- matrix(rnorm(n*p), ncol=p) lengthscale <- c(1:p) # approach 1 kernel <- MultiplicativeRQ.Kernel(lengthscale, alpha=1) Evaluate.Kernel(kernel, X) # approach 2 kernel <- Get.Kernel(lengthscale, type="MultiplicativeRQ", parameters=list(alpha=1)) Evaluate.Kernel(kernel, X)n <- 5 p <- 3 X <- matrix(rnorm(n*p), ncol=p) lengthscale <- c(1:p) # approach 1 kernel <- MultiplicativeRQ.Kernel(lengthscale, alpha=1) Evaluate.Kernel(kernel, X) # approach 2 kernel <- Get.Kernel(lengthscale, type="MultiplicativeRQ", parameters=list(alpha=1)) Evaluate.Kernel(kernel, X)
This function specifies the Multiplicative kernel with the user defined R function.
MultiplicativeUDF.Kernel(lengthscale, kernel.function)MultiplicativeUDF.Kernel(lengthscale, kernel.function)
lengthscale |
a vector for the positive length scale parameters |
kernel.function |
user defined kernel function |
The Multiplicative User Defined Function (UDF) kernel is given by
where is the user defined kernel function that takes as input,
where
is the dimension-wise euclidean distances between and weighted by
the length scale parameters 's.
A Multiplicative User Defined Function (UDF) Kernel Class Object.
Chaofan Huang, Difan Song, and V. Roshan Joseph
Duvenaud, D. (2014). The kernel cookbook: Advice on covariance functions.
Rasmussen, C. E. & Williams, C. K. (2006). Gaussian Processes for Machine Learning. The MIT Press.
UDF.Kernel, Get.Kernel, Evaluate.Kernel.
n <- 5 p <- 3 X <- matrix(rnorm(n*p), ncol=p) lengthscale <- c(1:p) kernel.function <- function(sqdist) {return (exp(-sqrt(sqdist)))} # approach 1 kernel <- MultiplicativeUDF.Kernel(lengthscale, kernel.function=kernel.function) Evaluate.Kernel(kernel, X) # approach 2 kernel <- Get.Kernel(lengthscale, type="MultiplicativeUDF", parameters=list(kernel.function=kernel.function)) Evaluate.Kernel(kernel, X)n <- 5 p <- 3 X <- matrix(rnorm(n*p), ncol=p) lengthscale <- c(1:p) kernel.function <- function(sqdist) {return (exp(-sqrt(sqdist)))} # approach 1 kernel <- MultiplicativeUDF.Kernel(lengthscale, kernel.function=kernel.function) Evaluate.Kernel(kernel, X) # approach 2 kernel <- Get.Kernel(lengthscale, type="MultiplicativeUDF", parameters=list(kernel.function=kernel.function)) Evaluate.Kernel(kernel, X)
This functions fits the ordinary kriging model to the data.
Ordinary.Kriging( X, y, interpolation = TRUE, fit = TRUE, nugget = NULL, kernel = NULL, kernel.parameters = list(), nlopt.parameters = list() )Ordinary.Kriging( X, y, interpolation = TRUE, fit = TRUE, nugget = NULL, kernel = NULL, kernel.parameters = list(), nlopt.parameters = list() )
X |
a matrix for input (feature) |
y |
a vector for output (target), only one-dimensional output is supported |
interpolation |
interpolation whether to interpolate, for noisy data please set |
fit |
whether to fit the length scale parameters from data |
nugget |
an optional nugget value to add to the diagonal of the correlation matrix for numerical stability or noise modeling |
kernel |
a kernel class object |
kernel.parameters |
a list of parameters required for the kernel, if no kernel class object is provided |
nlopt.parameters |
a list of parameters required for NLopt, including choice of optimization algorithm and maximum number of evaluation |
Ordinary kriging assumes a constant mean. Please see Joseph (2026) for details.
For data from deterministic computer experiments, use interpolation=TRUE and will give an interpolator.
For noisy data, use interpolation=FALSE, which will give an approximator of the underlying function.
The kernel choices are required and can be specified by
(i) providing the kernel class object to kernel
or (ii) specifying the kernel type and other parameters in kernel.parameters.
Please see examples section of Fit.Kriging for detail usages.
When the lengthscale / correlation parameters are unknown,
all parameters including the constant mean can be estimated via Maximum Likelihood method by setting fit=TRUE.
The initial / lower bound / upper bound of the lengthscale parameters can be provided in kernel.parameters,
otherwise a good initial and range would be estimated from the data.
The optimization is performed via NLopt,
a open-source library for nonlinear optimization.
All gradient-free optimization methods in NLopt
are supported and can be specified in nlopt.parameters.
See nloptr::nloptr.print.options() for the list of available derivative-free algorithms (prefix with NLOPT_GN or NLOPT_LN).
The maximum number of optimization steps can also be defined in nlopt.parameters.
Please see examples section of Fit.Kriging for detail usages.
A Ordinary Kriging Class Object.
Chaofan Huang, Difan Song, and V. Roshan Joseph
Joseph, V. R. (2026). Experimental Design for Data Science and Engineering. Chapman & Hall/CRC, doi:10.1201/9781003661535.
Fit.Kriging, Predict.Kriging, Get.Kriging.Parameters.
# one dimensional example f <- function(x) { x <- 0.5 + 2*x y <- sin(10*pi*x)/(2*x) + (x-1)^4 return (y) } set.seed(1234) # train set n <- 30 p <- 1 X <- matrix(runif(n),ncol=p) y <- apply(X, 1, f) newX <- matrix(seq(0,1,length=1001), ncol=p) # approach 1 kriging <- Ordinary.Kriging(X, y, interpolation=TRUE, fit=TRUE, kernel.parameters=list(type="Gaussian")) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) Get.Kriging.Parameters(kriging) # approach 2 kriging <- Fit.Kriging(X, y, interpolation=TRUE, fit=TRUE, model="OK", kernel.parameters=list(type="Gaussian")) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) Get.Kriging.Parameters(kriging)# one dimensional example f <- function(x) { x <- 0.5 + 2*x y <- sin(10*pi*x)/(2*x) + (x-1)^4 return (y) } set.seed(1234) # train set n <- 30 p <- 1 X <- matrix(runif(n),ncol=p) y <- apply(X, 1, f) newX <- matrix(seq(0,1,length=1001), ncol=p) # approach 1 kriging <- Ordinary.Kriging(X, y, interpolation=TRUE, fit=TRUE, kernel.parameters=list(type="Gaussian")) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) Get.Kriging.Parameters(kriging) # approach 2 kriging <- Fit.Kriging(X, y, interpolation=TRUE, fit=TRUE, model="OK", kernel.parameters=list(type="Gaussian")) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) Get.Kriging.Parameters(kriging)
This function creates a Probability of Improvement (PI) sequential design object for optimization (finding the minimum of the objective function).
PI.Sequential( design.parameters, kriging = NULL, kriging.parameters = NULL, nlopt.parameters = list() )PI.Sequential( design.parameters, kriging = NULL, kriging.parameters = NULL, nlopt.parameters = list() )
design.parameters |
a list specifying the design space, containing:
|
kriging |
(optional if kriging.parameters provided) a fitted kriging class object (e.g., from Ordinary.Kriging or Fit.Kriging) |
kriging.parameters |
(optional if kriging provided) a list of parameters to create kriging via Fit.Kriging, must contain X, y and optionally other Fit.Kriging parameters |
nlopt.parameters |
a list of parameters for NLopt optimization (used when |
PI selects the next design point as the one that maximizes the probability of improvement:
where ,
and are the kriging predictive mean and standard deviation,
and is the standard normal CDF.
The design space is specified via design.parameters, which must contain
design.lower.bound and design.upper.bound vectors.
During optimization, candidate points can be provided via design.candidates
in Get.Next.Design.
If the kriging object was fitted with scale=TRUE, design bounds,
candidates, new design points, predictions, returned designs, and returned data
are supplied and returned on the original input scale; scaling is handled
internally for the sequential criterion.
A PI Sequential Class Object.
Chaofan Huang, Difan Song, and V. Roshan Joseph
Kushner, H. J. (1964). A new method of locating the maximum point of an arbitrary multipeak curve in the presence of noise. Journal of Basic Engineering, 86(1), 97-106.
EI.Sequential, UCB.Sequential, UDF.Sequential, Get.Next.Design, Add.Next.Design, Get.Best.Design.
# one dimensional example f <- function(x) { x <- 0.5 + 2*x y <- sin(10*pi*x)/(2*x) + (x-1)^4 return (y) } set.seed(1234) n <- 10 p <- 1 X <- matrix(runif(n), ncol=p) y <- apply(X, 1, f) newX <- matrix(seq(0, 1, length=1001), ncol=p) # create sequential kriging <- Ordinary.Kriging(X, y, interpolation=TRUE, fit=TRUE, kernel.parameters=list(type="Gaussian")) design.parameters <- list(design.lower.bound=c(0), design.upper.bound=c(1)) sequential <- PI.Sequential(design.parameters, kriging) # sequential design loop with visualization for (i in 1:5) { # visualize current kriging pred <- Predict.Sequential(sequential, newX) plot(newX, f(newX), "l", main=sprintf("PI Iteration %d", i)) points(Get.Data(sequential)$X, Get.Data(sequential)$y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) # get next design and evaluate Xn <- Get.Next.Design(sequential) new.design <- list(X=Xn, y=f(Xn)) points(new.design$X, new.design$y, pch=16, col="green") # add to kriging and update sequential <- Add.Next.Design(sequential, new.design) } # final visualization and best design pred <- Predict.Sequential(sequential, newX) plot(newX, f(newX), "l", main="PI Final") points(Get.Data(sequential)$X, Get.Data(sequential)$y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) best.design <- Get.Best.Design(sequential) points(best.design$design, best.design$objective, pch=16, col="green")# one dimensional example f <- function(x) { x <- 0.5 + 2*x y <- sin(10*pi*x)/(2*x) + (x-1)^4 return (y) } set.seed(1234) n <- 10 p <- 1 X <- matrix(runif(n), ncol=p) y <- apply(X, 1, f) newX <- matrix(seq(0, 1, length=1001), ncol=p) # create sequential kriging <- Ordinary.Kriging(X, y, interpolation=TRUE, fit=TRUE, kernel.parameters=list(type="Gaussian")) design.parameters <- list(design.lower.bound=c(0), design.upper.bound=c(1)) sequential <- PI.Sequential(design.parameters, kriging) # sequential design loop with visualization for (i in 1:5) { # visualize current kriging pred <- Predict.Sequential(sequential, newX) plot(newX, f(newX), "l", main=sprintf("PI Iteration %d", i)) points(Get.Data(sequential)$X, Get.Data(sequential)$y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) # get next design and evaluate Xn <- Get.Next.Design(sequential) new.design <- list(X=Xn, y=f(Xn)) points(new.design$X, new.design$y, pch=16, col="green") # add to kriging and update sequential <- Add.Next.Design(sequential, new.design) } # final visualization and best design pred <- Predict.Sequential(sequential, newX) plot(newX, f(newX), "l", main="PI Final") points(Get.Data(sequential)$X, Get.Data(sequential)$y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) best.design <- Get.Best.Design(sequential) points(best.design$design, best.design$objective, pch=16, col="green")
This function gives prediction and uncertainty quantification of the kriging model on a new input.
Predict.Kriging(kriging, X, Neumann = FALSE)Predict.Kriging(kriging, X, Neumann = FALSE)
kriging |
a kriging class object |
X |
a matrix for the new input (features) to perform predictions |
Neumann |
whether to use the Neumann series approximation for prediction when the fitted model interpolates; default is |
If kriging was fitted with scale=TRUE in Fit.Kriging, X is scaled to [0, 1] using the training minima and maxima stored in the fitted object before prediction.
mean |
kriging mean computed at the new input |
sd |
kriging standard computed at the new input |
Chaofan Huang, Difan Song, and V. Roshan Joseph
Joseph, V. R. (2006). Limit kriging. Technometrics, 48(4), 458-466.
Joseph, V. R. (2025). Rational Kriging. Journal of the American Statistical Association. 120, 548-558.
Joseph, V. R. (2026). Experimental Design for Data Science and Engineering. Chapman & Hall/CRC, doi:10.1201/9781003661535.
Rasmussen, C. E. & Williams, C. K. (2006). Gaussian Processes for Machine Learning. The MIT Press.
# one dimensional example f <- function(x) { x <- 0.5 + 2*x y <- sin(10*pi*x)/(2*x) + (x-1)^4 return (y) } set.seed(1234) # train set n <- 30 p <- 1 X <- matrix(runif(n),ncol=p) y <- apply(X, 1, f) newX <- matrix(seq(0,1,length=1001), ncol=p) kriging <- Fit.Kriging(X, y, interpolation=TRUE, fit=TRUE, model="OK", kernel.parameters=list(type="Gaussian")) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3)# one dimensional example f <- function(x) { x <- 0.5 + 2*x y <- sin(10*pi*x)/(2*x) + (x-1)^4 return (y) } set.seed(1234) # train set n <- 30 p <- 1 X <- matrix(runif(n),ncol=p) y <- apply(X, 1, f) newX <- matrix(seq(0,1,length=1001), ncol=p) kriging <- Fit.Kriging(X, y, interpolation=TRUE, fit=TRUE, model="OK", kernel.parameters=list(type="Gaussian")) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3)
This function computes kriging predictions from the sequential design object at new input locations.
Predict.Sequential(sequential, newX)Predict.Sequential(sequential, newX)
sequential |
a sequential design object (e.g., from ALM.Sequential, EI.Sequential, etc.) |
newX |
a matrix of new input locations for prediction |
If the sequential object was created from a scaled kriging object, newX
should be provided on the original input scale and is scaled internally before
prediction.
A list with components:
meanthe predictive mean
sdthe predictive standard deviation
Chaofan Huang, Difan Song, and V. Roshan Joseph
# one dimensional example f <- function(x) { x <- 0.5 + 2*x y <- sin(10*pi*x)/(2*x) + (x-1)^4 return (y) } set.seed(1234) n <- 10 p <- 1 X <- matrix(runif(n), ncol=p) y <- apply(X, 1, f) newX <- matrix(seq(0, 1, length=1001), ncol=p) # create sequential kriging <- Ordinary.Kriging(X, y, interpolation=TRUE, fit=TRUE, kernel.parameters=list(type="Gaussian")) design.parameters <- list(design.lower.bound=c(0), design.upper.bound=c(1)) sequential <- EI.Sequential(design.parameters, kriging) # get prediction and visualization pred <- Predict.Sequential(sequential, newX) plot(newX, f(newX), "l", main="EI Final") points(Get.Data(sequential)$X, Get.Data(sequential)$y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3)# one dimensional example f <- function(x) { x <- 0.5 + 2*x y <- sin(10*pi*x)/(2*x) + (x-1)^4 return (y) } set.seed(1234) n <- 10 p <- 1 X <- matrix(runif(n), ncol=p) y <- apply(X, 1, f) newX <- matrix(seq(0, 1, length=1001), ncol=p) # create sequential kriging <- Ordinary.Kriging(X, y, interpolation=TRUE, fit=TRUE, kernel.parameters=list(type="Gaussian")) design.parameters <- list(design.lower.bound=c(0), design.upper.bound=c(1)) sequential <- EI.Sequential(design.parameters, kriging) # get prediction and visualization pred <- Predict.Sequential(sequential, newX) plot(newX, f(newX), "l", main="EI Final") points(Get.Data(sequential)$X, Get.Data(sequential)$y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3)
This functions fits the rational kriging model to the data.
Rational.Kriging( X, y, fit = TRUE, nugget = NULL, kernel = NULL, kernel.parameters = list(), nlopt.parameters = list() )Rational.Kriging( X, y, fit = TRUE, nugget = NULL, kernel = NULL, kernel.parameters = list(), nlopt.parameters = list() )
X |
a matrix for input (feature) |
y |
a vector for output (target), only one-dimensional output is supported |
fit |
whether to fit the length scale parameters from data |
nugget |
an optional nugget value to add to the diagonal of the correlation matrix for numerical stability or noise modeling |
kernel |
a kernel class object |
kernel.parameters |
a list of parameters required for the kernel, if no kernel class object is provided |
nlopt.parameters |
a list of parameters required for NLopt, including choice of optimization algorithm and maximum number of evaluation |
Rational kriging gives a rational predictor in terms of the inputs, which gives a more stable estimate of the mean. Please see Joseph (2025) for details. Only interpolation is available. Noisy output is not supported for rational kriging.
The kernel choices are required and can be specified by
(i) providing the kernel class object to kernel
or (ii) specifying the kernel type and other parameters in kernel.parameters.
Please see examples section of Fit.Kriging for detail usages.
When the lengthscale / correlation parameters are unknown,
all parameters including the constant mean can be estimated via Maximum Likelihood method by setting fit=TRUE.
The initial / lower bound / upper bound of the lengthscale parameters can be provided in kernel.parameters,
otherwise a good initial and range would be estimated from the data.
The optimization is performed via NLopt,
a open-source library for nonlinear optimization.
All gradient-free optimization methods in NLopt
are supported and can be specified in nlopt.parameters.
See nloptr::nloptr.print.options() for the list of available derivative-free algorithms (prefix with NLOPT_GN or NLOPT_LN).
The maximum number of optimization steps can also be defined in nlopt.parameters.
Please see examples section of Fit.Kriging for detail usages.
A Rational Kriging Class Object.
Chaofan Huang, Difan Song, and V. Roshan Joseph
Joseph, V. R. (2025). Rational Kriging. Journal of the American Statistical Association. 120, 548-558.
Fit.Kriging, Predict.Kriging, Get.Kriging.Parameters.
# one dimensional example f <- function(x) { x <- 0.5 + 2*x y <- sin(10*pi*x)/(2*x) + (x-1)^4 return (y) } set.seed(1234) # train set n <- 30 p <- 1 X <- matrix(runif(n),ncol=p) y <- apply(X, 1, f) newX <- matrix(seq(0,1,length=1001), ncol=p) # approach 1 kriging <- Rational.Kriging(X, y, fit=TRUE, kernel.parameters=list(type="RQ",alpha=1)) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) Get.Kriging.Parameters(kriging) # approach 2 kriging <- Fit.Kriging(X, y, interpolation=TRUE, fit=TRUE, model="RK", kernel.parameters=list(type="RQ",alpha=1)) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) Get.Kriging.Parameters(kriging)# one dimensional example f <- function(x) { x <- 0.5 + 2*x y <- sin(10*pi*x)/(2*x) + (x-1)^4 return (y) } set.seed(1234) # train set n <- 30 p <- 1 X <- matrix(runif(n),ncol=p) y <- apply(X, 1, f) newX <- matrix(seq(0,1,length=1001), ncol=p) # approach 1 kriging <- Rational.Kriging(X, y, fit=TRUE, kernel.parameters=list(type="RQ",alpha=1)) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) Get.Kriging.Parameters(kriging) # approach 2 kriging <- Fit.Kriging(X, y, interpolation=TRUE, fit=TRUE, model="RK", kernel.parameters=list(type="RQ",alpha=1)) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) Get.Kriging.Parameters(kriging)
This function specifies the Rational Quadratic (RQ) kernel.
RQ.Kernel(lengthscale, alpha = 1)RQ.Kernel(lengthscale, alpha = 1)
lengthscale |
a vector for the positive length scale parameters |
alpha |
a positive scalar for the scale mixture parameter that controls the relative weighting of large-scale and small-scale variations |
The Rational Quadratic (RQ) kernel is given by
where is the scale mixture parameter and
is the euclidean distance between and weighted by
the length scale parameters 's.
As , it converges to the Gaussian.Kernel.
A Rational Quadratic (RQ) Kernel Class Object.
Chaofan Huang, Difan Song, and V. Roshan Joseph
Duvenaud, D. (2014). The kernel cookbook: Advice on covariance functions.
Rasmussen, C. E. & Williams, C. K. (2006). Gaussian Processes for Machine Learning. The MIT Press.
MultiplicativeRQ.Kernel, Get.Kernel, Evaluate.Kernel.
n <- 5 p <- 3 X <- matrix(rnorm(n*p), ncol=p) lengthscale <- c(1:p) # approach 1 kernel <- RQ.Kernel(lengthscale, alpha=1) Evaluate.Kernel(kernel, X) # approach 2 kernel <- Get.Kernel(lengthscale, type="RQ", parameters=list(alpha=1)) Evaluate.Kernel(kernel, X)n <- 5 p <- 3 X <- matrix(rnorm(n*p), ncol=p) lengthscale <- c(1:p) # approach 1 kernel <- RQ.Kernel(lengthscale, alpha=1) Evaluate.Kernel(kernel, X) # approach 2 kernel <- Get.Kernel(lengthscale, type="RQ", parameters=list(alpha=1)) Evaluate.Kernel(kernel, X)
This function creates an Upper Confidence Bound (UCB) sequential design object for optimization (finding the minimum of the objective function).
UCB.Sequential( design.parameters, kriging = NULL, kriging.parameters = NULL, lambda = 2, nlopt.parameters = list() )UCB.Sequential( design.parameters, kriging = NULL, kriging.parameters = NULL, lambda = 2, nlopt.parameters = list() )
design.parameters |
a list specifying the design space, containing:
|
kriging |
(optional if kriging.parameters provided) a fitted kriging class object (e.g., from Ordinary.Kriging or Fit.Kriging) |
kriging.parameters |
(optional if kriging provided) a list of parameters to create kriging via Fit.Kriging, must contain X, y and optionally other Fit.Kriging parameters |
lambda |
a positive scalar controlling the exploration-exploitation tradeoff (default: 2) |
nlopt.parameters |
a list of parameters for NLopt optimization (used when |
UCB selects the next design point as the one that minimizes the lower confidence bound:
where and are the kriging predictive mean and standard deviation,
and controls the exploration-exploitation tradeoff.
Larger encourages more exploration.
The design space is specified via design.parameters, which must contain
design.lower.bound and design.upper.bound vectors.
During optimization, candidate points can be provided via design.candidates
in Get.Next.Design.
If the kriging object was fitted with scale=TRUE, design bounds,
candidates, new design points, predictions, returned designs, and returned data
are supplied and returned on the original input scale; scaling is handled
internally for the sequential criterion.
A UCB Sequential Class Object.
Chaofan Huang, Difan Song, and V. Roshan Joseph
Srinivas, N., Krause, A., Kakade, S. M., & Seeger, M. (2009). Gaussian process optimization in the bandit setting: No regret and experimental design. arXiv preprint arXiv:0912.3995.
EI.Sequential, PI.Sequential, UDF.Sequential, Get.Next.Design, Add.Next.Design, Get.Best.Design.
# one dimensional example f <- function(x) { x <- 0.5 + 2*x y <- sin(10*pi*x)/(2*x) + (x-1)^4 return (y) } set.seed(1234) n <- 10 p <- 1 X <- matrix(runif(n), ncol=p) y <- apply(X, 1, f) newX <- matrix(seq(0, 1, length=1001), ncol=p) # create sequential kriging <- Ordinary.Kriging(X, y, interpolation=TRUE, fit=TRUE, kernel.parameters=list(type="Gaussian")) design.parameters <- list(design.lower.bound=c(0), design.upper.bound=c(1)) sequential <- UCB.Sequential(design.parameters, kriging, lambda=2) # sequential design loop with visualization for (i in 1:5) { # visualize current kriging pred <- Predict.Sequential(sequential, newX) plot(newX, f(newX), "l", main=sprintf("UCB Iteration %d", i)) points(Get.Data(sequential)$X, Get.Data(sequential)$y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) # get next design and evaluate Xn <- Get.Next.Design(sequential) new.design <- list(X=Xn, y=f(Xn)) points(new.design$X, new.design$y, pch=16, col="green") # add to kriging and update sequential <- Add.Next.Design(sequential, new.design) } # final visualization and best design pred <- Predict.Sequential(sequential, newX) plot(newX, f(newX), "l", main="UCB Final") points(Get.Data(sequential)$X, Get.Data(sequential)$y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) best.design <- Get.Best.Design(sequential) points(best.design$design, best.design$objective, pch=16, col="green")# one dimensional example f <- function(x) { x <- 0.5 + 2*x y <- sin(10*pi*x)/(2*x) + (x-1)^4 return (y) } set.seed(1234) n <- 10 p <- 1 X <- matrix(runif(n), ncol=p) y <- apply(X, 1, f) newX <- matrix(seq(0, 1, length=1001), ncol=p) # create sequential kriging <- Ordinary.Kriging(X, y, interpolation=TRUE, fit=TRUE, kernel.parameters=list(type="Gaussian")) design.parameters <- list(design.lower.bound=c(0), design.upper.bound=c(1)) sequential <- UCB.Sequential(design.parameters, kriging, lambda=2) # sequential design loop with visualization for (i in 1:5) { # visualize current kriging pred <- Predict.Sequential(sequential, newX) plot(newX, f(newX), "l", main=sprintf("UCB Iteration %d", i)) points(Get.Data(sequential)$X, Get.Data(sequential)$y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) # get next design and evaluate Xn <- Get.Next.Design(sequential) new.design <- list(X=Xn, y=f(Xn)) points(new.design$X, new.design$y, pch=16, col="green") # add to kriging and update sequential <- Add.Next.Design(sequential, new.design) } # final visualization and best design pred <- Predict.Sequential(sequential, newX) plot(newX, f(newX), "l", main="UCB Final") points(Get.Data(sequential)$X, Get.Data(sequential)$y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) best.design <- Get.Best.Design(sequential) points(best.design$design, best.design$objective, pch=16, col="green")
This function specifies a kernel with the user defined R function.
UDF.Kernel(lengthscale, kernel.function)UDF.Kernel(lengthscale, kernel.function)
lengthscale |
a vector for the positive length scale parameters |
kernel.function |
user defined kernel function |
The User Defined Function (UDF) kernel is given by
where is the user defined kernel function that takes as input,
where
is the euclidean distance between and weighted by
the length scale parameters 's.
A User Defined Function (UDF) Kernel Class Object.
Chaofan Huang, Difan Song, and V. Roshan Joseph
Duvenaud, D. (2014). The kernel cookbook: Advice on covariance functions.
Rasmussen, C. E. & Williams, C. K. (2006). Gaussian Processes for Machine Learning. The MIT Press.
MultiplicativeUDF.Kernel, Get.Kernel, Evaluate.Kernel.
n <- 5 p <- 3 X <- matrix(rnorm(n*p), ncol=p) lengthscale <- c(1:p) kernel.function <- function(sqdist) {return (exp(-sqrt(sqdist)))} # approach 1 kernel <- UDF.Kernel(lengthscale, kernel.function=kernel.function) Evaluate.Kernel(kernel, X) # approach 2 kernel <- Get.Kernel(lengthscale, type="UDF", parameters=list(kernel.function=kernel.function)) Evaluate.Kernel(kernel, X)n <- 5 p <- 3 X <- matrix(rnorm(n*p), ncol=p) lengthscale <- c(1:p) kernel.function <- function(sqdist) {return (exp(-sqrt(sqdist)))} # approach 1 kernel <- UDF.Kernel(lengthscale, kernel.function=kernel.function) Evaluate.Kernel(kernel, X) # approach 2 kernel <- Get.Kernel(lengthscale, type="UDF", parameters=list(kernel.function=kernel.function)) Evaluate.Kernel(kernel, X)
This function creates a User Defined Function (UDF) sequential design object with a custom acquisition function.
UDF.Sequential( design.parameters, kriging = NULL, kriging.parameters = NULL, criterion.function, criterion.parameters = list(), nlopt.parameters = list() )UDF.Sequential( design.parameters, kriging = NULL, kriging.parameters = NULL, criterion.function, criterion.parameters = list(), nlopt.parameters = list() )
design.parameters |
a list specifying the design space, containing:
|
kriging |
(optional if kriging.parameters provided) a fitted kriging class object (e.g., from Ordinary.Kriging or Fit.Kriging) |
kriging.parameters |
(optional if kriging provided) a list of parameters to create kriging via Fit.Kriging, must contain X, y and optionally other Fit.Kriging parameters |
criterion.function |
an R function that takes (mean, sd, X, y, criterion.parameters) and returns a scalar criterion value to be maximized |
criterion.parameters |
a list of additional parameters to pass to the criterion function |
nlopt.parameters |
a list of parameters for NLopt optimization (used when |
The UDF sequential design allows users to specify a custom criterion function
for selecting the next design point. The criterion function receives the
predictive mean, predictive standard deviation, the current training data,
and any additional user-defined parameters.
If the kriging object was fitted with scale=TRUE, the criterion
function receives the current training X on the original input scale.
The design space is specified via design.parameters, which must contain
design.lower.bound and design.upper.bound vectors.
During optimization, candidate points can be provided via design.candidates
in Get.Next.Design.
If the kriging object was fitted with scale=TRUE, design bounds,
candidates, new design points, predictions, returned designs, and returned data
are supplied and returned on the original input scale; scaling is handled
internally for the sequential criterion.
A UDF Sequential Class Object.
Chaofan Huang, Difan Song, and V. Roshan Joseph
ALM.Sequential, EI.Sequential, PI.Sequential, UCB.Sequential, Predict.Sequential, Get.Next.Design, Add.Next.Design.
# one dimensional example f <- function(x) { x <- 0.5 + 2*x y <- sin(10*pi*x)/(2*x) + (x-1)^4 return (y) } set.seed(1234) n <- 10 p <- 1 X <- matrix(runif(n), ncol=p) y <- apply(X, 1, f) newX <- matrix(seq(0, 1, length=1001), ncol=p) # create sequential kriging <- Ordinary.Kriging(X, y, interpolation=TRUE, fit=TRUE, kernel.parameters=list(type="Gaussian")) design.parameters <- list(design.lower.bound=c(0), design.upper.bound=c(1)) # define custom criterion function (e.g., ALM-like using predictive SD) my.criterion <- function(mean, sd, X, y, clist) { return(sd) } sequential <- UDF.Sequential(design.parameters, kriging, criterion.function=my.criterion, criterion.parameters=list()) # sequential design loop with visualization for (i in 1:5) { # visualize current kriging pred <- Predict.Sequential(sequential, newX) plot(newX, f(newX), "l", main=sprintf("UDF Iteration %d", i)) points(Get.Data(sequential)$X, Get.Data(sequential)$y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) # get next design and evaluate Xn <- Get.Next.Design(sequential) new.design <- list(X=Xn, y=f(Xn)) points(new.design$X, new.design$y, pch=16, col="green") # add to kriging and update sequential <- Add.Next.Design(sequential, new.design) } # final visualization pred <- Predict.Sequential(sequential, newX) plot(newX, f(newX), "l", main="UDF Final") points(Get.Data(sequential)$X, Get.Data(sequential)$y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3)# one dimensional example f <- function(x) { x <- 0.5 + 2*x y <- sin(10*pi*x)/(2*x) + (x-1)^4 return (y) } set.seed(1234) n <- 10 p <- 1 X <- matrix(runif(n), ncol=p) y <- apply(X, 1, f) newX <- matrix(seq(0, 1, length=1001), ncol=p) # create sequential kriging <- Ordinary.Kriging(X, y, interpolation=TRUE, fit=TRUE, kernel.parameters=list(type="Gaussian")) design.parameters <- list(design.lower.bound=c(0), design.upper.bound=c(1)) # define custom criterion function (e.g., ALM-like using predictive SD) my.criterion <- function(mean, sd, X, y, clist) { return(sd) } sequential <- UDF.Sequential(design.parameters, kriging, criterion.function=my.criterion, criterion.parameters=list()) # sequential design loop with visualization for (i in 1:5) { # visualize current kriging pred <- Predict.Sequential(sequential, newX) plot(newX, f(newX), "l", main=sprintf("UDF Iteration %d", i)) points(Get.Data(sequential)$X, Get.Data(sequential)$y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) # get next design and evaluate Xn <- Get.Next.Design(sequential) new.design <- list(X=Xn, y=f(Xn)) points(new.design$X, new.design$y, pch=16, col="green") # add to kriging and update sequential <- Add.Next.Design(sequential, new.design) } # final visualization pred <- Predict.Sequential(sequential, newX) plot(newX, f(newX), "l", main="UDF Final") points(Get.Data(sequential)$X, Get.Data(sequential)$y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3)
This functions fits the universal kriging model to the data.
Universal.Kriging( X, y, basis.function, interpolation = TRUE, fit = TRUE, nugget = NULL, kernel = NULL, kernel.parameters = list(), nlopt.parameters = list() )Universal.Kriging( X, y, basis.function, interpolation = TRUE, fit = TRUE, nugget = NULL, kernel = NULL, kernel.parameters = list(), nlopt.parameters = list() )
X |
a matrix for input (feature) |
y |
a vector for output (target), only one-dimensional output is supported |
basis.function |
the basis functions for specifying the prior mean |
interpolation |
interpolation whether to interpolate, for noisy data please set |
fit |
whether to fit the length scale parameters from data |
nugget |
an optional nugget value to add to the diagonal of the correlation matrix for numerical stability or noise modeling |
kernel |
a kernel class object |
kernel.parameters |
a list of parameters required for the kernel, if no kernel class object is provided |
nlopt.parameters |
a list of parameters required for NLopt, including choice of optimization algorithm and maximum number of evaluation |
Universal kriging permits a more general function of mean, which can be specified using basis.function.
Please see Joseph (2006) for details.
For data from deterministic computer experiments, use interpolation=TRUE and will give an interpolator.
For noisy data, use interpolation=FALSE, which will give an approximator of the underlying function.
The kernel choices are required and can be specified by
(i) providing the kernel class object to kernel
or (ii) specifying the kernel type and other parameters in kernel.parameters.
Please see examples section of Fit.Kriging for detail usages.
When the lengthscale / correlation parameters are unknown,
all parameters including the constant mean can be estimated via Maximum Likelihood method by setting fit=TRUE.
The initial / lower bound / upper bound of the lengthscale parameters can be provided in kernel.parameters,
otherwise a good initial and range would be estimated from the data.
The optimization is performed via NLopt,
a open-source library for nonlinear optimization.
All gradient-free optimization methods in NLopt
are supported and can be specified in nlopt.parameters.
See nloptr::nloptr.print.options() for the list of available derivative-free algorithms (prefix with NLOPT_GN or NLOPT_LN).
The maximum number of optimization steps can also be defined in nlopt.parameters.
Please see examples section of Fit.Kriging for detail usages.
A Universal Kriging Class Object.
Chaofan Huang, Difan Song, and V. Roshan Joseph
Joseph, V. R. (2026). Experimental Design for Data Science and Engineering. Chapman & Hall/CRC, doi:10.1201/9781003661535.
Fit.Kriging, Predict.Kriging, Get.Kriging.Parameters.
# one dimensional example f <- function(x) { x <- 0.5 + 2*x y <- sin(10*pi*x)/(2*x) + (x-1)^4 return (y) } set.seed(1234) # train set n <- 30 p <- 1 X <- matrix(runif(n),ncol=p) y <- apply(X, 1, f) newX <- matrix(seq(0,1,length=1001), ncol=p) basis.function <- function(x) {c(1,x[1],x[1]^2)} # approach 1 kriging <- Universal.Kriging(X, y, basis.function=basis.function, interpolation=TRUE, fit=TRUE, kernel.parameters=list(type="Gaussian")) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) Get.Kriging.Parameters(kriging) # approach 2 kriging <- Fit.Kriging(X, y, interpolation=TRUE, fit=TRUE, model="UK", model.parameters=list(basis.function=basis.function), kernel.parameters=list(type="Gaussian")) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) Get.Kriging.Parameters(kriging)# one dimensional example f <- function(x) { x <- 0.5 + 2*x y <- sin(10*pi*x)/(2*x) + (x-1)^4 return (y) } set.seed(1234) # train set n <- 30 p <- 1 X <- matrix(runif(n),ncol=p) y <- apply(X, 1, f) newX <- matrix(seq(0,1,length=1001), ncol=p) basis.function <- function(x) {c(1,x[1],x[1]^2)} # approach 1 kriging <- Universal.Kriging(X, y, basis.function=basis.function, interpolation=TRUE, fit=TRUE, kernel.parameters=list(type="Gaussian")) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) Get.Kriging.Parameters(kriging) # approach 2 kriging <- Fit.Kriging(X, y, interpolation=TRUE, fit=TRUE, model="UK", model.parameters=list(basis.function=basis.function), kernel.parameters=list(type="Gaussian")) pred <- Predict.Kriging(kriging, newX) plot(newX, f(newX), "l") points(X, y, pch=16, col="blue") lines(newX, pred$mean, col="red", lty=2) lines(newX, pred$mean-2*pred$sd, col="red", lty=3) lines(newX, pred$mean+2*pred$sd, col="red", lty=3) Get.Kriging.Parameters(kriging)