Learn R Programming

kergp (version 0.5.7)

simulate, covAll-method: Simulation of a covAll Object

Description

Simulation of a covAll object.

Usage

# S4 method for covAll
simulate(object, nsim = 1, seed = NULL,
         X, mu = NULL, method = "mvrnorm", checkNames = TRUE,
         ...)

Value

A numeric matrix with nrow(X) rows and nsim columns. Each column is the vector of the simulated path at the simulation locations.

Arguments

object

A covariance kernel object.

nsim

Number of simulated paths.

seed

Not used yet.

X

A matrix with the needed inputs as its columns.

mu

Optional vector with length nrow(X) giving the expectation \(\mu(\mathbf{x})\) of the Gaussian Process at the simulation locations \(\mathbf{x}\).

method

Character used to choose the simulation method. For now the only possible value is "mvrnorm" corresponding to the function with this name in the MASS package.

checkNames

Logical. It TRUE the colnames of X and the input names of object as given by inputNames(object) must be identical sets.

...

Other arguments for methods.

See Also

The mvrnorm function.

Examples

Run this code

## -- as in example(kergp) define an argumentwise invariant kernel --

kernFun <- function(x1, x2, par) {
  h <- (abs(x1) - abs(x2)) / par[1]
  S <- sum(h^2)
  d2 <- exp(-S)
  K <- par[2] * d2
  d1 <- 2 * K * S / par[1]   
  attr(K, "gradient") <- c(theta = d1,  sigma2 = d2)
  return(K)
}

covSymGauss <- covMan(kernel = kernFun,
                      hasGrad = TRUE,
                      label = "argumentwise invariant",
                      d = 2,
                      parNames = c("theta", "sigma2"),
                      par = c(theta = 0.5, sigma2 = 2))

## -- simulate a path from the corresponding GP --

nGrid <- 24; n <- nGrid^2; d <- 2
xGrid <- seq(from = -1, to = 1, length.out = nGrid)
Xgrid <- expand.grid(x1 = xGrid, x2 = xGrid)

ySim <- simulate(covSymGauss, X = Xgrid)
contour(x = xGrid, y = xGrid,
        z = matrix(ySim, nrow = nGrid, ncol = nGrid), 
        nlevels = 15)

Run the code above in your browser using DataLab