GauPro model that uses kernels
GauPro model that uses kernels
Object of R6Class with methods for fitting GP model.
R6Class object.
new(X, Z, corr="Gauss", verbose=0, separable=T, useC=F,
                  useGrad=T,
         parallel=T, nug.est=T, ...)This method is used to create object of this
         class with X and Z as the data.
update(Xnew=NULL, Znew=NULL, Xall=NULL, Zall=NULL,
restarts = 5,
param_update = T, nug.update = self$nug.est)This method updates the model, adding new data if given, then running optimization again.
XDesign matrix
ZResponses
NNumber of data points
DDimension of data
nug.minMinimum value of nugget
nug.maxMaximum value of the nugget.
nug.estShould the nugget be estimated?
nugValue of the nugget, is estimated unless told otherwise
param.estShould the kernel parameters be estimated?
verbose0 means nothing printed, 1 prints some, 2 prints most.
useGradShould grad be used?
useCShould C code be used?
parallelShould the code be run in parallel?
parallel_coresHow many cores are there? By default it detects.
kernelThe kernel to determine the correlations.
trendThe trend.
mu_hatXPredicted trend value for each point in X.
s2_hatVariance parameter estimate
KCovariance matrix
KcholCholesky factorization of K
KinvInverse of K
Kinv_Z_minus_mu_hatXK inverse times Z minus the predicted trend at X.
restartsNumber of optimization restarts to do when updating.
normalizeShould the inputs be normalized?
normalize_meanIf using normalize, the mean of each column.
normalize_sdIf using normalize, the standard deviation of each column.
optimizerWhat algorithm should be used to optimize the parameters.
new()Create kernel_model object
GauPro_kernel_model$new( X, Z, kernel, trend, verbose = 0, useC = F, useGrad = T, parallel = FALSE, parallel_cores = "detect", nug = 1e-06, nug.min = 1e-08, nug.max = Inf, nug.est = TRUE, param.est = TRUE, restarts = 5, normalize = FALSE, optimizer = "L-BFGS-B", ... )
XMatrix whose rows are the input points
ZOutput points corresponding to X
kernelThe kernel to use. E.g., Gaussian$new().
trendTrend to use. E.g., trend_constant$new().
verboseAmount of stuff to print. 0 is little, 2 is a lot.
useCShould C code be used when possible? Should be faster.
useGradShould the gradient be used?
parallelShould code be run in parallel? Make optimization faster but uses more computer resources.
parallel_coresWhen using parallel, how many cores should be used?
nugValue for the nugget. The starting value if estimating it.
nug.minMinimum allowable value for the nugget.
nug.maxMaximum allowable value for the nugget.
nug.estShould the nugget be estimated?
param.estShould the kernel parameters be estimated?
restartsHow many optimization restarts should be used when estimating parameters?
normalizeShould the data be normalized?
optimizerWhat algorithm should be used to optimize the parameters.
...Not used
fit()Fit model
GauPro_kernel_model$fit(X, Z)
XInputs
ZOutputs
update_K_and_estimates()Update covariance matrix and estimates
GauPro_kernel_model$update_K_and_estimates()
predict()Predict for a matrix of points
GauPro_kernel_model$predict(XX, se.fit = F, covmat = F, split_speed = F)
XXpoints to predict at
se.fitShould standard error be returned?
covmatShould covariance matrix be returned?
split_speedShould the matrix be split for faster predictions?
pred()Predict for a matrix of points
GauPro_kernel_model$pred(XX, se.fit = F, covmat = F, split_speed = F)
XXpoints to predict at
se.fitShould standard error be returned?
covmatShould covariance matrix be returned?
split_speedShould the matrix be split for faster predictions?
pred_one_matrix()Predict for a matrix of points
GauPro_kernel_model$pred_one_matrix( XX, se.fit = F, covmat = F, return_df = FALSE )
XXpoints to predict at
se.fitShould standard error be returned?
covmatShould covariance matrix be returned?
return_dfWhen returning se.fit, should it be returned in a data frame?
pred_mean()Predict mean
GauPro_kernel_model$pred_mean(XX, kx.xx)
XXpoints to predict at
kx.xxCovariance of X with XX
pred_meanC()Predict mean using C
GauPro_kernel_model$pred_meanC(XX, kx.xx)
XXpoints to predict at
kx.xxCovariance of X with XX
pred_var()Predict variance
GauPro_kernel_model$pred_var(XX, kxx, kx.xx, covmat = F)
XXpoints to predict at
kxxCovariance of XX with itself
kx.xxCovariance of X with XX
covmatShould the covariance matrix be returned?
pred_LOO()leave one out predictions
GauPro_kernel_model$pred_LOO(se.fit = FALSE)
se.fitShould standard errors be included?
pred_var_after_adding_points()Predict variance after adding points
GauPro_kernel_model$pred_var_after_adding_points(add_points, pred_points)
add_pointsPoints to add
pred_pointsPoints to predict at
pred_var_after_adding_points_sep()Predict variance reductions after adding each point separately
GauPro_kernel_model$pred_var_after_adding_points_sep(add_points, pred_points)
add_pointsPoints to add
pred_pointsPoints to predict at
pred_var_reduction()Predict variance reduction for a single point
GauPro_kernel_model$pred_var_reduction(add_point, pred_points)
add_pointPoint to add
pred_pointsPoints to predict at
pred_var_reductions()Predict variance reductions
GauPro_kernel_model$pred_var_reductions(add_points, pred_points)
add_pointsPoints to add
pred_pointsPoints to predict at
cool1Dplot()Make cool 1D plot
GauPro_kernel_model$cool1Dplot( n2 = 20, nn = 201, col2 = "gray", xlab = "x", ylab = "y", xmin = NULL, xmax = NULL, ymin = NULL, ymax = NULL )
n2Number of things to plot
nnNumber of things to plot
col2color
xlabx label
ylaby label
xminxmin
xmaxxmax
yminymin
ymaxymax
plot1D()Make 1D plot
GauPro_kernel_model$plot1D( n2 = 20, nn = 201, col2 = 2, xlab = "x", ylab = "y", xmin = NULL, xmax = NULL, ymin = NULL, ymax = NULL )
n2Number of things to plot
nnNumber of things to plot
col2color
xlabx label
ylaby label
xminxmin
xmaxxmax
yminymin
ymaxymax
plot2D()Make 2D plot
GauPro_kernel_model$plot2D()
loglikelihood()Calculate loglikelihood of parameters
GauPro_kernel_model$loglikelihood(mu = self$mu_hatX, s2 = self$s2_hat)
muMean parameters
s2Variance parameter
get_optim_functions()Get optimization functions
GauPro_kernel_model$get_optim_functions(param_update, nug.update)
param_updateShould parameters be updated?
nug.updateShould nugget be updated?
param_optim_lower()Lower bounds of parameters for optimization
GauPro_kernel_model$param_optim_lower(nug.update)
nug.updateIs the nugget being updated?
param_optim_upper()Upper bounds of parameters for optimization
GauPro_kernel_model$param_optim_upper(nug.update)
nug.updateIs the nugget being updated?
param_optim_start()Starting point for parameters for optimization
GauPro_kernel_model$param_optim_start(nug.update, jitter)
nug.updateIs nugget being updated?
jitterShould there be a jitter?
param_optim_start0()Starting point for parameters for optimization
GauPro_kernel_model$param_optim_start0(nug.update, jitter)
nug.updateIs nugget being updated?
jitterShould there be a jitter?
param_optim_start_mat()Get matrix for starting points of optimization
GauPro_kernel_model$param_optim_start_mat(restarts, nug.update, l)
restartsNumber of restarts to use
nug.updateIs nugget being updated?
lNot used
optim()Optimize parameters
GauPro_kernel_model$optim( restarts = 5, param_update = T, nug.update = self$nug.est, parallel = self$parallel, parallel_cores = self$parallel_cores )
restartsNumber of restarts to do
param_updateShould parameters be updated?
nug.updateShould nugget be updated?
parallelShould restarts be done in parallel?
parallel_coresIf running parallel, how many cores should be used?
optimRestart()Run a single optimization restart.
GauPro_kernel_model$optimRestart( start.par, start.par0, param_update, nug.update, optim.func, optim.grad, optim.fngr, lower, upper, jit = T, start.par.i )
start.parStarting parameters
start.par0Starting parameters
param_updateShould parameters be updated?
nug.updateShould nugget be updated?
optim.funcFunction to optimize.
optim.gradGradient of function to optimize.
optim.fngrFunction that returns the function value and its gradient.
lowerLower bounds for optimization
upperUpper bounds for optimization
jitIs jitter being used?
start.par.iStarting parameters for this restart
update()Update the model. Should only give in (Xnew and Znew) or (Xall and Zall).
GauPro_kernel_model$update( Xnew = NULL, Znew = NULL, Xall = NULL, Zall = NULL, restarts = self$restarts, param_update = self$param.est, nug.update = self$nug.est, no_update = FALSE )
XnewNew X values to add.
ZnewNew Z values to add.
XallAll X values to be used. Will replace existing X.
ZallAll Z values to be used. Will replace existing Z.
restartsNumber of optimization restarts.
param_updateAre the parameters being updated?
nug.updateIs the nugget being updated?
no_updateAre no parameters being updated?
update_fast()Fast update when adding new data.
GauPro_kernel_model$update_fast(Xnew = NULL, Znew = NULL)
XnewNew X values to add.
ZnewNew Z values to add.
update_params()Update the parameters.
GauPro_kernel_model$update_params(..., nug.update)
...Passed to optim.
nug.updateIs the nugget being updated?
update_data()Update the data. Should only give in (Xnew and Znew) or (Xall and Zall).
GauPro_kernel_model$update_data( Xnew = NULL, Znew = NULL, Xall = NULL, Zall = NULL )
XnewNew X values to add.
ZnewNew Z values to add.
XallAll X values to be used. Will replace existing X.
ZallAll Z values to be used. Will replace existing Z.
update_corrparams()Update correlation parameters. Not the nugget.
GauPro_kernel_model$update_corrparams(...)
...Passed to self$update()
update_nugget()Update nugget Not the correlation parameters.
GauPro_kernel_model$update_nugget(...)
...Passed to self$update()
deviance()Calculate the deviance.
GauPro_kernel_model$deviance( params = NULL, nug = self$nug, nuglog, trend_params = NULL )
paramsKernel parameters
nugNugget
nuglogLog of nugget. Only give in nug or nuglog.
trend_paramsParameters for the trend.
deviance_grad()Calculate the gradient of the deviance.
GauPro_kernel_model$deviance_grad( params = NULL, kernel_update = TRUE, X = self$X, nug = self$nug, nug.update, nuglog, trend_params = NULL, trend_update = TRUE )
paramsKernel parameters
kernel_updateIs the kernel being updated? If yes, it's part of the gradient.
XInput matrix
nugNugget
nug.updateIs the nugget being updated? If yes, it's part of the gradient.
nuglogLog of the nugget.
trend_paramsTrend parameters
trend_updateIs the trend being updated? If yes, it's part of the gradient.
deviance_fngr()Calculate the deviance along with its gradient.
GauPro_kernel_model$deviance_fngr( params = NULL, kernel_update = TRUE, X = self$X, nug = self$nug, nug.update, nuglog, trend_params = NULL, trend_update = TRUE )
paramsKernel parameters
kernel_updateIs the kernel being updated? If yes, it's part of the gradient.
XInput matrix
nugNugget
nug.updateIs the nugget being updated? If yes, it's part of the gradient.
nuglogLog of the nugget.
trend_paramsTrend parameters
trend_updateIs the trend being updated? If yes, it's part of the gradient.
grad()Calculate gradient
GauPro_kernel_model$grad(XX, X = self$X, Z = self$Z)
XXpoints to calculate at
XX points
Zoutput points
grad_norm()Calculate norm of gradient
GauPro_kernel_model$grad_norm(XX)
XXpoints to calculate at
grad_dist()Calculate distribution of gradient
GauPro_kernel_model$grad_dist(XX)
XXpoints to calculate at
grad_sample()Sample gradient at points
GauPro_kernel_model$grad_sample(XX, n)
XXpoints to calculate at
nNumber of samples
grad_norm2_mean()Calculate mean of gradient norm squared
GauPro_kernel_model$grad_norm2_mean(XX)
XXpoints to calculate at
grad_norm2_dist()Calculate distribution of gradient norm squared
GauPro_kernel_model$grad_norm2_dist(XX)
XXpoints to calculate at
grad_norm2_sample()Get samples of squared norm of gradient
GauPro_kernel_model$grad_norm2_sample(XX, n)
XXpoints to sample at
nNumber of samples
hessian()Calculate Hessian
GauPro_kernel_model$hessian(XX, as_array = FALSE)
XXPoints to calculate Hessian at
as_arrayShould result be an array?
sample()Sample at rows of XX
GauPro_kernel_model$sample(XX, n = 1)
XXInput matrix
nNumber of samples
print()Print this object
GauPro_kernel_model$print()
clone()The objects of this class are cloneable with this method.
GauPro_kernel_model$clone(deep = FALSE)
deepWhether to make a deep clone.
Class providing object with methods for fitting a GP model. Allows for different kernel and trend functions to be used.
# NOT RUN {
n <- 12
x <- matrix(seq(0,1,length.out = n), ncol=1)
y <- sin(2*pi*x) + rnorm(n,0,1e-1)
gp <- GauPro_kernel_model$new(X=x, Z=y, kernel=Gaussian$new(1),
                              parallel=FALSE)
gp$predict(.454)
# }
Run the code above in your browser using DataLab