contours: Contours of a Function Related to a Kriging Model object with...

View source: R/contours.R

contoursR Documentation

Contours of a Function Related to a Kriging Model object with Two Inputs

Description

Contours of a kriging function or statistic related to a kriging model object with two inputs. This can be the kriging mean, the kriging (conditional) standard deviation and more.

Usage

contours(
  object,
  which = "mean",
  other = NULL,
  lower = c(0, 0),
  upper = c(1, 1),
  nGrid = 50,
  grad = FALSE,
  otherGrad = NULL,
  whereGrad = "levels",
  ...
)

Arguments

object

An object with class "km" or equivalent with two inputs.

which

Character vector. Name of the kriging function(s)/statistic(s) to be shown. Can contain "mean", "trend", "sd", "sd2" or "var". Can have length 0 as well, in order to display the contours of a function having or not a formal argument object. This function is then provided by using other.

other

Character. Name of a function. This can be a function to be compared to the stat(s) given in which (usually the kriging mean). If which has length zero we can also specify a gradient function. The function must be a function of one vector argument. It optionally can have one more argument with name "model" or "object" in which case object will be passed will be passed to this argument as is required to diplay a one-point Bayesian optimisation criterion (EI, AEI, ...), see Examples.

lower, upper

Numeric vectors with length 2 definign the bounds of the rectangular region for the contours.

nGrid

Integer. Number of grid points. Can be of length 2 if different grids are to be used for the two dimensions.

grad

Logical. If TRUE the gradient of the kriging function/statistic will be shown using arrows. This will only be possible when only one function is used among "mean" "trend" "sd" or "sd2", or when a function is given in other. In the second case the gradient function must be given in otherGrad.

otherGrad

Character. Name of the gradient function of the function given in other. This will be ignored if other is not provided or if grad is FALSE. Not implemented yet.

whereGrad

Either a character with length one or a data frame or matrix with two columns. This defines the points at which the gradient will be evaluated and plotted as a small arrow in a vector-field fashion. The default is "levels" indicating that the gradient is evaluated along some level curves (not those used to define the filled contours). Another possible value is "grid" Finally if a matrix or data frame is provided, the gradient will only be evaluated and plotted at the specified points.

...

Not used yet.

Details

When several functions are given, they will be displayed on different facets of the plot. These functions should then have the same dimension because only one colour scale is used. For instance it makes no sense to give the mean and the variance which do not have the same dimension, nor even the mean and the standard deviation because these two functions may have different order of magnitude. We can usefully want the true function and the kriging mean, or the kriging mean and the kriging trend.

Value

A graphical object inheriting from "ggplot".

Examples

set.seed(1521)
n <- 9
design <- matrix(runif(n * 2), ncol = 2,
                 dimnames = list(NULL, c("x1", "x2")))
design <- data.frame(design)
y <- apply(design, 1, branin)
model <- km(~1, design = design, response = y)

## Contours only
## =============
contours(model) + ggtitle("kriging mean (default in 'contours')")
contours(model, other = "branin") + ggtitle("'branin' and kriging mean")
contours(model, which = c("mean", "trend")) + ggtitle("Kriging mean and trend")
contours(model, which = "sd") + ggtitle("Kriging sd")

## Display gradients
## =================
contours(model, which = "mean", grad = TRUE) +
     ggtitle("Kriging mean, gradients at contours")
contours(model, which = "sd", grad = TRUE) +
    ggtitle("Kriging sd, gradients at contours")
contours(model, which = "sd", grad = TRUE, whereGrad = "grid") +
    ggtitle("Kriging sd, gradients at grid points")

## more involved examples
## ======================
## Not run: 
braninG <- function(x) branin_with_grad(x)$gradient
contours(model, which = character(0), grad = TRUE,
         other = "branin", otherGrad = "braninG", whereGrad = "grid") +
    ggtitle("Branin function and its gradient")
contours(model, which = character(0), grad = TRUE,
         other = "EI", otherGrad = "EI.grad", whereGrad = "grid") +
    ggtitle("Expected Improvement and its gradient")

## End(Not run)

libKriging/dolka documentation built on April 14, 2022, 7:17 a.m.