laGP (version 1.4)

laGP: Localized Approximate GP Prediction At a Single Input Location

Description

Build a sub-design of X of size end, and infer parameters, for approximate Gaussian process prediction at reference location(s) Xref. Return the moments of those predictive equations, and indices into the local design

Usage

laGP(Xref, start, end, X, Z, d = NULL, g = 1/10000,
     method = c("alc", "alcray", "mspe", "nn", "fish"), Xi.ret = TRUE,
     close = min(1000*if(method == "alcray") 10 else 1, nrow(X)), 
     alc.gpu = FALSE, numrays = ncol(X), rect = NULL, verb = 0)
laGP.R(Xref, start, end, X, Z, d = NULL, g = 1/10000,
     method = c("alc", "alcray", "mspe", "nn", "fish"), Xi.ret = TRUE,
     pall = FALSE, close = min(1000*if(method=="alcray") 10 else 1, nrow(X)),  
     parallel = c("none", "omp", "gpu"), numrays = ncol(X), rect = NULL, 
     verb = 0)
laGPsep(Xref, start, end, X, Z, d = NULL, g = 1/10000, 
     method = c("alc", "alcray", "nn"), Xi.ret = TRUE, 
     close = min(1000*if(method == "alcray") 10 else 1, nrow(X)), 
     numrays = ncol(X), rect = NULL, verb = 0)
laGPsep.R(Xref, start, end, X, Z, d = NULL, g = 1/10000,
       method = c("alc", "alcray", "nn"), Xi.ret = TRUE,
       pall = FALSE, close = min(1000*if(method == "alcray") 10 else 1, nrow(X)),  
       parallel = c("none", "omp"), numrays = ncol(X), rect = NULL, 
       verb = 0)

Arguments

Xref

a vector of length ncol(X) containing a single reference location; or a matrix with ncol(Xref) = ncol(X) containing multiple reference locations (unless method = "alcray") for simultaneous sub-design and prediction

start

the number of Nearest Neighbor (NN) locations for initialization; must specify start >= 6

end

the total size of the local designs; must have start < end

X

a matrix or data.frame containing the full (large) design matrix of input locations

Z

a vector of responses/dependent values with length(Z) = ncol(X)

d

a prior or initial setting for the lengthscale parameter for a Gaussian correlation function; a (default) NULL value causes a sensible regularization (prior) and initial setting to be generated via darg; a scalar specifies an initial value, causing darg to only generate the prior; otherwise, a list or partial list matching the output of darg can be used to specify a custom prior. In the case of a partial list, the only the missing entries will be generated. Note that a default/generated list specifies MLE/MAP inference for this parameter. With laGPsep, the starting values can be a ncol(X)-by-nrow(XX) matrix or ncol(X) vector

g

a prior or initial setting for the nugget parameter; a NULL value causes a sensible regularization (prior) and initial setting to be generated via garg; a scalar (default g = 1/10000) specifies an initial value, causing garg to only generate the prior; otherwise, a list or partial list matching the output of garg can be used to specify a custom prior. In the case of a partial list, only the missing entries will be generated. Note that a default/generated list specifies no inference for this parameter; i.e., it is fixed at its starting or default value, which may be appropriate for emulating deterministic computer code output. In such situations a value much smaller than the default may work even better (i.e., yield better out-of-sample predictive performance). The default was chosen conservatively

method

Specifies the method by which end-start candidates from X are chosen in order to predict at Xref. In brief, ALC ("alc", default) minimizes predictive variance; ALCRAY ("alcray")) executes a thrifty ALC-based search focused on rays emanating from the reference location [must have nrow(Xref) = 1]; MSPE ("mspe") augments ALC with extra derivative information to minimize mean-squared prediction error (requires extra computation); NN ("nn") uses nearest neighbor; and EFI ("fish") uses the expected Fisher information - essentially 1/G from Gramacy & Apley (2015) - which is global heuristic, i.e., not localized to Xref

Xi.ret

A scalar logical indicating whether or not a vector of indices into X, specifying the chosen sub-design, should be returned on output

pall

a scalar logical (for laGP.R only) offering the ability to obtain predictions after every update (for progress indication and debugging), rather than after just the last update

close

a non-negative integer specifying the number of NNs (to Xref) in X to consider when searching for elements of the sub-design; close = 0 specifies all. For method="alcray" this specifies the scope used to snap ray-based solutions back to elements of X, otherwise there are no restrictions on that search

alc.gpu

a scalar logical indicating if a GPU should be used to parallelize the evaluation of the ALC criteria (method = "alc"). Requires the package be compiled with CUDA flags; see README/INSTALL in the package source for more details; currently only available via laGP, not laGPsep or the .R variants and only supports off-loading ALC calculation to the GPU

parallel

a switch indicating if any parallel calculation of the criteria is desired. Currently parallelization at this level is only provided for method = "alc"). For parallel = "omp", the package must be compiled with OMP flags; for parallel = "gpu", the package must be compiled with CUDA flags see README/INSTALL in the package source for more details; currently only available via laGP.R

numrays

a scalar integer indicating the number of rays for each greedy search; only relevant when method="alcray". More rays leads to a more thorough, but more computational intensive search

rect

an optional 2-by-ncol(X) matrix describing a bounding rectangle for X that is used by the "alcray" method. If not specified, the rectangle is calculated from the range applied to the columns of X

verb

a positive integer specifying the verbosity level; verb = 0 is quiet, and larger values cause more progress information to be printed to the screen

Value

The output is a list with the following components.

mean

a vector of predictive means of length nrow(Xref)

s2

a vector of Student-t scale parameters of length nrow(Xref)

df

a Student-t degrees of freedom scalar (applies to all Xref)

llik

a scalar indicating the maximized log likelihood or log posterior probability of the data/parameter(s) under the chosen sub-design; provided up to an additive constant

time

a scalar giving the passage of wall-clock time elapsed for (substantive parts of) the calculation

method

a copy of the method argument

d

a full-list version of the d argument, possibly completed by darg

g

a full-list version of the g argument, possibly completed by garg

mle

if d$mle and/or g$mle are TRUE, then mle is a data.frame containing the values found for these parameters, and the number of required iterations

Xi

when Xi.ret = TRUE, this field contains a vector of indices of length end into X indicating the sub-design chosen

close

a copy of the input argument

Details

A sub-design of X of size end is built-up according to the criteria prescribed by the method and then used to predict at Xref. The first start locations are NNs in order to initialize the first GP, via newGP or newGPsep, and thereby initialize the search. Each subsequent addition is found via the chosen criterion (method), and the GP fit is updated via updateGP or updateGPsep

The runtime is cubic in end, although the multiplicative “constant” out front depends on the method chosen, the size of the design X, and close. The "alcray" method has a smaller constant since it does not search over all candidates exhaustively.

After building the sub-design, local MLE/MAP lengthscale (and/or nugget) parameters are estimated, depending on the d and g arguments supplied. This is facilitated by calls to mleGP or jmleGP.

Finally predGP is called on the resulting local GP model, and the parameters of the resulting Student-t distribution(s) are returned. Unless Xi.ret = FALSE, the indices of the local design are also returned.

The functions laGP.R and laGPsep.R are a prototype R-only version for debugging and transparency purposes. They are slower than laGP and laGPsep, which are primarily in C, and may not provide identical output in all cases due differing library implementations used as subroutines; see note below for an example. laGP.R and other .R functions in the package may be useful for developing new programs that involve similar subroutines. The current version of laGP.R allows OpenMP and/or GPU parallelization of the criteria (method) if the package is compiled with the appropriate flags. See README/INSTALL in the package source for more information. For algorithmic details, see Gramacy, Niemi, & Weiss (2014)

References

R.B. Gramacy (2016). laGP: Large-Scale Spatial Modeling via Local Approximate Gaussian Processes in R., Journal of Statistical Software, 72(1), 1-46; or see vignette("laGP")

R.B. Gramacy and D.W. Apley (2015). Local Gaussian process approximation for large computer experiments. Journal of Computational and Graphical Statistics, 24(2), pp. 561-678; preprint on arXiv:1303.0383; http://arxiv.org/abs/1303.0383

R.B. Gramacy, J. Niemi, R.M. Weiss (2014). Massively parallel approximate Gaussian process regression. SIAM/ASA Journal on Uncertainty Quantification, 2(1), pp. 568-584; preprint on arXiv:1310.5182; http://arxiv.org/abs/1310.5182

R.B. Gramacy and B. Haaland (2015). Speeding up neighborhood search in local Gaussian process prediction. Technometrics, to appear; preprint on arXiv:1409.0074 http://arxiv.org/abs/1409.0074

See Also

vignette("laGP"), aGP, newGP, updateGP, predGP, mleGP, jmleGP, alcGP, mspeGP, alcrayGP

Examples

Run this code
## examining a particular laGP call from the larger analysis provided
## in the aGP documentation

## Simple 2-d test function used in Gramacy & Apley (2014);
## thanks to Lee, Gramacy, Taddy, and others who have used it before
f2d <- function(x, y=NULL)
  {
    if(is.null(y)) {
      if(!is.matrix(x)) x <- matrix(x, ncol=2)
      y <- x[,2]; x <- x[,1]
    }
    g <- function(z)
      return(exp(-(z-1)^2) + exp(-0.8*(z+1)^2) - 0.05*sin(8*(z+0.1)))
    z <- -g(x)*g(y)
  }

## build up a design with N=~40K locations
x <- seq(-2, 2, by=0.02)
X <- as.matrix(expand.grid(x, x))
Z <- f2d(X)

## local analysis, first pass
Xref <- matrix(c(-1.725, 1.725), nrow=TRUE)
out <- laGP(Xref, 6, 50, X, Z, method="nn")

## second and pass via ALC, MSPE, and ALC-ray respectively
out2 <- laGP(Xref, 6, 50, X, Z, d=out$mle$d)
out2.mspe <- laGP(Xref, 6, 50, X, Z, d=out2$mle$d, method="mspe")
out2.alcray <- laGP(Xref, 6, 50, X, Z, d=out2$mle$d, method="alcray")

## look at the different designs
plot(rbind(X[out2$Xi,], X[out2.mspe$Xi,]), type="n",
     xlab="x1", ylab="x2", main="comparing local designs")
points(Xref[1], Xref[2], col=2, cex=0.5)
text(X[out2$Xi,], labels=1:50, cex=0.6)
text(X[out2.mspe$Xi,], labels=1:50, cex=0.6, col="green")
text(X[out2.alcray$Xi,], labels=1:50, cex=0.6, col="red")

legend("topright", c("pass 2 ALC", "pass 3 MSPE", "pass 3 ALCRAY"),
       text.col=c("black", "green", "red"), bty="n")

## compare times
data.frame(nn=out$time, alc=out2$time, 
  mspe=out2.mspe$time, alcray=out2.alcray$time)

## Here is the example from the Gramacy & Haaland (2014) paper;
## the lower lengthscale (d) setting generates more spread
out <- laGP(Xref, 6, 50, X, Z, d=0.1, method="alc")
out2 <- laGP(Xref, 6, 50, X, Z, d=0.1, method="alcray")
plot(X[out$Xi,], xlab="x1", ylab="x2", type="n")
text(X[out$Xi,], labels=1:length(out$Xi), cex=0.7)
text(X[out2$Xi,], labels=1:length(out2$Xi), cex=0.7, col=3)
points(Xref[1], Xref[2], pch=19, col=2)
legend("topright", c("exhaustive", "via rays"), text.col=c(1,3), bty="n")

Run the code above in your browser using DataCamp Workspace