| Title: | Gaussian Process Fitting |
|---|---|
| Description: | Fits a Gaussian process model to data. Gaussian processes are commonly used in computer experiments to fit an interpolating model. The model is stored as an 'R6' object and can be easily updated with new data. There are options to run in parallel, and 'Rcpp' has been used to speed up calculations. For more info about Gaussian process software, see Erickson et al. (2018) <doi:10.1016/j.ejor.2017.10.002>. |
| Authors: | Collin Erickson [aut, cre] |
| Maintainer: | Collin Erickson <[email protected]> |
| License: | GPL-3 |
| Version: | 0.2.17.9000 |
| Built: | 2026-05-18 09:31:48 UTC |
| Source: | https://github.com/collinerickson/gaupro |
Kernel product
## S3 method for class 'GauPro_kernel' k1 * k2## S3 method for class 'GauPro_kernel' k1 * k2
k1 |
First kernel |
k2 |
Second kernel |
Kernel which is product of two kernels
k1 <- Exponential$new(beta=1) k2 <- Matern32$new(beta=0) k <- k1 * k2 k$k(matrix(c(2,1), ncol=1))k1 <- Exponential$new(beta=1) k2 <- Matern32$new(beta=0) k <- k1 * k2 k$k(matrix(c(2,1), ncol=1))
Kernel sum
## S3 method for class 'GauPro_kernel' k1 + k2## S3 method for class 'GauPro_kernel' k1 + k2
k1 |
First kernel |
k2 |
Second kernel |
Kernel which is sum of two kernels
k1 <- Exponential$new(beta=1) k2 <- Matern32$new(beta=0) k <- k1 + k2 k$k(matrix(c(2,1), ncol=1))k1 <- Exponential$new(beta=1) k2 <- Matern32$new(beta=0) k <- k1 + k2 k$k(matrix(c(2,1), ncol=1))
The result is transposed since that is what apply will give you
arma_mult_cube_vec(cub, v)arma_mult_cube_vec(cub, v)
cub |
A cube (3D array) |
v |
A vector |
Transpose of multiplication over first dimension of cub time v
d1 <- 10 d2 <- 1e2 d3 <- 2e2 aa <- array(data = rnorm(d1*d2*d3), dim = c(d1, d2, d3)) bb <- rnorm(d3) t1 <- apply(aa, 1, function(U) {U%*%bb}) t2 <- arma_mult_cube_vec(aa, bb) dd <- t1 - t2 summary(dd) image(dd) table(dd) # microbenchmark::microbenchmark(apply(aa, 1, function(U) {U%*%bb}), # arma_mult_cube_vec(aa, bb))d1 <- 10 d2 <- 1e2 d3 <- 2e2 aa <- array(data = rnorm(d1*d2*d3), dim = c(d1, d2, d3)) bb <- rnorm(d3) t1 <- apply(aa, 1, function(U) {U%*%bb}) t2 <- arma_mult_cube_vec(aa, bb) dd <- t1 - t2 summary(dd) image(dd) table(dd) # microbenchmark::microbenchmark(apply(aa, 1, function(U) {U%*%bb}), # arma_mult_cube_vec(aa, bb))
Correlation Cubic matrix in C (symmetric)
corr_cubic_matrix_symC(x, theta)corr_cubic_matrix_symC(x, theta)
x |
Matrix x |
theta |
Theta vector |
Correlation matrix
corr_cubic_matrix_symC(matrix(c(1,0,0,1),2,2),c(1,1))corr_cubic_matrix_symC(matrix(c(1,0,0,1),2,2),c(1,1))
Correlation Gaussian matrix in C (symmetric)
corr_exponential_matrix_symC(x, theta)corr_exponential_matrix_symC(x, theta)
x |
Matrix x |
theta |
Theta vector |
Correlation matrix
corr_gauss_matrix_symC(matrix(c(1,0,0,1),2,2),c(1,1))corr_gauss_matrix_symC(matrix(c(1,0,0,1),2,2),c(1,1))
Correlation Gaussian matrix gradient in C using Armadillo
corr_gauss_dCdX(XX, X, theta, s2)corr_gauss_dCdX(XX, X, theta, s2)
XX |
Matrix XX to get gradient for |
X |
Matrix X GP was fit to |
theta |
Theta vector |
s2 |
Variance parameter |
3-dim array of correlation derivative
# corr_gauss_dCdX(matrix(c(1,0,0,1),2,2),c(1,1))# corr_gauss_dCdX(matrix(c(1,0,0,1),2,2),c(1,1))
Gaussian correlation
corr_gauss_matrix(x, x2 = NULL, theta)corr_gauss_matrix(x, x2 = NULL, theta)
x |
First data matrix |
x2 |
Second data matrix |
theta |
Correlation parameter |
Correlation matrix
corr_gauss_matrix(matrix(1:10,ncol=1), matrix(6:15,ncol=1), 1e-2)corr_gauss_matrix(matrix(1:10,ncol=1), matrix(6:15,ncol=1), 1e-2)
20-25
corr_gauss_matrix_armaC(x, y, theta, s2 = 1)corr_gauss_matrix_armaC(x, y, theta, s2 = 1)
x |
Matrix x |
y |
Matrix y, must have same number of columns as x |
theta |
Theta vector |
s2 |
Variance to multiply matrix by |
Correlation matrix
corr_gauss_matrix_armaC(matrix(c(1,0,0,1),2,2),matrix(c(1,0,1,1),2,2),c(1,1)) x1 <- matrix(runif(100*6), nrow=100, ncol=6) x2 <- matrix(runif(1e4*6), ncol=6) th <- runif(6) t1 <- corr_gauss_matrixC(x1, x2, th) t2 <- corr_gauss_matrix_armaC(x1, x2, th) identical(t1, t2) # microbenchmark::microbenchmark(corr_gauss_matrixC(x1, x2, th), # corr_gauss_matrix_armaC(x1, x2, th))corr_gauss_matrix_armaC(matrix(c(1,0,0,1),2,2),matrix(c(1,0,1,1),2,2),c(1,1)) x1 <- matrix(runif(100*6), nrow=100, ncol=6) x2 <- matrix(runif(1e4*6), ncol=6) th <- runif(6) t1 <- corr_gauss_matrixC(x1, x2, th) t2 <- corr_gauss_matrix_armaC(x1, x2, th) identical(t1, t2) # microbenchmark::microbenchmark(corr_gauss_matrixC(x1, x2, th), # corr_gauss_matrix_armaC(x1, x2, th))
About 30
corr_gauss_matrix_sym_armaC(x, theta)corr_gauss_matrix_sym_armaC(x, theta)
x |
Matrix x |
theta |
Theta vector |
Correlation matrix
corr_gauss_matrix_sym_armaC(matrix(c(1,0,0,1),2,2),c(1,1)) x3 <- matrix(runif(1e3*6), ncol=6) th <- runif(6) t3 <- corr_gauss_matrix_symC(x3, th) t4 <- corr_gauss_matrix_sym_armaC(x3, th) identical(t3, t4) # microbenchmark::microbenchmark(corr_gauss_matrix_symC(x3, th), # corr_gauss_matrix_sym_armaC(x3, th), times=50)corr_gauss_matrix_sym_armaC(matrix(c(1,0,0,1),2,2),c(1,1)) x3 <- matrix(runif(1e3*6), ncol=6) th <- runif(6) t3 <- corr_gauss_matrix_symC(x3, th) t4 <- corr_gauss_matrix_sym_armaC(x3, th) identical(t3, t4) # microbenchmark::microbenchmark(corr_gauss_matrix_symC(x3, th), # corr_gauss_matrix_sym_armaC(x3, th), times=50)
Correlation Gaussian matrix in C (symmetric)
corr_gauss_matrix_symC(x, theta)corr_gauss_matrix_symC(x, theta)
x |
Matrix x |
theta |
Theta vector |
Correlation matrix
corr_gauss_matrix_symC(matrix(c(1,0,0,1),2,2),c(1,1))corr_gauss_matrix_symC(matrix(c(1,0,0,1),2,2),c(1,1))
Correlation Gaussian matrix in C using Rcpp
corr_gauss_matrixC(x, y, theta)corr_gauss_matrixC(x, y, theta)
x |
Matrix x |
y |
Matrix y, must have same number of columns as x |
theta |
Theta vector |
Correlation matrix
corr_gauss_matrixC(matrix(c(1,0,0,1),2,2), matrix(c(1,0,1,1),2,2), c(1,1))corr_gauss_matrixC(matrix(c(1,0,0,1),2,2), matrix(c(1,0,1,1),2,2), c(1,1))
Correlation Latent factor matrix in C (symmetric)
corr_latentfactor_matrix_symC(x, theta, xindex, latentdim, offdiagequal)corr_latentfactor_matrix_symC(x, theta, xindex, latentdim, offdiagequal)
x |
Matrix x |
theta |
Theta vector |
xindex |
Index to use |
latentdim |
Number of latent dimensions |
offdiagequal |
What to set off-diagonal values with matching values to. |
Correlation matrix
corr_latentfactor_matrix_symC(matrix(c(1,.5, 2,1.6, 1,0),ncol=2,byrow=TRUE), c(1.5,1.8), 1, 1, 1-1e-6) corr_latentfactor_matrix_symC(matrix(c(0,0,0,1,0,0,0,2,0,0,0,3,0,0,0,4), ncol=4, byrow=TRUE), c(0.101, -0.714, 0.114, -0.755, 0.117, -0.76, 0.116, -0.752), 4, 2, 1-1e-6) * 6.85corr_latentfactor_matrix_symC(matrix(c(1,.5, 2,1.6, 1,0),ncol=2,byrow=TRUE), c(1.5,1.8), 1, 1, 1-1e-6) corr_latentfactor_matrix_symC(matrix(c(0,0,0,1,0,0,0,2,0,0,0,3,0,0,0,4), ncol=4, byrow=TRUE), c(0.101, -0.714, 0.114, -0.755, 0.117, -0.76, 0.116, -0.752), 4, 2, 1-1e-6) * 6.85
Correlation Latent factor matrix in C (symmetric)
corr_latentfactor_matrixmatrixC(x, y, theta, xindex, latentdim, offdiagequal)corr_latentfactor_matrixmatrixC(x, y, theta, xindex, latentdim, offdiagequal)
x |
Matrix x |
y |
Matrix y |
theta |
Theta vector |
xindex |
Index to use |
latentdim |
Number of latent dimensions |
offdiagequal |
What to set off-diagonal values with matching values to. |
Correlation matrix
corr_latentfactor_matrixmatrixC(matrix(c(1,.5, 2,1.6, 1,0),ncol=2,byrow=TRUE), matrix(c(2,1.6, 1,0),ncol=2,byrow=TRUE), c(1.5,1.8), 1, 1, 1-1e-6) corr_latentfactor_matrixmatrixC(matrix(c(0,0,0,1,0,0,0,2,0,0,0,3,0,0,0,4), ncol=4, byrow=TRUE), matrix(c(0,0,0,2,0,0,0,4,0,0,0,1), ncol=4, byrow=TRUE), c(0.101, -0.714, 0.114, -0.755, 0.117, -0.76, 0.116, -0.752), 4, 2, 1-1e-6) * 6.85corr_latentfactor_matrixmatrixC(matrix(c(1,.5, 2,1.6, 1,0),ncol=2,byrow=TRUE), matrix(c(2,1.6, 1,0),ncol=2,byrow=TRUE), c(1.5,1.8), 1, 1, 1-1e-6) corr_latentfactor_matrixmatrixC(matrix(c(0,0,0,1,0,0,0,2,0,0,0,3,0,0,0,4), ncol=4, byrow=TRUE), matrix(c(0,0,0,2,0,0,0,4,0,0,0,1), ncol=4, byrow=TRUE), c(0.101, -0.714, 0.114, -0.755, 0.117, -0.76, 0.116, -0.752), 4, 2, 1-1e-6) * 6.85
Correlation Matern 3/2 matrix in C (symmetric)
corr_matern32_matrix_symC(x, theta)corr_matern32_matrix_symC(x, theta)
x |
Matrix x |
theta |
Theta vector |
Correlation matrix
corr_gauss_matrix_symC(matrix(c(1,0,0,1),2,2),c(1,1))corr_gauss_matrix_symC(matrix(c(1,0,0,1),2,2),c(1,1))
Correlation Gaussian matrix in C (symmetric)
corr_matern52_matrix_symC(x, theta)corr_matern52_matrix_symC(x, theta)
x |
Matrix x |
theta |
Theta vector |
Correlation matrix
corr_matern52_matrix_symC(matrix(c(1,0,0,1),2,2),c(1,1))corr_matern52_matrix_symC(matrix(c(1,0,0,1),2,2),c(1,1))
Correlation ordered factor matrix in C (symmetric)
corr_orderedfactor_matrix_symC(x, theta, xindex, offdiagequal)corr_orderedfactor_matrix_symC(x, theta, xindex, offdiagequal)
x |
Matrix x |
theta |
Theta vector |
xindex |
Index to use |
offdiagequal |
What to set off-diagonal values with matching values to. |
Correlation matrix
corr_orderedfactor_matrix_symC(matrix(c(1,.5, 2,1.6, 1,0),ncol=2,byrow=TRUE), c(1.5,1.8), 1, 1-1e-6) corr_orderedfactor_matrix_symC(matrix(c(0,0,0,1,0,0,0,2,0,0,0,3,0,0,0,4), ncol=4, byrow=TRUE), c(0.101, -0.714, 0.114, -0.755, 0.117, -0.76, 0.116, -0.752), 4, 1-1e-6) * 6.85corr_orderedfactor_matrix_symC(matrix(c(1,.5, 2,1.6, 1,0),ncol=2,byrow=TRUE), c(1.5,1.8), 1, 1-1e-6) corr_orderedfactor_matrix_symC(matrix(c(0,0,0,1,0,0,0,2,0,0,0,3,0,0,0,4), ncol=4, byrow=TRUE), c(0.101, -0.714, 0.114, -0.755, 0.117, -0.76, 0.116, -0.752), 4, 1-1e-6) * 6.85
Correlation ordered factor matrix in C (symmetric)
corr_orderedfactor_matrixmatrixC(x, y, theta, xindex, offdiagequal)corr_orderedfactor_matrixmatrixC(x, y, theta, xindex, offdiagequal)
x |
Matrix x |
y |
Matrix y |
theta |
Theta vector |
xindex |
Index to use |
offdiagequal |
What to set off-diagonal values with matching values to. |
Correlation matrix
corr_orderedfactor_matrixmatrixC(matrix(c(1,.5, 2,1.6, 1,0),ncol=2,byrow=TRUE), matrix(c(2,1.6, 1,0),ncol=2,byrow=TRUE), c(1.5,1.8), 1, 1-1e-6) corr_orderedfactor_matrixmatrixC(matrix(c(0,0,0,1,0,0,0,2,0,0,0,3,0,0,0,4), ncol=4, byrow=TRUE), matrix(c(0,0,0,2,0,0,0,4,0,0,0,1), ncol=4, byrow=TRUE), c(0.101, -0.714, 0.114, -0.755, 0.117, -0.76, 0.116, -0.752), 4, 1-1e-6) * 6.85corr_orderedfactor_matrixmatrixC(matrix(c(1,.5, 2,1.6, 1,0),ncol=2,byrow=TRUE), matrix(c(2,1.6, 1,0),ncol=2,byrow=TRUE), c(1.5,1.8), 1, 1-1e-6) corr_orderedfactor_matrixmatrixC(matrix(c(0,0,0,1,0,0,0,2,0,0,0,3,0,0,0,4), ncol=4, byrow=TRUE), matrix(c(0,0,0,2,0,0,0,4,0,0,0,1), ncol=4, byrow=TRUE), c(0.101, -0.714, 0.114, -0.755, 0.117, -0.76, 0.116, -0.752), 4, 1-1e-6) * 6.85
Cubic Kernel R6 class
Cubic Kernel R6 class
k_Cubic( beta, s2 = 1, D, beta_lower = -8, beta_upper = 6, beta_est = TRUE, s2_lower = 1e-08, s2_upper = 1e+08, s2_est = TRUE, useC = TRUE, isotropic = FALSE )k_Cubic( beta, s2 = 1, D, beta_lower = -8, beta_upper = 6, beta_est = TRUE, s2_lower = 1e-08, s2_upper = 1e+08, s2_est = TRUE, useC = TRUE, isotropic = FALSE )
beta |
Initial beta value |
s2 |
Initial variance |
D |
Number of input dimensions of data |
beta_lower |
Lower bound for beta |
beta_upper |
Upper bound for beta |
beta_est |
Should beta be estimated? |
s2_lower |
Lower bound for s2 |
s2_upper |
Upper bound for s2 |
s2_est |
Should s2 be estimated? |
useC |
Should C code used? Much faster. |
isotropic |
If isotropic then a single beta/theta is used for all dimensions. If not (anisotropic) then a separate beta/beta is used for each dimension. |
R6Class object.
Object of R6Class with methods for fitting GP model.
GauPro::GauPro_kernel -> GauPro::GauPro_kernel_beta -> GauPro_kernel_Cubic
GauPro::GauPro_kernel$plot()GauPro::GauPro_kernel_beta$C_dC_dparams()GauPro::GauPro_kernel_beta$initialize()GauPro::GauPro_kernel_beta$param_optim_lower()GauPro::GauPro_kernel_beta$param_optim_start()GauPro::GauPro_kernel_beta$param_optim_start0()GauPro::GauPro_kernel_beta$param_optim_upper()GauPro::GauPro_kernel_beta$s2_from_params()GauPro::GauPro_kernel_beta$set_params_from_optim()k()
Calculate covariance between two points
Cubic$k(x, y = NULL, beta = self$beta, s2 = self$s2, params = NULL)
xvector.
yvector, optional. If excluded, find correlation of x with itself.
betaCorrelation parameters.
s2Variance parameter.
paramsparameters to use instead of beta and s2.
kone()
Find covariance of two points
Cubic$kone(x, y, beta, theta, s2)
xvector
yvector
betacorrelation parameters on log scale
thetacorrelation parameters on regular scale
s2Variance parameter
dC_dparams()
Derivative of covariance with respect to parameters
Cubic$dC_dparams(params = NULL, X, C_nonug, C, nug)
paramsKernel parameters
Xmatrix of points in rows
C_nonugCovariance without nugget added to diagonal
CCovariance with nugget
nugValue of nugget
dC_dx()
Derivative of covariance with respect to X
Cubic$dC_dx(XX, X, theta, beta = self$beta, s2 = self$s2)
XXmatrix of points
Xmatrix of points to take derivative with respect to
thetaCorrelation parameters
betalog of theta
s2Variance parameter
print()
Print this object
Cubic$print()
clone()
The objects of this class are cloneable with this method.
Cubic$clone(deep = FALSE)
deepWhether to make a deep clone.
k1 <- Cubic$new(beta=runif(6)-.5) plot(k1) 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=Cubic$new(1), parallel=FALSE, restarts=0) gp$predict(.454)k1 <- Cubic$new(beta=runif(6)-.5) plot(k1) 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=Cubic$new(1), parallel=FALSE, restarts=0) gp$predict(.454)
Exponential Kernel R6 class
Exponential Kernel R6 class
k_Exponential( beta, s2 = 1, D, beta_lower = -8, beta_upper = 6, beta_est = TRUE, s2_lower = 1e-08, s2_upper = 1e+08, s2_est = TRUE, useC = TRUE, isotropic = FALSE )k_Exponential( beta, s2 = 1, D, beta_lower = -8, beta_upper = 6, beta_est = TRUE, s2_lower = 1e-08, s2_upper = 1e+08, s2_est = TRUE, useC = TRUE, isotropic = FALSE )
beta |
Initial beta value |
s2 |
Initial variance |
D |
Number of input dimensions of data |
beta_lower |
Lower bound for beta |
beta_upper |
Upper bound for beta |
beta_est |
Should beta be estimated? |
s2_lower |
Lower bound for s2 |
s2_upper |
Upper bound for s2 |
s2_est |
Should s2 be estimated? |
useC |
Should C code used? Much faster. |
isotropic |
If isotropic then a single beta/theta is used for all dimensions. If not (anisotropic) then a separate beta/beta is used for each dimension. |
R6Class object.
Object of R6Class with methods for fitting GP model.
GauPro::GauPro_kernel -> GauPro::GauPro_kernel_beta -> GauPro_kernel_Exponential
GauPro::GauPro_kernel$plot()GauPro::GauPro_kernel_beta$C_dC_dparams()GauPro::GauPro_kernel_beta$initialize()GauPro::GauPro_kernel_beta$param_optim_lower()GauPro::GauPro_kernel_beta$param_optim_start()GauPro::GauPro_kernel_beta$param_optim_start0()GauPro::GauPro_kernel_beta$param_optim_upper()GauPro::GauPro_kernel_beta$s2_from_params()GauPro::GauPro_kernel_beta$set_params_from_optim()k()
Calculate covariance between two points
Exponential$k(x, y = NULL, beta = self$beta, s2 = self$s2, params = NULL)
xvector.
yvector, optional. If excluded, find correlation of x with itself.
betaCorrelation parameters.
s2Variance parameter.
paramsparameters to use instead of beta and s2.
kone()
Find covariance of two points
Exponential$kone(x, y, beta, theta, s2)
xvector
yvector
betacorrelation parameters on log scale
thetacorrelation parameters on regular scale
s2Variance parameter
dC_dparams()
Derivative of covariance with respect to parameters
Exponential$dC_dparams(params = NULL, X, C_nonug, C, nug)
paramsKernel parameters
Xmatrix of points in rows
C_nonugCovariance without nugget added to diagonal
CCovariance with nugget
nugValue of nugget
dC_dx()
Derivative of covariance with respect to X
Exponential$dC_dx(XX, X, theta, beta = self$beta, s2 = self$s2)
XXmatrix of points
Xmatrix of points to take derivative with respect to
thetaCorrelation parameters
betalog of theta
s2Variance parameter
print()
Print this object
Exponential$print()
clone()
The objects of this class are cloneable with this method.
Exponential$clone(deep = FALSE)
deepWhether to make a deep clone.
k1 <- Exponential$new(beta=0)k1 <- Exponential$new(beta=0)
Initialize kernel object
k_FactorKernel( s2 = 1, D, nlevels, xindex, p_lower = 0, p_upper = 0.9, p_est = TRUE, s2_lower = 1e-08, s2_upper = 1e+08, s2_est = TRUE, p, useC = TRUE, offdiagequal = 1 - 1e-06 )k_FactorKernel( s2 = 1, D, nlevels, xindex, p_lower = 0, p_upper = 0.9, p_est = TRUE, s2_lower = 1e-08, s2_upper = 1e+08, s2_est = TRUE, p, useC = TRUE, offdiagequal = 1 - 1e-06 )
s2 |
Initial variance |
D |
Number of input dimensions of data |
nlevels |
Number of levels for the factor |
xindex |
Index of the factor (which column of X) |
p_lower |
Lower bound for p |
p_upper |
Upper bound for p |
p_est |
Should p be estimated? |
s2_lower |
Lower bound for s2 |
s2_upper |
Upper bound for s2 |
s2_est |
Should s2 be estimated? |
p |
Vector of correlations |
useC |
Should C code used? Not implemented for FactorKernel yet. |
offdiagequal |
What should offdiagonal values be set to when the indices are the same? Use to avoid decomposition errors, similar to adding a nugget. |
R6Class object.
For a factor that has been converted to its indices. Each factor will need a separate kernel.
Object of R6Class with methods for fitting GP model.
GauPro::GauPro_kernel -> GauPro_kernel_FactorKernel
pParameter for correlation
p_estShould p be estimated?
p_lowerLower bound of p
p_upperUpper bound of p
p_lengthlength of p
s2variance
s2_estIs s2 estimated?
logs2Log of s2
logs2_lowerLower bound of logs2
logs2_upperUpper bound of logs2
xindexIndex of the factor (which column of X)
nlevelsNumber of levels for the factor
offdiagequalWhat should offdiagonal values be set to when the indices are the same? Use to avoid decomposition errors, similar to adding a nugget.
new()
Initialize kernel object
FactorKernel$new( s2 = 1, D, nlevels, xindex, p_lower = 0, p_upper = 0.9, p_est = TRUE, s2_lower = 1e-08, s2_upper = 1e+08, s2_est = TRUE, p, useC = TRUE, offdiagequal = 1 - 1e-06 )
s2Initial variance
DNumber of input dimensions of data
nlevelsNumber of levels for the factor
xindexIndex of the factor (which column of X)
p_lowerLower bound for p
p_upperUpper bound for p
p_estShould p be estimated?
s2_lowerLower bound for s2
s2_upperUpper bound for s2
s2_estShould s2 be estimated?
pVector of correlations
useCShould C code used? Not implemented for FactorKernel yet.
offdiagequalWhat should offdiagonal values be set to when the indices are the same? Use to avoid decomposition errors, similar to adding a nugget.
k()
Calculate covariance between two points
FactorKernel$k(x, y = NULL, p = self$p, s2 = self$s2, params = NULL)
xvector.
yvector, optional. If excluded, find correlation of x with itself.
pCorrelation parameters.
s2Variance parameter.
paramsparameters to use instead of beta and s2.
kone()
Find covariance of two points
FactorKernel$kone(x, y, p, s2, isdiag = TRUE, offdiagequal = self$offdiagequal)
xvector
yvector
pcorrelation parameters on regular scale
s2Variance parameter
isdiagIs this on the diagonal of the covariance?
offdiagequalWhat should offdiagonal values be set to when the indices are the same? Use to avoid decomposition errors, similar to adding a nugget.
dC_dparams()
Derivative of covariance with respect to parameters
FactorKernel$dC_dparams(params = NULL, X, C_nonug, C, nug)
paramsKernel parameters
Xmatrix of points in rows
C_nonugCovariance without nugget added to diagonal
CCovariance with nugget
nugValue of nugget
C_dC_dparams()
Calculate covariance matrix and its derivative with respect to parameters
FactorKernel$C_dC_dparams(params = NULL, X, nug)
paramsKernel parameters
Xmatrix of points in rows
nugValue of nugget
dC_dx()
Derivative of covariance with respect to X
FactorKernel$dC_dx(XX, X, ...)
XXmatrix of points
Xmatrix of points to take derivative with respect to
...Additional args, not used
param_optim_start()
Starting point for parameters for optimization
FactorKernel$param_optim_start( jitter = F, y, p_est = self$p_est, s2_est = self$s2_est )
jitterShould there be a jitter?
yOutput
p_estIs p being estimated?
s2_estIs s2 being estimated?
param_optim_start0()
Starting point for parameters for optimization
FactorKernel$param_optim_start0( jitter = F, y, p_est = self$p_est, s2_est = self$s2_est )
jitterShould there be a jitter?
yOutput
p_estIs p being estimated?
s2_estIs s2 being estimated?
param_optim_lower()
Lower bounds of parameters for optimization
FactorKernel$param_optim_lower(p_est = self$p_est, s2_est = self$s2_est)
p_estIs p being estimated?
s2_estIs s2 being estimated?
param_optim_upper()
Upper bounds of parameters for optimization
FactorKernel$param_optim_upper(p_est = self$p_est, s2_est = self$s2_est)
p_estIs p being estimated?
s2_estIs s2 being estimated?
set_params_from_optim()
Set parameters from optimization output
FactorKernel$set_params_from_optim( optim_out, p_est = self$p_est, s2_est = self$s2_est )
optim_outOutput from optimization
p_estIs p being estimated?
s2_estIs s2 being estimated?
s2_from_params()
Get s2 from params vector
FactorKernel$s2_from_params(params, s2_est = self$s2_est)
paramsparameter vector
s2_estIs s2 being estimated?
print()
Print this object
FactorKernel$print()
clone()
The objects of this class are cloneable with this method.
FactorKernel$clone(deep = FALSE)
deepWhether to make a deep clone.
kk <- FactorKernel$new(D=1, nlevels=5, xindex=1) kk$p <- (1:10)/100 kmat <- outer(1:5, 1:5, Vectorize(kk$k)) kmat kk$plot() # 2D, Gaussian on 1D, index on 2nd dim if (requireNamespace("dplyr", quietly=TRUE)) { library(dplyr) n <- 20 X <- cbind(matrix(runif(n,2,6), ncol=1), matrix(sample(1:2, size=n, replace=TRUE), ncol=1)) X <- rbind(X, c(3.3,3)) n <- nrow(X) Z <- X[,1] - (X[,2]-1.8)^2 + rnorm(n,0,.1) tibble(X=X, Z) %>% arrange(X,Z) k2a <- IgnoreIndsKernel$new(k=Gaussian$new(D=1), ignoreinds = 2) k2b <- FactorKernel$new(D=2, nlevels=3, xind=2) k2 <- k2a * k2b k2b$p_upper <- .65*k2b$p_upper gp <- GauPro_kernel_model$new(X=X, Z=Z, kernel = k2, verbose = 5, nug.min=1e-2, restarts=0) gp$kernel$k1$kernel$beta gp$kernel$k2$p gp$kernel$k(x = gp$X) tibble(X=X, Z=Z, pred=gp$predict(X)) %>% arrange(X, Z) tibble(X=X[,2], Z) %>% group_by(X) %>% summarize(n=n(), mean(Z)) curve(gp$pred(cbind(matrix(x,ncol=1),1)),2,6, ylim=c(min(Z), max(Z))) points(X[X[,2]==1,1], Z[X[,2]==1]) curve(gp$pred(cbind(matrix(x,ncol=1),2)), add=TRUE, col=2) points(X[X[,2]==2,1], Z[X[,2]==2], col=2) curve(gp$pred(cbind(matrix(x,ncol=1),3)), add=TRUE, col=3) points(X[X[,2]==3,1], Z[X[,2]==3], col=3) legend(legend=1:3, fill=1:3, x="topleft") # See which points affect (5.5, 3 themost) data.frame(X, cov=gp$kernel$k(X, c(5.5,3))) %>% arrange(-cov) plot(k2b) }kk <- FactorKernel$new(D=1, nlevels=5, xindex=1) kk$p <- (1:10)/100 kmat <- outer(1:5, 1:5, Vectorize(kk$k)) kmat kk$plot() # 2D, Gaussian on 1D, index on 2nd dim if (requireNamespace("dplyr", quietly=TRUE)) { library(dplyr) n <- 20 X <- cbind(matrix(runif(n,2,6), ncol=1), matrix(sample(1:2, size=n, replace=TRUE), ncol=1)) X <- rbind(X, c(3.3,3)) n <- nrow(X) Z <- X[,1] - (X[,2]-1.8)^2 + rnorm(n,0,.1) tibble(X=X, Z) %>% arrange(X,Z) k2a <- IgnoreIndsKernel$new(k=Gaussian$new(D=1), ignoreinds = 2) k2b <- FactorKernel$new(D=2, nlevels=3, xind=2) k2 <- k2a * k2b k2b$p_upper <- .65*k2b$p_upper gp <- GauPro_kernel_model$new(X=X, Z=Z, kernel = k2, verbose = 5, nug.min=1e-2, restarts=0) gp$kernel$k1$kernel$beta gp$kernel$k2$p gp$kernel$k(x = gp$X) tibble(X=X, Z=Z, pred=gp$predict(X)) %>% arrange(X, Z) tibble(X=X[,2], Z) %>% group_by(X) %>% summarize(n=n(), mean(Z)) curve(gp$pred(cbind(matrix(x,ncol=1),1)),2,6, ylim=c(min(Z), max(Z))) points(X[X[,2]==1,1], Z[X[,2]==1]) curve(gp$pred(cbind(matrix(x,ncol=1),2)), add=TRUE, col=2) points(X[X[,2]==2,1], Z[X[,2]==2], col=2) curve(gp$pred(cbind(matrix(x,ncol=1),3)), add=TRUE, col=3) points(X[X[,2]==3,1], Z[X[,2]==3], col=3) legend(legend=1:3, fill=1:3, x="topleft") # See which points affect (5.5, 3 themost) data.frame(X, cov=gp$kernel$k(X, c(5.5,3))) %>% arrange(-cov) plot(k2b) }
GauPro_selector
GauPro(..., type = "Gauss")GauPro(..., type = "Gauss")
... |
Pass on |
type |
Type of Gaussian process, or the kind of correlation function. |
A GauPro object
n <- 12 x <- matrix(seq(0,1,length.out = n), ncol=1) #y <- sin(2*pi*x) + rnorm(n,0,1e-1) y <- (2*x) %%1 gp <- GauPro(X=x, Z=y, parallel=FALSE)n <- 12 x <- matrix(seq(0,1,length.out = n), ncol=1) #y <- sin(2*pi*x) + rnorm(n,0,1e-1) y <- (2*x) %%1 gp <- GauPro(X=x, Z=y, parallel=FALSE)
Class providing object with methods for fitting a GP model
Class providing object with methods for fitting a GP model
R6Class object.
Object of R6Class with methods for fitting GP model.
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
nugValue of the nugget, is estimated unless told otherwise
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? It will self detect, do not set yourself.
nug.estShould the nugget be estimated?
param.estShould the parameters be estimated?
mu_hatMean estimate
s2_hatVariance estimate
KCovariance matrix
KcholCholesky factorization of K
KinvInverse of K
corr_func()
Correlation function
GauPro_base$corr_func(...)
...Does nothing
new()
Create GauPro object
GauPro_base$new( X, Z, verbose = 0, useC = F, useGrad = T, parallel = FALSE, nug = 1e-06, nug.min = 1e-08, nug.est = T, param.est = TRUE, ... )
XMatrix whose rows are the input points
ZOutput points corresponding to X
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.
nugValue for the nugget. The starting value if estimating it.
nug.minMinimum allowable value for the nugget.
nug.estShould the nugget be estimated?
param.estShould the kernel parameters be estimated?
...Not used
initialize_GauPr()
Not used
GauPro_base$initialize_GauPr()
fit()
Fit the model, never use this function
GauPro_base$fit(X, Z)
XNot used
ZNot used
update_K_and_estimates()
Update Covariance matrix and estimated parameters
GauPro_base$update_K_and_estimates()
predict()
Predict mean and se for given matrix
GauPro_base$predict(XX, se.fit = F, covmat = F, split_speed = T)
XXPoints to predict at
se.fitShould the se be returned?
covmatShould the covariance matrix be returned?
split_speedShould the predictions be split up for speed
pred()
Predict mean and se for given matrix
GauPro_base$pred(XX, se.fit = F, covmat = F, split_speed = T)
XXPoints to predict at
se.fitShould the se be returned?
covmatShould the covariance matrix be returned?
split_speedShould the predictions be split up for speed
pred_one_matrix()
Predict mean and se for given matrix
GauPro_base$pred_one_matrix(XX, se.fit = F, covmat = F)
XXPoints to predict at
se.fitShould the se be returned?
covmatShould the covariance matrix be returned?
pred_mean()
Predict mean
GauPro_base$pred_mean(XX, kx.xx)
XXPoints to predict at
kx.xxCovariance matrix between X and XX
pred_meanC()
Predict mean using C code
GauPro_base$pred_meanC(XX, kx.xx)
XXPoints to predict at
kx.xxCovariance matrix between X and XX
pred_var()
Predict variance
GauPro_base$pred_var(XX, kxx, kx.xx, covmat = F)
XXPoints to predict at
kxxCovariance matrix of XX with itself
kx.xxCovariance matrix between X and XX
covmatNot used
pred_LOO()
Predict at X using leave-one-out. Can use for diagnostics.
GauPro_base$pred_LOO(se.fit = FALSE)
se.fitShould the standard error and t values be returned?
plot()
Plot the object
GauPro_base$plot(...)
...Parameters passed to cool1Dplot(), plot2D(), or plotmarginal()
cool1Dplot()
Make cool 1D plot
GauPro_base$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_base$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 of the prediction interval
xlabx label
ylaby label
xminxmin
xmaxxmax
yminymin
ymaxymax
plot2D()
Make 2D plot
GauPro_base$plot2D()
loglikelihood()
Calculate the log likelihood, don't use this
GauPro_base$loglikelihood(mu = self$mu_hat, s2 = self$s2_hat)
muMean vector
s2s2 param
optim()
Optimize parameters
GauPro_base$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_base$optimRestart( start.par, start.par0, param_update, nug.update, optim.func, optim.grad, optim.fngr, lower, upper, jit = T )
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?
update()
Update the model, can be data and parameters
GauPro_base$update( Xnew = NULL, Znew = NULL, Xall = NULL, Zall = NULL, restarts = 5, param_update = self$param.est, nug.update = self$nug.est, no_update = FALSE )
XnewNew X matrix
ZnewNew Z values
XallMatrix with all X values
ZallAll Z values
restartsNumber of optimization restarts
param_updateShould the parameters be updated?
nug.updateShould the nugget be updated?
no_updateShould none of the parameters/nugget be updated?
update_data()
Update the data
GauPro_base$update_data(Xnew = NULL, Znew = NULL, Xall = NULL, Zall = NULL)
XnewNew X matrix
ZnewNew Z values
XallMatrix with all X values
ZallAll Z values
update_corrparams()
Update the correlation parameters
GauPro_base$update_corrparams(...)
...Args passed to update
update_nugget()
Update the nugget
GauPro_base$update_nugget(...)
...Args passed to update
deviance_searchnug()
Optimize deviance for nugget
GauPro_base$deviance_searchnug()
nugget_update()
Update the nugget
GauPro_base$nugget_update()
grad_norm()
Calculate the norm of the gradient at XX
GauPro_base$grad_norm(XX)
XXPoints to calculate at
sample()
Sample at XX
GauPro_base$sample(XX, n = 1)
XXInput points to sample at
nNumber of samples
print()
Print object
GauPro_base$print()
clone()
The objects of this class are cloneable with this method.
GauPro_base$clone(deep = FALSE)
deepWhether to make a deep clone.
#n <- 12 #x <- matrix(seq(0,1,length.out = n), ncol=1) #y <- sin(2*pi*x) + rnorm(n,0,1e-1) #gp <- GauPro(X=x, Z=y, parallel=FALSE)#n <- 12 #x <- matrix(seq(0,1,length.out = n), ncol=1) #y <- sin(2*pi*x) + rnorm(n,0,1e-1) #gp <- GauPro(X=x, Z=y, parallel=FALSE)
Corr Gauss GP using inherited optim
Corr Gauss GP using inherited optim
R6Class object.
Object of R6Class with methods for fitting GP model.
GauPro::GauPro_base -> GauPro_Gauss
corrName of correlation
thetaCorrelation parameters
theta_lengthLength of theta
theta_mapMap for theta
theta_shortShort vector for theta
separableAre the dimensions separable?
GauPro::GauPro_base$cool1Dplot()GauPro::GauPro_base$deviance_searchnug()GauPro::GauPro_base$fit()GauPro::GauPro_base$grad_norm()GauPro::GauPro_base$initialize_GauPr()GauPro::GauPro_base$loglikelihood()GauPro::GauPro_base$nugget_update()GauPro::GauPro_base$optim()GauPro::GauPro_base$optimRestart()GauPro::GauPro_base$plot()GauPro::GauPro_base$plot1D()GauPro::GauPro_base$plot2D()GauPro::GauPro_base$pred()GauPro::GauPro_base$pred_LOO()GauPro::GauPro_base$pred_mean()GauPro::GauPro_base$pred_meanC()GauPro::GauPro_base$pred_one_matrix()GauPro::GauPro_base$pred_var()GauPro::GauPro_base$predict()GauPro::GauPro_base$sample()GauPro::GauPro_base$update()GauPro::GauPro_base$update_K_and_estimates()GauPro::GauPro_base$update_corrparams()GauPro::GauPro_base$update_data()GauPro::GauPro_base$update_nugget()new()
Create GauPro object
GauPro_Gauss$new( X, Z, verbose = 0, separable = T, useC = F, useGrad = T, parallel = FALSE, nug = 1e-06, nug.min = 1e-08, nug.est = T, param.est = T, theta = NULL, theta_short = NULL, theta_map = NULL, ... )
XMatrix whose rows are the input points
ZOutput points corresponding to X
verboseAmount of stuff to print. 0 is little, 2 is a lot.
separableAre dimensions separable?
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.
nugValue for the nugget. The starting value if estimating it.
nug.minMinimum allowable value for the nugget.
nug.estShould the nugget be estimated?
param.estShould the kernel parameters be estimated?
thetaCorrelation parameters
theta_shortCorrelation parameters, not recommended
theta_mapCorrelation parameters, not recommended
...Not used
corr_func()
Correlation function
GauPro_Gauss$corr_func(x, x2 = NULL, theta = self$theta)
xFirst point
x2Second point
thetaCorrelation parameter
deviance_theta()
Calculate deviance
GauPro_Gauss$deviance_theta(theta)
thetaCorrelation parameter
deviance_theta_log()
Calculate deviance
GauPro_Gauss$deviance_theta_log(beta)
betaCorrelation parameter on log scale
deviance()
Calculate deviance
GauPro_Gauss$deviance(theta = self$theta, nug = self$nug)
thetaCorrelation parameter
nugNugget
deviance_grad()
Calculate deviance gradient
GauPro_Gauss$deviance_grad( theta = NULL, nug = self$nug, joint = NULL, overwhat = if (self$nug.est) "joint" else "theta" )
thetaCorrelation parameter
nugNugget
jointCalculate over theta and nug at same time?
overwhatCalculate over theta and nug at same time?
deviance_fngr()
Calculate deviance and gradient at same time
GauPro_Gauss$deviance_fngr( theta = NULL, nug = NULL, overwhat = if (self$nug.est) "joint" else "theta" )
thetaCorrelation parameter
nugNugget
overwhatCalculate over theta and nug at same time?
jointCalculate over theta and nug at same time?
deviance_log()
Calculate deviance gradient
GauPro_Gauss$deviance_log(beta = NULL, nug = self$nug, joint = NULL)
betaCorrelation parameter on log scale
nugNugget
jointCalculate over theta and nug at same time?
deviance_log2()
Calculate deviance on log scale
GauPro_Gauss$deviance_log2(beta = NULL, lognug = NULL, joint = NULL)
betaCorrelation parameter on log scale
lognugLog of nugget
jointCalculate over theta and nug at same time?
deviance_log_grad()
Calculate deviance gradient on log scale
GauPro_Gauss$deviance_log_grad( beta = NULL, nug = self$nug, joint = NULL, overwhat = if (self$nug.est) "joint" else "theta" )
betaCorrelation parameter
nugNugget
jointCalculate over theta and nug at same time?
overwhatCalculate over theta and nug at same time?
deviance_log2_grad()
Calculate deviance gradient on log scale
GauPro_Gauss$deviance_log2_grad( beta = NULL, lognug = NULL, joint = NULL, overwhat = if (self$nug.est) "joint" else "theta" )
betaCorrelation parameter
lognugLog of nugget
jointCalculate over theta and nug at same time?
overwhatCalculate over theta and nug at same time?
deviance_log2_fngr()
Calculate deviance and gradient on log scale
GauPro_Gauss$deviance_log2_fngr( beta = NULL, lognug = NULL, joint = NULL, overwhat = if (self$nug.est) "joint" else "theta" )
betaCorrelation parameter
lognugLog of nugget
jointCalculate over theta and nug at same time?
overwhatCalculate over theta and nug at same time?
get_optim_functions()
Get optimization functions
GauPro_Gauss$get_optim_functions(param_update, nug.update)
param_updateShould the parameters be updated?
nug.updateShould the nugget be updated?
param_optim_lower()
Lower bound of params
GauPro_Gauss$param_optim_lower()
param_optim_upper()
Upper bound of params
GauPro_Gauss$param_optim_upper()
param_optim_start()
Start value of params for optim
GauPro_Gauss$param_optim_start()
param_optim_start0()
Start value of params for optim
GauPro_Gauss$param_optim_start0()
param_optim_jitter()
Jitter value of params for optim
GauPro_Gauss$param_optim_jitter(param_value)
param_valueparam value to add jitter to
update_params()
Update value of params after optim
GauPro_Gauss$update_params(restarts, param_update, nug.update)
restartsNumber of restarts
param_updateAre the params being updated?
nug.updateIs the nugget being updated?
grad()
Calculate the gradient
GauPro_Gauss$grad(XX)
XXPoints to calculate grad at
grad_dist()
Calculate the gradient distribution
GauPro_Gauss$grad_dist(XX)
XXPoints to calculate grad at
hessian()
Calculate the hessian
GauPro_Gauss$hessian(XX, useC = self$useC)
XXPoints to calculate grad at
useCShould C code be used to speed up?
print()
Print this object
GauPro_Gauss$print()
clone()
The objects of this class are cloneable with this method.
GauPro_Gauss$clone(deep = FALSE)
deepWhether to make a deep clone.
n <- 12 x <- matrix(seq(0,1,length.out = n), ncol=1) y <- sin(2*pi*x) + rnorm(n,0,1e-1) gp <- GauPro_Gauss$new(X=x, Z=y, parallel=FALSE)n <- 12 x <- matrix(seq(0,1,length.out = n), ncol=1) y <- sin(2*pi*x) + rnorm(n,0,1e-1) gp <- GauPro_Gauss$new(X=x, Z=y, parallel=FALSE)
Corr Gauss GP using inherited optim
Corr Gauss GP using inherited optim
R6Class object.
Object of R6Class with methods for fitting GP model.
GauPro::GauPro_base -> GauPro::GauPro_Gauss -> GauPro_Gauss_LOO
use_LOOShould the leave-one-out correction be used?
tmodSecond GP model fit to the t-values of leave-one-out predictions
GauPro::GauPro_base$cool1Dplot()GauPro::GauPro_base$deviance_searchnug()GauPro::GauPro_base$fit()GauPro::GauPro_base$grad_norm()GauPro::GauPro_base$initialize_GauPr()GauPro::GauPro_base$loglikelihood()GauPro::GauPro_base$nugget_update()GauPro::GauPro_base$optim()GauPro::GauPro_base$optimRestart()GauPro::GauPro_base$plot()GauPro::GauPro_base$plot1D()GauPro::GauPro_base$plot2D()GauPro::GauPro_base$pred()GauPro::GauPro_base$pred_LOO()GauPro::GauPro_base$pred_mean()GauPro::GauPro_base$pred_meanC()GauPro::GauPro_base$pred_var()GauPro::GauPro_base$predict()GauPro::GauPro_base$sample()GauPro::GauPro_base$update_K_and_estimates()GauPro::GauPro_base$update_corrparams()GauPro::GauPro_base$update_data()GauPro::GauPro_base$update_nugget()GauPro::GauPro_Gauss$corr_func()GauPro::GauPro_Gauss$deviance()GauPro::GauPro_Gauss$deviance_fngr()GauPro::GauPro_Gauss$deviance_grad()GauPro::GauPro_Gauss$deviance_log()GauPro::GauPro_Gauss$deviance_log2()GauPro::GauPro_Gauss$deviance_log2_fngr()GauPro::GauPro_Gauss$deviance_log2_grad()GauPro::GauPro_Gauss$deviance_log_grad()GauPro::GauPro_Gauss$deviance_theta()GauPro::GauPro_Gauss$deviance_theta_log()GauPro::GauPro_Gauss$get_optim_functions()GauPro::GauPro_Gauss$grad()GauPro::GauPro_Gauss$grad_dist()GauPro::GauPro_Gauss$hessian()GauPro::GauPro_Gauss$initialize()GauPro::GauPro_Gauss$param_optim_jitter()GauPro::GauPro_Gauss$param_optim_lower()GauPro::GauPro_Gauss$param_optim_start()GauPro::GauPro_Gauss$param_optim_start0()GauPro::GauPro_Gauss$param_optim_upper()GauPro::GauPro_Gauss$update_params()update()
Update the model, can be data and parameters
GauPro_Gauss_LOO$update( Xnew = NULL, Znew = NULL, Xall = NULL, Zall = NULL, restarts = 5, param_update = self$param.est, nug.update = self$nug.est, no_update = FALSE )
XnewNew X matrix
ZnewNew Z values
XallMatrix with all X values
ZallAll Z values
restartsNumber of optimization restarts
param_updateShould the parameters be updated?
nug.updateShould the nugget be updated?
no_updateShould none of the parameters/nugget be updated?
pred_one_matrix()
Predict mean and se for given matrix
GauPro_Gauss_LOO$pred_one_matrix(XX, se.fit = F, covmat = F)
XXPoints to predict at
se.fitShould the se be returned?
covmatShould the covariance matrix be returned?
print()
Print this object
GauPro_Gauss_LOO$print()
clone()
The objects of this class are cloneable with this method.
GauPro_Gauss_LOO$clone(deep = FALSE)
deepWhether to make a deep clone.
n <- 12 x <- matrix(seq(0,1,length.out = n), ncol=1) y <- sin(2*pi*x) + rnorm(n,0,1e-1) gp <- GauPro_Gauss_LOO$new(X=x, Z=y, parallel=FALSE)n <- 12 x <- matrix(seq(0,1,length.out = n), ncol=1) y <- sin(2*pi*x) + rnorm(n,0,1e-1) gp <- GauPro_Gauss_LOO$new(X=x, Z=y, parallel=FALSE)
Kernel R6 class
Kernel R6 class
R6Class object.
Object of R6Class with methods for fitting GP model.
DNumber of input dimensions of data
useCShould C code be used when possible? Can be much faster.
plot()
Plot kernel decay.
GauPro_kernel$plot(X = NULL)
XMatrix of points the kernel is used with. Some will be used to demonstrate how the covariance changes.
print()
Print this object
GauPro_kernel$print()
clone()
The objects of this class are cloneable with this method.
GauPro_kernel$clone(deep = FALSE)
deepWhether to make a deep clone.
#k <- GauPro_kernel$new()#k <- GauPro_kernel$new()
Beta Kernel R6 class
Beta Kernel R6 class
R6Class object.
This is the base structure for a kernel that uses beta = log10(theta) for the lengthscale parameter. It standardizes the params because they all use the same underlying structure. Kernels that inherit this only need to implement kone and dC_dparams.
Object of R6Class with methods for fitting GP model.
GauPro::GauPro_kernel -> GauPro_kernel_beta
betaParameter for correlation. Log of theta.
beta_estShould beta be estimated?
beta_lowerLower bound of beta
beta_upperUpper bound of beta
beta_lengthlength of beta
s2variance
logs2Log of s2
logs2_lowerLower bound of logs2
logs2_upperUpper bound of logs2
s2_estShould s2 be estimated?
useCShould C code used? Much faster.
isotropicIf isotropic then a single beta/theta is used for all dimensions. If not (anisotropic) then a separate beta/beta is used for each dimension.
new()
Initialize kernel object
GauPro_kernel_beta$new( beta, s2 = 1, D, beta_lower = -8, beta_upper = 6, beta_est = TRUE, s2_lower = 1e-08, s2_upper = 1e+08, s2_est = TRUE, useC = TRUE, isotropic = FALSE )
betaInitial beta value
s2Initial variance
DNumber of input dimensions of data
beta_lowerLower bound for beta
beta_upperUpper bound for beta
beta_estShould beta be estimated?
s2_lowerLower bound for s2
s2_upperUpper bound for s2
s2_estShould s2 be estimated?
useCShould C code used? Much faster.
isotropicIf isotropic then a single beta/theta is used for all dimensions. If not (anisotropic) then a separate beta/beta is used for each dimension.
k()
Calculate covariance between two points
GauPro_kernel_beta$k( x, y = NULL, beta = self$beta, s2 = self$s2, params = NULL )
xvector.
yvector, optional. If excluded, find correlation of x with itself.
betaCorrelation parameters. Log of theta.
s2Variance parameter.
paramsparameters to use instead of beta and s2.
kone()
Calculate covariance between two points
GauPro_kernel_beta$kone(x, y, beta, theta, s2)
xvector.
yvector.
betaCorrelation parameters. Log of theta.
thetaCorrelation parameters.
s2Variance parameter.
param_optim_start()
Starting point for parameters for optimization
GauPro_kernel_beta$param_optim_start( jitter = F, y, beta_est = self$beta_est, s2_est = self$s2_est )
jitterShould there be a jitter?
yOutput
beta_estIs beta being estimated?
s2_estIs s2 being estimated?
param_optim_start0()
Starting point for parameters for optimization
GauPro_kernel_beta$param_optim_start0( jitter = F, y, beta_est = self$beta_est, s2_est = self$s2_est )
jitterShould there be a jitter?
yOutput
beta_estIs beta being estimated?
s2_estIs s2 being estimated?
param_optim_lower()
Upper bounds of parameters for optimization
GauPro_kernel_beta$param_optim_lower( beta_est = self$beta_est, s2_est = self$s2_est )
beta_estIs beta being estimated?
s2_estIs s2 being estimated?
p_estIs p being estimated?
param_optim_upper()
Upper bounds of parameters for optimization
GauPro_kernel_beta$param_optim_upper( beta_est = self$beta_est, s2_est = self$s2_est )
beta_estIs beta being estimated?
s2_estIs s2 being estimated?
p_estIs p being estimated?
set_params_from_optim()
Set parameters from optimization output
GauPro_kernel_beta$set_params_from_optim( optim_out, beta_est = self$beta_est, s2_est = self$s2_est )
optim_outOutput from optimization
beta_estIs beta being estimated?
s2_estIs s2 being estimated?
C_dC_dparams()
Calculate covariance matrix and its derivative with respect to parameters
GauPro_kernel_beta$C_dC_dparams(params = NULL, X, nug)
paramsKernel parameters
Xmatrix of points in rows
nugValue of nugget
s2_from_params()
Get s2 from params vector
GauPro_kernel_beta$s2_from_params(params, s2_est = self$s2_est)
paramsparameter vector
s2_estIs s2 being estimated?
clone()
The objects of this class are cloneable with this method.
GauPro_kernel_beta$clone(deep = FALSE)
deepWhether to make a deep clone.
#k1 <- Matern52$new(beta=0)#k1 <- Matern52$new(beta=0)
Class providing object with methods for fitting a GP model. Allows for different kernel and trend functions to be used. The object is an R6 object with many methods that can be called.
'gpkm()' is equivalent to 'GauPro_kernel_model$new()', but is easier to type and gives parameter autocomplete suggestions.
R6Class object.
Object of R6Class with methods for fitting GP model.
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 = 0,
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.
track_optimShould it track the parameters evaluated while optimizing?
track_optim_inputsIf track_optim is TRUE, this will keep a list of parameters evaluated. View them with plot_track_optim.
track_optim_devIf track_optim is TRUE, this will keep a vector of the deviance values calculated while optimizing parameters. View them with plot_track_optim.
formulaFormula
convert_formula_dataList for storing data to convert data using the formula
new()
Create kernel_model object
GauPro_kernel_model$new( X, Z, kernel, trend, verbose = 0, useC = TRUE, useGrad = TRUE, parallel = FALSE, parallel_cores = "detect", nug = 1e-06, nug.min = 1e-08, nug.max = 100, nug.est = TRUE, param.est = TRUE, restarts = 0, normalize = FALSE, optimizer = "L-BFGS-B", track_optim = FALSE, formula, data, ... )
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.
track_optimShould it track the parameters evaluated while optimizing?
formulaFormula for the data if giving in a data frame.
dataData frame of data. Use in conjunction with formula.
...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, mean_dist = FALSE, return_df = TRUE )
XXpoints to predict at
se.fitShould standard error be returned?
covmatShould covariance matrix be returned?
split_speedShould the matrix be split for faster predictions?
mean_distShould the error be for the distribution of the mean?
return_dfWhen returning se.fit, should it be returned in a data frame? Otherwise it will be a list, which is faster.
pred()
Predict for a matrix of points
GauPro_kernel_model$pred( XX, se.fit = F, covmat = F, split_speed = F, mean_dist = FALSE, return_df = TRUE )
XXpoints to predict at
se.fitShould standard error be returned?
covmatShould covariance matrix be returned?
split_speedShould the matrix be split for faster predictions?
mean_distShould the error be for the distribution of the mean?
return_dfWhen returning se.fit, should it be returned in a data frame? Otherwise it will be a list, which is faster.
pred_one_matrix()
Predict for a matrix of points
GauPro_kernel_model$pred_one_matrix( XX, se.fit = F, covmat = F, return_df = FALSE, mean_dist = 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? Otherwise it will be a list, which is faster.
mean_distShould the error be for the distribution of the mean?
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
plot()
Plot the object
GauPro_kernel_model$plot(...)
...Parameters passed to cool1Dplot(), plot2D(), or plotmarginal()
cool1Dplot()
Make cool 1D plot
GauPro_kernel_model$cool1Dplot( n2 = 20, nn = 201, col2 = "green", xlab = "x", ylab = "y", xmin = NULL, xmax = NULL, ymin = NULL, ymax = NULL, gg = TRUE )
n2Number of things to plot
nnNumber of things to plot
col2color
xlabx label
ylaby label
xminxmin
xmaxxmax
yminymin
ymaxymax
ggShould ggplot2 be used to make plot?
plot1D()
Make 1D plot
GauPro_kernel_model$plot1D( n2 = 20, nn = 201, col2 = 2, col3 = 3, xlab = "x", ylab = "y", xmin = NULL, xmax = NULL, ymin = NULL, ymax = NULL, gg = TRUE )
n2Number of things to plot
nnNumber of things to plot
col2Color of the prediction interval
col3Color of the interval for the mean
xlabx label
ylaby label
xminxmin
xmaxxmax
yminymin
ymaxymax
ggShould ggplot2 be used to make plot?
plot2D()
Make 2D plot
GauPro_kernel_model$plot2D(se = FALSE, mean = TRUE, horizontal = TRUE, n = 50)
seShould the standard error of prediction be plotted?
meanShould the mean be plotted?
horizontalIf plotting mean and se, should they be next to each other?
nNumber of points along each dimension
plotmarginal()
Plot marginal. For each input, hold all others at a constant value and adjust it along it's range to see how the prediction changes.
GauPro_kernel_model$plotmarginal(npt = 5, ncol = NULL)
nptNumber of lines to make. Each line represents changing a single variable while holding the others at the same values.
ncolNumber of columnsfor the plot
plotmarginalrandom()
Plot marginal prediction for random sample of inputs
GauPro_kernel_model$plotmarginalrandom(npt = 100, ncol = NULL)
nptNumber of random points to evaluate
ncolNumber of columns in the plot
plotkernel()
Plot the kernel
GauPro_kernel_model$plotkernel(X = self$X)
XX matrix for kernel plot
plotLOO()
Plot leave one out predictions for design points
GauPro_kernel_model$plotLOO()
plot_track_optim()
If track_optim, this will plot the parameters in the order they were evaluated.
GauPro_kernel_model$plot_track_optim(minindex = NULL)
minindexMinimum index to plot.
loglikelihood()
Calculate loglikelihood of Z given parameters
GauPro_kernel_model$loglikelihood( mu = self$mu_hatX, s2 = self$s2_hat, Z = self$Z )
muMean parameters
s2Variance parameter
ZZ values
AIC()
AIC (Akaike information criterion)
GauPro_kernel_model$AIC()
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 = self$restarts, n0 = 5 * self$D, param_update = T, nug.update = self$nug.est, parallel = self$parallel, parallel_cores = self$parallel_cores )
restartsNumber of restarts to do
n0This many starting parameters are chosen and evaluated. The best ones are used as the starting points for optimization.
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. The deviance is -2 times the loglikelihood, excluding the constant term.
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?
gradpredvar()
Calculate gradient of the predictive variance
GauPro_kernel_model$gradpredvar(XX)
XXpoints to calculate at
sample()
Sample at rows of XX
GauPro_kernel_model$sample(XX, n = 1)
XXInput matrix
nNumber of samples
optimize_fn()
Optimize any function of the GP prediction over the valid input space. If there are inputs that should only be optimized over a discrete set of values, specify 'mopar' for all parameters. Factor inputs will be handled automatically.
GauPro_kernel_model$optimize_fn( fn = NULL, lower = apply(self$X, 2, min), upper = apply(self$X, 2, max), n0 = 100, minimize = FALSE, fn_args = NULL, gr = NULL, fngr = NULL, mopar = NULL, groupeval = FALSE )
fnFunction to optimize
lowerLower bounds to search within
upperUpper bounds to search within
n0Number of points to evaluate in initial stage
minimizeAre you trying to minimize the output?
fn_argsArguments to pass to the function fn.
grGradient of function to optimize.
fngrFunction that returns list with names elements "fn" for the function value and "gr" for the gradient. Useful when it is slow to evaluate and fn/gr would duplicate calculations if done separately.
moparList of parameters using mixopt
groupevalCan a matrix of points be evaluated? Otherwise just a single point at a time.
EI()
Calculate expected improvement
GauPro_kernel_model$EI(x, minimize = FALSE, eps = 0, return_grad = FALSE, ...)
xVector to calculate EI of, or matrix for whose rows it should be calculated
minimizeAre you trying to minimize the output?
epsExploration parameter
return_gradShould the gradient be returned?
...Additional args
maxEI()
Find the point that maximizes the expected improvement. If there are inputs that should only be optimized over a discrete set of values, specify 'mopar' for all parameters.
GauPro_kernel_model$maxEI( lower = apply(self$X, 2, min), upper = apply(self$X, 2, max), n0 = 100, minimize = FALSE, eps = 0, dontconvertback = FALSE, EItype = "corrected", mopar = NULL, usegrad = FALSE )
lowerLower bounds to search within
upperUpper bounds to search within
n0Number of points to evaluate in initial stage
minimizeAre you trying to minimize the output?
epsExploration parameter
dontconvertbackIf data was given in with a formula, should it converted back to the original scale?
EItypeType of EI to calculate. One of "EI", "Augmented", or "Corrected"
moparList of parameters using mixopt
usegradShould the gradient be used when optimizing? Can make it faster.
maxqEI()
Find the multiple points that maximize the expected improvement. Currently only implements the constant liar method.
GauPro_kernel_model$maxqEI( npoints, method = "pred", lower = apply(self$X, 2, min), upper = apply(self$X, 2, max), n0 = 100, minimize = FALSE, eps = 0, EItype = "corrected", dontconvertback = FALSE, mopar = NULL )
npointsNumber of points to add
methodMethod to use for setting the output value for the points chosen as a placeholder. Can be one of: "CL" for constant liar, which uses the best value seen yet; or "pred", which uses the predicted value, also called the Believer method in literature.
lowerLower bounds to search within
upperUpper bounds to search within
n0Number of points to evaluate in initial stage
minimizeAre you trying to minimize the output?
epsExploration parameter
EItypeType of EI to calculate. One of "EI", "Augmented", or "Corrected"
dontconvertbackIf data was given in with a formula, should it converted back to the original scale?
moparList of parameters using mixopt
KG()
Calculate Knowledge Gradient
GauPro_kernel_model$KG(x, minimize = FALSE, eps = 0, current_extreme = NULL)
xPoint to calculate at
minimizeIs the objective to minimize?
epsExploration parameter
current_extremeUsed for recursive solving
AugmentedEI()
Calculated Augmented EI
GauPro_kernel_model$AugmentedEI( x, minimize = FALSE, eps = 0, return_grad = F, ... )
xVector to calculate EI of, or matrix for whose rows it should be calculated
minimizeAre you trying to minimize the output?
epsExploration parameter
return_gradShould the gradient be returned?
...Additional args
fThe reference max, user shouldn't change this.
CorrectedEI()
Calculated Augmented EI
GauPro_kernel_model$CorrectedEI( x, minimize = FALSE, eps = 0, return_grad = F, ... )
xVector to calculate EI of, or matrix for whose rows it should be calculated
minimizeAre you trying to minimize the output?
epsExploration parameter
return_gradShould the gradient be returned?
...Additional args
importance()
Feature importance
GauPro_kernel_model$importance(plot = TRUE, print_bars = TRUE)
plotShould the plot be made?
print_barsShould the importances be printed as bars?
print()
Print this object
GauPro_kernel_model$print()
summary()
Summary
GauPro_kernel_model$summary(...)
...Additional arguments
clone()
The objects of this class are cloneable with this method.
GauPro_kernel_model$clone(deep = FALSE)
deepWhether to make a deep clone.
https://scikit-learn.org/stable/modules/permutation_importance.html#id2
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="gauss") gp$predict(.454) gp$plot1D() gp$cool1Dplot() n <- 200 d <- 7 x <- matrix(runif(n*d), ncol=d) f <- function(x) {x[1]*x[2] + cos(x[3]) + x[4]^2} y <- apply(x, 1, f) gp <- GauPro_kernel_model$new(X=x, Z=y, kernel=Gaussian)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="gauss") gp$predict(.454) gp$plot1D() gp$cool1Dplot() n <- 200 d <- 7 x <- matrix(runif(n*d), ncol=d) f <- function(x) {x[1]*x[2] + cos(x[3]) + x[4]^2} y <- apply(x, 1, f) gp <- GauPro_kernel_model$new(X=x, Z=y, kernel=Gaussian)
Corr Gauss GP using inherited optim
Corr Gauss GP using inherited optim
R6Class object.
Object of R6Class with methods for fitting GP model.
GauPro::GauPro -> GauPro_kernel_model_LOO
tmodA second GP model for the t-values of leave-one-out predictions
use_LOOShould the leave-one-out error corrections be used?
GauPro::GauPro$AIC()GauPro::GauPro$AugmentedEI()GauPro::GauPro$CorrectedEI()GauPro::GauPro$EI()GauPro::GauPro$KG()GauPro::GauPro$cool1Dplot()GauPro::GauPro$deviance()GauPro::GauPro$deviance_fngr()GauPro::GauPro$deviance_grad()GauPro::GauPro$fit()GauPro::GauPro$get_optim_functions()GauPro::GauPro$grad()GauPro::GauPro$grad_dist()GauPro::GauPro$grad_norm()GauPro::GauPro$grad_norm2_dist()GauPro::GauPro$grad_norm2_mean()GauPro::GauPro$grad_norm2_sample()GauPro::GauPro$grad_sample()GauPro::GauPro$gradpredvar()GauPro::GauPro$hessian()GauPro::GauPro$importance()GauPro::GauPro$loglikelihood()GauPro::GauPro$maxEI()GauPro::GauPro$maxqEI()GauPro::GauPro$optim()GauPro::GauPro$optimRestart()GauPro::GauPro$optimize_fn()GauPro::GauPro$param_optim_lower()GauPro::GauPro$param_optim_start()GauPro::GauPro$param_optim_start0()GauPro::GauPro$param_optim_start_mat()GauPro::GauPro$param_optim_upper()GauPro::GauPro$plot()GauPro::GauPro$plot1D()GauPro::GauPro$plot2D()GauPro::GauPro$plotLOO()GauPro::GauPro$plot_track_optim()GauPro::GauPro$plotkernel()GauPro::GauPro$plotmarginal()GauPro::GauPro$plotmarginalrandom()GauPro::GauPro$pred()GauPro::GauPro$pred_LOO()GauPro::GauPro$pred_mean()GauPro::GauPro$pred_meanC()GauPro::GauPro$pred_var()GauPro::GauPro$pred_var_after_adding_points()GauPro::GauPro$pred_var_after_adding_points_sep()GauPro::GauPro$pred_var_reduction()GauPro::GauPro$pred_var_reductions()GauPro::GauPro$predict()GauPro::GauPro$print()GauPro::GauPro$sample()GauPro::GauPro$summary()GauPro::GauPro$update_K_and_estimates()GauPro::GauPro$update_corrparams()GauPro::GauPro$update_data()GauPro::GauPro$update_fast()GauPro::GauPro$update_nugget()GauPro::GauPro$update_params()new()
Create a kernel model that uses a leave-one-out GP model to fix the standard error predictions.
GauPro_kernel_model_LOO$new(..., LOO_kernel, LOO_options = list())
...Passed to super$initialize.
LOO_kernelThe kernel that should be used for the leave-one-out model. Shouldn't be too smooth.
LOO_optionsOptions passed to the leave-one-out model.
update()
Update the model. Should only give in (Xnew and Znew) or (Xall and Zall).
GauPro_kernel_model_LOO$update( Xnew = NULL, Znew = NULL, Xall = NULL, Zall = NULL, restarts = 5, 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?
pred_one_matrix()
Predict for a matrix of points
GauPro_kernel_model_LOO$pred_one_matrix( XX, se.fit = F, covmat = F, return_df = FALSE, mean_dist = 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?
mean_distShould mean distribution be returned?
clone()
The objects of this class are cloneable with this method.
GauPro_kernel_model_LOO$clone(deep = FALSE)
deepWhether to make a deep clone.
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_LOO$new(X=x, Z=y, kernel=Gaussian) y <- x^2 * sin(2*pi*x) + rnorm(n,0,1e-3) gp <- GauPro_kernel_model_LOO$new(X=x, Z=y, kernel=Matern52) y <- exp(-1.4*x)*cos(7*pi*x/2) gp <- GauPro_kernel_model_LOO$new(X=x, Z=y, kernel=Matern52)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_LOO$new(X=x, Z=y, kernel=Gaussian) y <- x^2 * sin(2*pi*x) + rnorm(n,0,1e-3) gp <- GauPro_kernel_model_LOO$new(X=x, Z=y, kernel=Matern52) y <- exp(-1.4*x)*cos(7*pi*x/2) gp <- GauPro_kernel_model_LOO$new(X=x, Z=y, kernel=Matern52)
Trend R6 class
Trend R6 class
R6Class object.
Object of R6Class with methods for fitting GP model.
DNumber of input dimensions of data
clone()
The objects of this class are cloneable with this method.
GauPro_trend$clone(deep = FALSE)
deepWhether to make a deep clone.
#k <- GauPro_trend$new()#k <- GauPro_trend$new()
Gaussian Kernel R6 class
Gaussian Kernel R6 class
k_Gaussian( beta, s2 = 1, D, beta_lower = -8, beta_upper = 6, beta_est = TRUE, s2_lower = 1e-08, s2_upper = 1e+08, s2_est = TRUE, useC = TRUE, isotropic = FALSE )k_Gaussian( beta, s2 = 1, D, beta_lower = -8, beta_upper = 6, beta_est = TRUE, s2_lower = 1e-08, s2_upper = 1e+08, s2_est = TRUE, useC = TRUE, isotropic = FALSE )
beta |
Initial beta value |
s2 |
Initial variance |
D |
Number of input dimensions of data |
beta_lower |
Lower bound for beta |
beta_upper |
Upper bound for beta |
beta_est |
Should beta be estimated? |
s2_lower |
Lower bound for s2 |
s2_upper |
Upper bound for s2 |
s2_est |
Should s2 be estimated? |
useC |
Should C code used? Much faster. |
isotropic |
If isotropic then a single beta/theta is used for all dimensions. If not (anisotropic) then a separate beta/beta is used for each dimension. |
R6Class object.
Object of R6Class with methods for fitting GP model.
GauPro::GauPro_kernel -> GauPro::GauPro_kernel_beta -> GauPro_kernel_Gaussian
GauPro::GauPro_kernel$plot()GauPro::GauPro_kernel_beta$initialize()GauPro::GauPro_kernel_beta$param_optim_lower()GauPro::GauPro_kernel_beta$param_optim_start()GauPro::GauPro_kernel_beta$param_optim_start0()GauPro::GauPro_kernel_beta$param_optim_upper()GauPro::GauPro_kernel_beta$s2_from_params()GauPro::GauPro_kernel_beta$set_params_from_optim()k()
Calculate covariance between two points
Gaussian$k(x, y = NULL, beta = self$beta, s2 = self$s2, params = NULL)
xvector.
yvector, optional. If excluded, find correlation of x with itself.
betaCorrelation parameters.
s2Variance parameter.
paramsparameters to use instead of beta and s2.
kone()
Find covariance of two points
Gaussian$kone(x, y, beta, theta, s2)
xvector
yvector
betacorrelation parameters on log scale
thetacorrelation parameters on regular scale
s2Variance parameter
dC_dparams()
Derivative of covariance with respect to parameters
Gaussian$dC_dparams(params = NULL, X, C_nonug, C, nug)
paramsKernel parameters
Xmatrix of points in rows
C_nonugCovariance without nugget added to diagonal
CCovariance with nugget
nugValue of nugget
C_dC_dparams()
Calculate covariance matrix and its derivative with respect to parameters
Gaussian$C_dC_dparams(params = NULL, X, nug)
paramsKernel parameters
Xmatrix of points in rows
nugValue of nugget
dC_dx()
Derivative of covariance with respect to X
Gaussian$dC_dx(XX, X, theta, beta = self$beta, s2 = self$s2)
XXmatrix of points
Xmatrix of points to take derivative with respect to
thetaCorrelation parameters
betalog of theta
s2Variance parameter
d2C_dx2()
Second derivative of covariance with respect to X
Gaussian$d2C_dx2(XX, X, theta, beta = self$beta, s2 = self$s2)
XXmatrix of points
Xmatrix of points to take derivative with respect to
thetaCorrelation parameters
betalog of theta
s2Variance parameter
d2C_dudv()
Second derivative of covariance with respect to X and XX each once.
Gaussian$d2C_dudv(XX, X, theta, beta = self$beta, s2 = self$s2)
XXmatrix of points
Xmatrix of points to take derivative with respect to
thetaCorrelation parameters
betalog of theta
s2Variance parameter
d2C_dudv_ueqvrows()
Second derivative of covariance with respect to X and XX when they equal the same value
Gaussian$d2C_dudv_ueqvrows(XX, theta, beta = self$beta, s2 = self$s2)
XXmatrix of points
thetaCorrelation parameters
betalog of theta
s2Variance parameter
print()
Print this object
Gaussian$print()
clone()
The objects of this class are cloneable with this method.
Gaussian$clone(deep = FALSE)
deepWhether to make a deep clone.
k1 <- Gaussian$new(beta=0) plot(k1) k1 <- Gaussian$new(beta=c(0,-1, 1)) plot(k1) 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) gp$plot1D() gp$cool1Dplot()k1 <- Gaussian$new(beta=0) plot(k1) k1 <- Gaussian$new(beta=c(0,-1, 1)) plot(k1) 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) gp$plot1D() gp$cool1Dplot()
Calculate the Gaussian deviance in C
Gaussian_devianceC(theta, nug, X, Z)Gaussian_devianceC(theta, nug, X, Z)
theta |
Theta vector |
nug |
Nugget |
X |
Matrix X |
Z |
Matrix Z |
Correlation matrix
Gaussian_devianceC(c(1,1), 1e-8, matrix(c(1,0,0,1),2,2), matrix(c(1,0),2,1))Gaussian_devianceC(c(1,1), 1e-8, matrix(c(1,0,0,1),2,2), matrix(c(1,0),2,1))
Calculate Hessian for a GP with Gaussian correlation
Gaussian_hessianC(XX, X, Z, Kinv, mu_hat, theta)Gaussian_hessianC(XX, X, Z, Kinv, mu_hat, theta)
XX |
The vector at which to calculate the Hessian |
X |
The input points |
Z |
The output values |
Kinv |
The inverse of the correlation matrix |
mu_hat |
Estimate of mu |
theta |
Theta parameters for the correlation |
Matrix, the Hessian at XX
set.seed(0) n <- 40 x <- matrix(runif(n*2), ncol=2) f1 <- function(a) {sin(2*pi*a[1]) + sin(6*pi*a[2])} y <- apply(x,1,f1) + rnorm(n,0,.01) gp <- GauPro(x,y, verbose=2, parallel=FALSE);gp$theta gp$hessian(c(.2,.75), useC=TRUE) # Should be -38.3, -5.96, -5.96, -389.4 as 2x2 matrixset.seed(0) n <- 40 x <- matrix(runif(n*2), ncol=2) f1 <- function(a) {sin(2*pi*a[1]) + sin(6*pi*a[2])} y <- apply(x,1,f1) + rnorm(n,0,.01) gp <- GauPro(x,y, verbose=2, parallel=FALSE);gp$theta gp$hessian(c(.2,.75), useC=TRUE) # Should be -38.3, -5.96, -5.96, -389.4 as 2x2 matrix
Gaussian hessian in C
Gaussian_hessianCC(XX, X, Z, Kinv, mu_hat, theta)Gaussian_hessianCC(XX, X, Z, Kinv, mu_hat, theta)
XX |
point to find Hessian at |
X |
matrix of data points |
Z |
matrix of output |
Kinv |
inverse of correlation matrix |
mu_hat |
mean estimate |
theta |
correlation parameters |
Hessian matrix
Calculate Hessian for a GP with Gaussian correlation
Gaussian_hessianR(XX, X, Z, Kinv, mu_hat, theta)Gaussian_hessianR(XX, X, Z, Kinv, mu_hat, theta)
XX |
The vector at which to calculate the Hessian |
X |
The input points |
Z |
The output values |
Kinv |
The inverse of the correlation matrix |
mu_hat |
Estimate of mu |
theta |
Theta parameters for the correlation |
Matrix, the Hessian at XX
set.seed(0) n <- 40 x <- matrix(runif(n*2), ncol=2) f1 <- function(a) {sin(2*pi*a[1]) + sin(6*pi*a[2])} y <- apply(x,1,f1) + rnorm(n,0,.01) gp <- GauPro(x,y, verbose=2, parallel=FALSE);gp$theta gp$hessian(c(.2,.75), useC=FALSE) # Should be -38.3, -5.96, -5.96, -389.4 as 2x2 matrixset.seed(0) n <- 40 x <- matrix(runif(n*2), ncol=2) f1 <- function(a) {sin(2*pi*a[1]) + sin(6*pi*a[2])} y <- apply(x,1,f1) + rnorm(n,0,.01) gp <- GauPro(x,y, verbose=2, parallel=FALSE);gp$theta gp$hessian(c(.2,.75), useC=FALSE) # Should be -38.3, -5.96, -5.96, -389.4 as 2x2 matrix
Gower factor Kernel R6 class
Gower factor Kernel R6 class
k_GowerFactorKernel( s2 = 1, D, nlevels, xindex, p_lower = 0, p_upper = 0.9, p_est = TRUE, s2_lower = 1e-08, s2_upper = 1e+08, s2_est = TRUE, p, useC = TRUE, offdiagequal = 1 - 1e-06 )k_GowerFactorKernel( s2 = 1, D, nlevels, xindex, p_lower = 0, p_upper = 0.9, p_est = TRUE, s2_lower = 1e-08, s2_upper = 1e+08, s2_est = TRUE, p, useC = TRUE, offdiagequal = 1 - 1e-06 )
s2 |
Initial variance |
D |
Number of input dimensions of data |
nlevels |
Number of levels for the factor |
xindex |
Index of the factor (which column of X) |
p_lower |
Lower bound for p |
p_upper |
Upper bound for p |
p_est |
Should p be estimated? |
s2_lower |
Lower bound for s2 |
s2_upper |
Upper bound for s2 |
s2_est |
Should s2 be estimated? |
p |
Vector of correlations |
useC |
Should C code used? Not implemented for FactorKernel yet. |
offdiagequal |
What should offdiagonal values be set to when the indices are the same? Use to avoid decomposition errors, similar to adding a nugget. |
R6Class object.
For a factor that has been converted to its indices. Each factor will need a separate kernel.
Object of R6Class with methods for fitting GP model.
GauPro::GauPro_kernel -> GauPro_kernel_GowerFactorKernel
pParameter for correlation
p_estShould p be estimated?
p_lowerLower bound of p
p_upperUpper bound of p
s2variance
s2_estIs s2 estimated?
logs2Log of s2
logs2_lowerLower bound of logs2
logs2_upperUpper bound of logs2
xindexIndex of the factor (which column of X)
nlevelsNumber of levels for the factor
offdiagequalWhat should offdiagonal values be set to when the indices are the same? Use to avoid decomposition errors, similar to adding a nugget.
new()
Initialize kernel object
GowerFactorKernel$new( s2 = 1, D, nlevels, xindex, p_lower = 0, p_upper = 0.9, p_est = TRUE, s2_lower = 1e-08, s2_upper = 1e+08, s2_est = TRUE, p, useC = TRUE, offdiagequal = 1 - 1e-06 )
s2Initial variance
DNumber of input dimensions of data
nlevelsNumber of levels for the factor
xindexIndex of the factor (which column of X)
p_lowerLower bound for p
p_upperUpper bound for p
p_estShould p be estimated?
s2_lowerLower bound for s2
s2_upperUpper bound for s2
s2_estShould s2 be estimated?
pVector of correlations
useCShould C code used? Not implemented for FactorKernel yet.
offdiagequalWhat should offdiagonal values be set to when the indices are the same? Use to avoid decomposition errors, similar to adding a nugget.
k()
Calculate covariance between two points
GowerFactorKernel$k(x, y = NULL, p = self$p, s2 = self$s2, params = NULL)
xvector.
yvector, optional. If excluded, find correlation of x with itself.
pCorrelation parameters.
s2Variance parameter.
paramsparameters to use instead of beta and s2.
kone()
Find covariance of two points
GowerFactorKernel$kone( x, y, p, s2, isdiag = TRUE, offdiagequal = self$offdiagequal )
xvector
yvector
pcorrelation parameters on regular scale
s2Variance parameter
isdiagIs this on the diagonal of the covariance?
offdiagequalWhat should offdiagonal values be set to when the indices are the same? Use to avoid decomposition errors, similar to adding a nugget.
dC_dparams()
Derivative of covariance with respect to parameters
GowerFactorKernel$dC_dparams(params = NULL, X, C_nonug, C, nug)
paramsKernel parameters
Xmatrix of points in rows
C_nonugCovariance without nugget added to diagonal
CCovariance with nugget
nugValue of nugget
C_dC_dparams()
Calculate covariance matrix and its derivative with respect to parameters
GowerFactorKernel$C_dC_dparams(params = NULL, X, nug)
paramsKernel parameters
Xmatrix of points in rows
nugValue of nugget
dC_dx()
Derivative of covariance with respect to X
GowerFactorKernel$dC_dx(XX, X, ...)
XXmatrix of points
Xmatrix of points to take derivative with respect to
...Additional args, not used
param_optim_start()
Starting point for parameters for optimization
GowerFactorKernel$param_optim_start( jitter = F, y, p_est = self$p_est, s2_est = self$s2_est )
jitterShould there be a jitter?
yOutput
p_estIs p being estimated?
s2_estIs s2 being estimated?
alpha_estIs alpha being estimated?
param_optim_start0()
Starting point for parameters for optimization
GowerFactorKernel$param_optim_start0( jitter = F, y, p_est = self$p_est, s2_est = self$s2_est )
jitterShould there be a jitter?
yOutput
p_estIs p being estimated?
s2_estIs s2 being estimated?
alpha_estIs alpha being estimated?
param_optim_lower()
Lower bounds of parameters for optimization
GowerFactorKernel$param_optim_lower(p_est = self$p_est, s2_est = self$s2_est)
p_estIs p being estimated?
s2_estIs s2 being estimated?
alpha_estIs alpha being estimated?
param_optim_upper()
Upper bounds of parameters for optimization
GowerFactorKernel$param_optim_upper(p_est = self$p_est, s2_est = self$s2_est)
p_estIs p being estimated?
s2_estIs s2 being estimated?
alpha_estIs alpha being estimated?
set_params_from_optim()
Set parameters from optimization output
GowerFactorKernel$set_params_from_optim( optim_out, p_est = self$p_est, s2_est = self$s2_est )
optim_outOutput from optimization
p_estIs p being estimated?
s2_estIs s2 being estimated?
alpha_estIs alpha being estimated?
s2_from_params()
Get s2 from params vector
GowerFactorKernel$s2_from_params(params, s2_est = self$s2_est)
paramsparameter vector
s2_estIs s2 being estimated?
print()
Print this object
GowerFactorKernel$print()
clone()
The objects of this class are cloneable with this method.
GowerFactorKernel$clone(deep = FALSE)
deepWhether to make a deep clone.
kk <- GowerFactorKernel$new(D=1, nlevels=5, xindex=1, p=.2) kmat <- outer(1:5, 1:5, Vectorize(kk$k)) kmat kk$plot() # 2D, Gaussian on 1D, index on 2nd dim if (requireNamespace("dplyr", quietly=TRUE)) { library(dplyr) n <- 20 X <- cbind(matrix(runif(n,2,6), ncol=1), matrix(sample(1:2, size=n, replace=TRUE), ncol=1)) X <- rbind(X, c(3.3,3)) n <- nrow(X) Z <- X[,1] - (X[,2]-1.8)^2 + rnorm(n,0,.1) tibble(X=X, Z) %>% arrange(X,Z) k2a <- IgnoreIndsKernel$new(k=Gaussian$new(D=1), ignoreinds = 2) k2b <- GowerFactorKernel$new(D=2, nlevels=3, xind=2) k2 <- k2a * k2b k2b$p_upper <- .65*k2b$p_upper gp <- GauPro_kernel_model$new(X=X, Z=Z, kernel = k2, verbose = 5, nug.min=1e-2, restarts=0) gp$kernel$k1$kernel$beta gp$kernel$k2$p gp$kernel$k(x = gp$X) tibble(X=X, Z=Z, pred=gp$predict(X)) %>% arrange(X, Z) tibble(X=X[,2], Z) %>% group_by(X) %>% summarize(n=n(), mean(Z)) curve(gp$pred(cbind(matrix(x,ncol=1),1)),2,6, ylim=c(min(Z), max(Z))) points(X[X[,2]==1,1], Z[X[,2]==1]) curve(gp$pred(cbind(matrix(x,ncol=1),2)), add=TRUE, col=2) points(X[X[,2]==2,1], Z[X[,2]==2], col=2) curve(gp$pred(cbind(matrix(x,ncol=1),3)), add=TRUE, col=3) points(X[X[,2]==3,1], Z[X[,2]==3], col=3) legend(legend=1:3, fill=1:3, x="topleft") # See which points affect (5.5, 3 themost) data.frame(X, cov=gp$kernel$k(X, c(5.5,3))) %>% arrange(-cov) plot(k2b) }kk <- GowerFactorKernel$new(D=1, nlevels=5, xindex=1, p=.2) kmat <- outer(1:5, 1:5, Vectorize(kk$k)) kmat kk$plot() # 2D, Gaussian on 1D, index on 2nd dim if (requireNamespace("dplyr", quietly=TRUE)) { library(dplyr) n <- 20 X <- cbind(matrix(runif(n,2,6), ncol=1), matrix(sample(1:2, size=n, replace=TRUE), ncol=1)) X <- rbind(X, c(3.3,3)) n <- nrow(X) Z <- X[,1] - (X[,2]-1.8)^2 + rnorm(n,0,.1) tibble(X=X, Z) %>% arrange(X,Z) k2a <- IgnoreIndsKernel$new(k=Gaussian$new(D=1), ignoreinds = 2) k2b <- GowerFactorKernel$new(D=2, nlevels=3, xind=2) k2 <- k2a * k2b k2b$p_upper <- .65*k2b$p_upper gp <- GauPro_kernel_model$new(X=X, Z=Z, kernel = k2, verbose = 5, nug.min=1e-2, restarts=0) gp$kernel$k1$kernel$beta gp$kernel$k2$p gp$kernel$k(x = gp$X) tibble(X=X, Z=Z, pred=gp$predict(X)) %>% arrange(X, Z) tibble(X=X[,2], Z) %>% group_by(X) %>% summarize(n=n(), mean(Z)) curve(gp$pred(cbind(matrix(x,ncol=1),1)),2,6, ylim=c(min(Z), max(Z))) points(X[X[,2]==1,1], Z[X[,2]==1]) curve(gp$pred(cbind(matrix(x,ncol=1),2)), add=TRUE, col=2) points(X[X[,2]==2,1], Z[X[,2]==2], col=2) curve(gp$pred(cbind(matrix(x,ncol=1),3)), add=TRUE, col=3) points(X[X[,2]==3,1], Z[X[,2]==3], col=3) legend(legend=1:3, fill=1:3, x="topleft") # See which points affect (5.5, 3 themost) data.frame(X, cov=gp$kernel$k(X, c(5.5,3))) %>% arrange(-cov) plot(k2b) }
Fits a Gaussian process regression model to data.
An R6 object is returned with many methods.
'gpkm()' is an alias for 'GauPro_kernel_model$new()'. For full documentation, see documentation for 'GauPro_kernel_model'.
Standard methods that work include 'plot()', 'summary()', and 'predict()'.
gpkm( X, Z, kernel, trend, verbose = 0, useC = TRUE, useGrad = TRUE, parallel = FALSE, parallel_cores = "detect", nug = 1e-06, nug.min = 1e-08, nug.max = 100, nug.est = TRUE, param.est = TRUE, restarts = 0, normalize = FALSE, optimizer = "L-BFGS-B", track_optim = FALSE, formula, data, ... )gpkm( X, Z, kernel, trend, verbose = 0, useC = TRUE, useGrad = TRUE, parallel = FALSE, parallel_cores = "detect", nug = 1e-06, nug.min = 1e-08, nug.max = 100, nug.est = TRUE, param.est = TRUE, restarts = 0, normalize = FALSE, optimizer = "L-BFGS-B", track_optim = FALSE, formula, data, ... )
X |
Matrix whose rows are the input points |
Z |
Output points corresponding to X |
kernel |
The kernel to use. E.g., Gaussian$new(). |
trend |
Trend to use. E.g., trend_constant$new(). |
verbose |
Amount of stuff to print. 0 is little, 2 is a lot. |
useC |
Should C code be used when possible? Should be faster. |
useGrad |
Should the gradient be used? |
parallel |
Should code be run in parallel? Make optimization faster but uses more computer resources. |
parallel_cores |
When using parallel, how many cores should be used? |
nug |
Value for the nugget. The starting value if estimating it. |
nug.min |
Minimum allowable value for the nugget. |
nug.max |
Maximum allowable value for the nugget. |
nug.est |
Should the nugget be estimated? |
param.est |
Should the kernel parameters be estimated? |
restarts |
How many optimization restarts should be used when estimating parameters? |
normalize |
Should the data be normalized? |
optimizer |
What algorithm should be used to optimize the parameters. |
track_optim |
Should it track the parameters evaluated while optimizing? |
formula |
Formula for the data if giving in a data frame. |
data |
Data frame of data. Use in conjunction with formula. |
... |
Not used |
The default kernel is a Matern 5/2 kernel, but factor/character inputs will be given factor kernels.
Calculate gradfunc in optimization to speed up. NEEDS TO APERM dC_dparams Doesn't need to be exported, should only be useful in functions.
gradfuncarray(dC_dparams, Cinv, Cinv_yminusmu)gradfuncarray(dC_dparams, Cinv, Cinv_yminusmu)
dC_dparams |
Derivative matrix for covariance function wrt kernel parameters |
Cinv |
Inverse of covariance matrix |
Cinv_yminusmu |
Vector that is the inverse of C times y minus the mean. |
Vector, one value for each parameter
gradfuncarray(array(dim=c(2,4,4), data=rnorm(32)), matrix(rnorm(16),4,4), rnorm(4))gradfuncarray(array(dim=c(2,4,4), data=rnorm(32)), matrix(rnorm(16),4,4), rnorm(4))
Calculate gradfunc in optimization to speed up. NEEDS TO APERM dC_dparams Doesn't need to be exported, should only be useful in functions.
gradfuncarrayR(dC_dparams, Cinv, Cinv_yminusmu)gradfuncarrayR(dC_dparams, Cinv, Cinv_yminusmu)
dC_dparams |
Derivative matrix for covariance function wrt kernel parameters |
Cinv |
Inverse of covariance matrix |
Cinv_yminusmu |
Vector that is the inverse of C times y minus the mean. |
Vector, one value for each parameter
a1 <- array(dim=c(2,4,4), data=rnorm(32)) a2 <- matrix(rnorm(16),4,4) a3 <- rnorm(4) #gradfuncarray(a1, a2, a3) #gradfuncarrayR(a1, a2, a3)a1 <- array(dim=c(2,4,4), data=rnorm(32)) a2 <- matrix(rnorm(16),4,4) a3 <- rnorm(4) #gradfuncarray(a1, a2, a3) #gradfuncarrayR(a1, a2, a3)
Kernel R6 class
Kernel R6 class
k_IgnoreIndsKernel(k, ignoreinds, useC = TRUE)k_IgnoreIndsKernel(k, ignoreinds, useC = TRUE)
k |
Kernel to use on the non-ignored indices |
ignoreinds |
Indices of columns of X to ignore. |
useC |
Should C code used? Not implemented for IgnoreInds. |
R6Class object.
Object of R6Class with methods for fitting GP model.
GauPro::GauPro_kernel -> GauPro_kernel_IgnoreInds
DNumber of input dimensions of data
kernelKernel to use on indices that aren't ignored
ignoreindsIndices to ignore. For a matrix X, these are the columns to ignore. For example, when those dimensions will be given a different kernel, such as for factors.
s2_estIs s2 being estimated?
s2Value of s2 (variance)
new()
Initialize kernel object
IgnoreIndsKernel$new(k, ignoreinds, useC = TRUE)
kKernel to use on the non-ignored indices
ignoreindsIndices of columns of X to ignore.
useCShould C code used? Not implemented for IgnoreInds.
k()
Calculate covariance between two points
IgnoreIndsKernel$k(x, y = NULL, ...)
xvector.
yvector, optional. If excluded, find correlation of x with itself.
...Passed to kernel
kone()
Find covariance of two points
IgnoreIndsKernel$kone(x, y, ...)
xvector
yvector
...Passed to kernel
dC_dparams()
Derivative of covariance with respect to parameters
IgnoreIndsKernel$dC_dparams(params = NULL, X, ...)
paramsKernel parameters
Xmatrix of points in rows
...Passed to kernel
C_dC_dparams()
Calculate covariance matrix and its derivative with respect to parameters
IgnoreIndsKernel$C_dC_dparams(params = NULL, X, nug)
paramsKernel parameters
Xmatrix of points in rows
nugValue of nugget
dC_dx()
Derivative of covariance with respect to X
IgnoreIndsKernel$dC_dx(XX, X, ...)
XXmatrix of points
Xmatrix of points to take derivative with respect to
...Additional arguments passed on to the kernel
param_optim_start()
Starting point for parameters for optimization
IgnoreIndsKernel$param_optim_start(...)
...Passed to kernel
param_optim_start0()
Starting point for parameters for optimization
IgnoreIndsKernel$param_optim_start0(...)
...Passed to kernel
param_optim_lower()
Lower bounds of parameters for optimization
IgnoreIndsKernel$param_optim_lower(...)
...Passed to kernel
param_optim_upper()
Upper bounds of parameters for optimization
IgnoreIndsKernel$param_optim_upper(...)
...Passed to kernel
set_params_from_optim()
Set parameters from optimization output
IgnoreIndsKernel$set_params_from_optim(...)
...Passed to kernel
s2_from_params()
Get s2 from params vector
IgnoreIndsKernel$s2_from_params(...)
...Passed to kernel
print()
Print this object
IgnoreIndsKernel$print()
clone()
The objects of this class are cloneable with this method.
IgnoreIndsKernel$clone(deep = FALSE)
deepWhether to make a deep clone.
kg <- Gaussian$new(D=3) kig <- GauPro::IgnoreIndsKernel$new(k = Gaussian$new(D=3), ignoreinds = 2) Xtmp <- as.matrix(expand.grid(1:2, 1:2, 1:2)) cbind(Xtmp, kig$k(Xtmp)) cbind(Xtmp, kg$k(Xtmp))kg <- Gaussian$new(D=3) kig <- GauPro::IgnoreIndsKernel$new(k = Gaussian$new(D=3), ignoreinds = 2) Xtmp <- as.matrix(expand.grid(1:2, 1:2, 1:2)) cbind(Xtmp, kig$k(Xtmp)) cbind(Xtmp, kg$k(Xtmp))
Derivative of cubic kernel covariance matrix in C
kernel_cubic_dC(x, theta, C_nonug, s2_est, beta_est, lenparams_D, s2_nug, s2)kernel_cubic_dC(x, theta, C_nonug, s2_est, beta_est, lenparams_D, s2_nug, s2)
x |
Matrix x |
theta |
Theta vector |
C_nonug |
cov mat without nugget |
s2_est |
whether s2 is being estimated |
beta_est |
Whether theta/beta is being estimated |
lenparams_D |
Number of parameters the derivative is being calculated for |
s2_nug |
s2 times the nug |
s2 |
s2 |
Correlation matrix
Derivative of Matern 5/2 kernel covariance matrix in C
kernel_exponential_dC( x, theta, C_nonug, s2_est, beta_est, lenparams_D, s2_nug, s2 )kernel_exponential_dC( x, theta, C_nonug, s2_est, beta_est, lenparams_D, s2_nug, s2 )
x |
Matrix x |
theta |
Theta vector |
C_nonug |
cov mat without nugget |
s2_est |
whether s2 is being estimated |
beta_est |
Whether theta/beta is being estimated |
lenparams_D |
Number of parameters the derivative is being calculated for |
s2_nug |
s2 times the nug |
s2 |
s2 parameter |
Correlation matrix
Derivative of Gaussian kernel covariance matrix in C
kernel_gauss_dC(x, theta, C_nonug, s2_est, beta_est, lenparams_D, s2_nug)kernel_gauss_dC(x, theta, C_nonug, s2_est, beta_est, lenparams_D, s2_nug)
x |
Matrix x |
theta |
Theta vector |
C_nonug |
cov mat without nugget |
s2_est |
whether s2 is being estimated |
beta_est |
Whether theta/beta is being estimated |
lenparams_D |
Number of parameters the derivative is being calculated for |
s2_nug |
s2 times the nug |
Correlation matrix
Derivative of covariance matrix of X with respect to kernel parameters for the Latent Factor Kernel
kernel_latentFactor_dC( x, pf, C_nonug, s2_est, p_est, lenparams_D, s2_nug, latentdim, xindex, nlevels, s2 )kernel_latentFactor_dC( x, pf, C_nonug, s2_est, p_est, lenparams_D, s2_nug, latentdim, xindex, nlevels, s2 )
x |
Matrix x |
pf |
pf vector |
C_nonug |
cov mat without nugget |
s2_est |
whether s2 is being estimated |
p_est |
Whether theta/beta is being estimated |
lenparams_D |
Number of parameters the derivative is being calculated for |
s2_nug |
s2 times the nug |
latentdim |
Number of latent dimensions |
xindex |
Which column of x is the indexing variable |
nlevels |
Number of levels |
s2 |
Value of s2 |
Correlation matrix
Derivative of Matern 5/2 kernel covariance matrix in C
kernel_matern32_dC(x, theta, C_nonug, s2_est, beta_est, lenparams_D, s2_nug)kernel_matern32_dC(x, theta, C_nonug, s2_est, beta_est, lenparams_D, s2_nug)
x |
Matrix x |
theta |
Theta vector |
C_nonug |
cov mat without nugget |
s2_est |
whether s2 is being estimated |
beta_est |
Whether theta/beta is being estimated |
lenparams_D |
Number of parameters the derivative is being calculated for |
s2_nug |
s2 times the nug |
Correlation matrix
Derivative of Matern 5/2 kernel covariance matrix in C
kernel_matern52_dC(x, theta, C_nonug, s2_est, beta_est, lenparams_D, s2_nug)kernel_matern52_dC(x, theta, C_nonug, s2_est, beta_est, lenparams_D, s2_nug)
x |
Matrix x |
theta |
Theta vector |
C_nonug |
cov mat without nugget |
s2_est |
whether s2 is being estimated |
beta_est |
Whether theta/beta is being estimated |
lenparams_D |
Number of parameters the derivative is being calculated for |
s2_nug |
s2 times the nug |
Correlation matrix
Derivative of covariance matrix of X with respect to kernel parameters for the Ordered Factor Kernel
kernel_orderedFactor_dC( x, pf, C_nonug, s2_est, p_est, lenparams_D, s2_nug, xindex, nlevels, s2 )kernel_orderedFactor_dC( x, pf, C_nonug, s2_est, p_est, lenparams_D, s2_nug, xindex, nlevels, s2 )
x |
Matrix x |
pf |
pf vector |
C_nonug |
cov mat without nugget |
s2_est |
whether s2 is being estimated |
p_est |
Whether theta/beta is being estimated |
lenparams_D |
Number of parameters the derivative is being calculated for |
s2_nug |
s2 times the nug |
xindex |
Which column of x is the indexing variable |
nlevels |
Number of levels |
s2 |
Value of s2 |
Correlation matrix
Gaussian Kernel R6 class
Gaussian Kernel R6 class
R6Class object.
Object of R6Class with methods for fitting GP model.
GauPro::GauPro_kernel -> GauPro_kernel_product
k1kernel 1
k2kernel 2
s2Variance
k1plparam length of kernel 1
k2plparam length of kernel 2
s2_estIs s2 being estimated?
new()
Is s2 being estimated?
Length of the parameters of k1
Length of the parameters of k2
Initialize kernel
kernel_product$new(k1, k2, useC = TRUE)
k1Kernel 1
k2Kernel 2
useCShould C code used? Not applicable for kernel product.
k()
Calculate covariance between two points
kernel_product$k(x, y = NULL, params, ...)
xvector.
yvector, optional. If excluded, find correlation of x with itself.
paramsparameters to use instead of beta and s2.
...Not used
param_optim_start()
Starting point for parameters for optimization
kernel_product$param_optim_start(jitter = F, y)
jitterShould there be a jitter?
yOutput
param_optim_start0()
Starting point for parameters for optimization
kernel_product$param_optim_start0(jitter = F, y)
jitterShould there be a jitter?
yOutput
param_optim_lower()
Lower bounds of parameters for optimization
kernel_product$param_optim_lower()
param_optim_upper()
Upper bounds of parameters for optimization
kernel_product$param_optim_upper()
set_params_from_optim()
Set parameters from optimization output
kernel_product$set_params_from_optim(optim_out)
optim_outOutput from optimization
dC_dparams()
Derivative of covariance with respect to parameters
kernel_product$dC_dparams(params = NULL, C, X, C_nonug, nug)
paramsKernel parameters
CCovariance with nugget
Xmatrix of points in rows
C_nonugCovariance without nugget added to diagonal
nugValue of nugget
C_dC_dparams()
Calculate covariance matrix and its derivative with respect to parameters
kernel_product$C_dC_dparams(params = NULL, X, nug)
paramsKernel parameters
Xmatrix of points in rows
nugValue of nugget
dC_dx()
Derivative of covariance with respect to X
kernel_product$dC_dx(XX, X)
XXmatrix of points
Xmatrix of points to take derivative with respect to
s2_from_params()
Get s2 from params vector
kernel_product$s2_from_params(params, s2_est = self$s2_est)
paramsparameter vector
s2_estIs s2 being estimated?
print()
Print this object
kernel_product$print()
clone()
The objects of this class are cloneable with this method.
kernel_product$clone(deep = FALSE)
deepWhether to make a deep clone.
k1 <- Exponential$new(beta=1) k2 <- Matern32$new(beta=2) k <- k1 * k2 k$k(matrix(c(2,1), ncol=1))k1 <- Exponential$new(beta=1) k2 <- Matern32$new(beta=2) k <- k1 * k2 k$k(matrix(c(2,1), ncol=1))
Gaussian Kernel R6 class
Gaussian Kernel R6 class
R6Class object.
Object of R6Class with methods for fitting GP model.
GauPro::GauPro_kernel -> GauPro_kernel_sum
k1kernel 1
k2kernel 2
k1_param_lengthparam length of kernel 1
k2_param_lengthparam length of kernel 2
k1plparam length of kernel 1
k2plparam length of kernel 2
s2variance
s2_estIs s2 being estimated?
new()
Initialize kernel
kernel_sum$new(k1, k2, useC = TRUE)
k1Kernel 1
k2Kernel 2
useCShould C code used? Not applicable for kernel sum.
k()
Calculate covariance between two points
kernel_sum$k(x, y = NULL, params, ...)
xvector.
yvector, optional. If excluded, find correlation of x with itself.
paramsparameters to use instead of beta and s2.
...Not used
param_optim_start()
Starting point for parameters for optimization
kernel_sum$param_optim_start(jitter = F, y)
jitterShould there be a jitter?
yOutput
param_optim_start0()
Starting point for parameters for optimization
kernel_sum$param_optim_start0(jitter = F, y)
jitterShould there be a jitter?
yOutput
param_optim_lower()
Lower bounds of parameters for optimization
kernel_sum$param_optim_lower()
param_optim_upper()
Upper bounds of parameters for optimization
kernel_sum$param_optim_upper()
set_params_from_optim()
Set parameters from optimization output
kernel_sum$set_params_from_optim(optim_out)
optim_outOutput from optimization
dC_dparams()
Derivative of covariance with respect to parameters
kernel_sum$dC_dparams(params = NULL, C, X, C_nonug, nug)
paramsKernel parameters
CCovariance with nugget
Xmatrix of points in rows
C_nonugCovariance without nugget added to diagonal
nugValue of nugget
C_dC_dparams()
Calculate covariance matrix and its derivative with respect to parameters
kernel_sum$C_dC_dparams(params = NULL, X, nug)
paramsKernel parameters
Xmatrix of points in rows
nugValue of nugget
dC_dx()
Derivative of covariance with respect to X
kernel_sum$dC_dx(XX, X)
XXmatrix of points
Xmatrix of points to take derivative with respect to
s2_from_params()
Get s2 from params vector
kernel_sum$s2_from_params(params)
paramsparameter vector
s2_estIs s2 being estimated?
print()
Print this object
kernel_sum$print()
clone()
The objects of this class are cloneable with this method.
kernel_sum$clone(deep = FALSE)
deepWhether to make a deep clone.
k1 <- Exponential$new(beta=1) k2 <- Matern32$new(beta=2) k <- k1 + k2 k$k(matrix(c(2,1), ncol=1))k1 <- Exponential$new(beta=1) k2 <- Matern32$new(beta=2) k <- k1 + k2 k$k(matrix(c(2,1), ncol=1))
Latent Factor Kernel R6 class
Latent Factor Kernel R6 class
k_LatentFactorKernel( s2 = 1, D, nlevels, xindex, latentdim, p_lower = 0, p_upper = 1, p_est = TRUE, s2_lower = 1e-08, s2_upper = 1e+08, s2_est = TRUE, useC = TRUE, offdiagequal = 1 - 1e-06 )k_LatentFactorKernel( s2 = 1, D, nlevels, xindex, latentdim, p_lower = 0, p_upper = 1, p_est = TRUE, s2_lower = 1e-08, s2_upper = 1e+08, s2_est = TRUE, useC = TRUE, offdiagequal = 1 - 1e-06 )
s2 |
Initial variance |
D |
Number of input dimensions of data |
nlevels |
Number of levels for the factor |
xindex |
Index of X to use the kernel on |
latentdim |
Dimension of embedding space |
p_lower |
Lower bound for p |
p_upper |
Upper bound for p |
p_est |
Should p be estimated? |
s2_lower |
Lower bound for s2 |
s2_upper |
Upper bound for s2 |
s2_est |
Should s2 be estimated? |
useC |
Should C code used? Much faster. |
offdiagequal |
What should offdiagonal values be set to when the indices are the same? Use to avoid decomposition errors, similar to adding a nugget. |
R6Class object.
Used for factor variables, a single dimension. Each level of the factor gets mapped into a latent space, then the distances in that space determine their correlations.
Object of R6Class with methods for fitting GP model.
GauPro::GauPro_kernel -> GauPro_kernel_LatentFactorKernel
pParameter for correlation
p_estShould p be estimated?
p_lowerLower bound of p
p_upperUpper bound of p
p_lengthlength of p
s2variance
s2_estIs s2 estimated?
logs2Log of s2
logs2_lowerLower bound of logs2
logs2_upperUpper bound of logs2
xindexIndex of the factor (which column of X)
nlevelsNumber of levels for the factor
latentdimDimension of embedding space
pf_to_p_logLogical vector used to convert pf to p
p_to_pf_indsVector of indexes used to convert p to pf
offdiagequalWhat should offdiagonal values be set to when the indices are the same? Use to avoid decomposition errors, similar to adding a nugget.
new()
Initialize kernel object
LatentFactorKernel$new( s2 = 1, D, nlevels, xindex, latentdim, p_lower = 0, p_upper = 1, p_est = TRUE, s2_lower = 1e-08, s2_upper = 1e+08, s2_est = TRUE, useC = TRUE, offdiagequal = 1 - 1e-06 )
s2Initial variance
DNumber of input dimensions of data
nlevelsNumber of levels for the factor
xindexIndex of X to use the kernel on
latentdimDimension of embedding space
p_lowerLower bound for p
p_upperUpper bound for p
p_estShould p be estimated?
s2_lowerLower bound for s2
s2_upperUpper bound for s2
s2_estShould s2 be estimated?
useCShould C code used? Much faster.
offdiagequalWhat should offdiagonal values be set to when the indices are the same? Use to avoid decomposition errors, similar to adding a nugget.
k()
Calculate covariance between two points
LatentFactorKernel$k(x, y = NULL, p = self$p, s2 = self$s2, params = NULL)
xvector.
yvector, optional. If excluded, find correlation of x with itself.
pCorrelation parameters.
s2Variance parameter.
paramsparameters to use instead of beta and s2.
kone()
Find covariance of two points
LatentFactorKernel$kone( x, y, pf, s2, isdiag = TRUE, offdiagequal = self$offdiagequal )
xvector
yvector
pfcorrelation parameters on regular scale, includes zeroes for first level.
s2Variance parameter
isdiagIs this on the diagonal of the covariance?
offdiagequalWhat should offdiagonal values be set to when the indices are the same? Use to avoid decomposition errors, similar to adding a nugget.
dC_dparams()
Derivative of covariance with respect to parameters
LatentFactorKernel$dC_dparams(params = NULL, X, C_nonug, C, nug)
paramsKernel parameters
Xmatrix of points in rows
C_nonugCovariance without nugget added to diagonal
CCovariance with nugget
nugValue of nugget
C_dC_dparams()
Calculate covariance matrix and its derivative with respect to parameters
LatentFactorKernel$C_dC_dparams(params = NULL, X, nug)
paramsKernel parameters
Xmatrix of points in rows
nugValue of nugget
dC_dx()
Derivative of covariance with respect to X
LatentFactorKernel$dC_dx(XX, X, ...)
XXmatrix of points
Xmatrix of points to take derivative with respect to
...Additional args, not used
param_optim_start()
Starting point for parameters for optimization
LatentFactorKernel$param_optim_start( jitter = F, y, p_est = self$p_est, s2_est = self$s2_est )
jitterShould there be a jitter?
yOutput
p_estIs p being estimated?
s2_estIs s2 being estimated?
param_optim_start0()
Starting point for parameters for optimization
LatentFactorKernel$param_optim_start0( jitter = F, y, p_est = self$p_est, s2_est = self$s2_est )
jitterShould there be a jitter?
yOutput
p_estIs p being estimated?
s2_estIs s2 being estimated?
param_optim_lower()
Lower bounds of parameters for optimization
LatentFactorKernel$param_optim_lower(p_est = self$p_est, s2_est = self$s2_est)
p_estIs p being estimated?
s2_estIs s2 being estimated?
param_optim_upper()
Upper bounds of parameters for optimization
LatentFactorKernel$param_optim_upper(p_est = self$p_est, s2_est = self$s2_est)
p_estIs p being estimated?
s2_estIs s2 being estimated?
set_params_from_optim()
Set parameters from optimization output
LatentFactorKernel$set_params_from_optim( optim_out, p_est = self$p_est, s2_est = self$s2_est )
optim_outOutput from optimization
p_estIs p being estimated?
s2_estIs s2 being estimated?
p_to_pf()
Convert p (short parameter vector) to pf (long parameter vector with zeros).
LatentFactorKernel$p_to_pf(p)
pParameter vector
s2_from_params()
Get s2 from params vector
LatentFactorKernel$s2_from_params(params, s2_est = self$s2_est)
paramsparameter vector
s2_estIs s2 being estimated?
plotLatent()
Plot the points in the latent space
LatentFactorKernel$plotLatent()
print()
Print this object
LatentFactorKernel$print()
clone()
The objects of this class are cloneable with this method.
LatentFactorKernel$clone(deep = FALSE)
deepWhether to make a deep clone.
https://stackoverflow.com/questions/27086195/linear-index-upper-triangular-matrix
# Create a new kernel for a single factor with 5 levels, # mapped into two latent dimensions. kk <- LatentFactorKernel$new(D=1, nlevels=5, xindex=1, latentdim=2) # Random initial parameter values kk$p # Plots to understand kk$plotLatent() kk$plot() # 5 levels, 1/4 are similar and 2/3/5 are similar n <- 30 x <- matrix(sample(1:5, n, TRUE)) y <- c(ifelse(x == 1 | x == 4, 4, -3) + rnorm(n,0,.1)) plot(c(x), y) m5 <- GauPro_kernel_model$new( X=x, Z=y, kernel=LatentFactorKernel$new(D=1, nlevels = 5, xindex = 1, latentdim = 2)) m5$kernel$p # We should see 1/4 and 2/3/4 in separate clusters m5$kernel$plotLatent() if (requireNamespace("dplyr", quietly=TRUE)) { library(dplyr) n <- 20 X <- cbind(matrix(runif(n,2,6), ncol=1), matrix(sample(1:2, size=n, replace=TRUE), ncol=1)) X <- rbind(X, c(3.3,3), c(3.7,3)) n <- nrow(X) Z <- X[,1] - (4-X[,2])^2 + rnorm(n,0,.1) plot(X[,1], Z, col=X[,2]) tibble(X=X, Z) %>% arrange(X,Z) k2a <- IgnoreIndsKernel$new(k=Gaussian$new(D=1), ignoreinds = 2) k2b <- LatentFactorKernel$new(D=2, nlevels=3, xind=2, latentdim=2) k2 <- k2a * k2b k2b$p_upper <- .65*k2b$p_upper gp <- GauPro_kernel_model$new(X=X, Z=Z, kernel = k2, verbose = 5, nug.min=1e-2, restarts=1) gp$kernel$k1$kernel$beta gp$kernel$k2$p gp$kernel$k(x = gp$X) tibble(X=X, Z=Z, pred=gp$predict(X)) %>% arrange(X, Z) tibble(X=X[,2], Z) %>% group_by(X) %>% summarize(n=n(), mean(Z)) curve(gp$pred(cbind(matrix(x,ncol=1),1)),2,6, ylim=c(min(Z), max(Z))) points(X[X[,2]==1,1], Z[X[,2]==1]) curve(gp$pred(cbind(matrix(x,ncol=1),2)), add=TRUE, col=2) points(X[X[,2]==2,1], Z[X[,2]==2], col=2) curve(gp$pred(cbind(matrix(x,ncol=1),3)), add=TRUE, col=3) points(X[X[,2]==3,1], Z[X[,2]==3], col=3) legend(legend=1:3, fill=1:3, x="topleft") # See which points affect (5.5, 3 themost) data.frame(X, cov=gp$kernel$k(X, c(5.5,3))) %>% arrange(-cov) plot(k2b) }# Create a new kernel for a single factor with 5 levels, # mapped into two latent dimensions. kk <- LatentFactorKernel$new(D=1, nlevels=5, xindex=1, latentdim=2) # Random initial parameter values kk$p # Plots to understand kk$plotLatent() kk$plot() # 5 levels, 1/4 are similar and 2/3/5 are similar n <- 30 x <- matrix(sample(1:5, n, TRUE)) y <- c(ifelse(x == 1 | x == 4, 4, -3) + rnorm(n,0,.1)) plot(c(x), y) m5 <- GauPro_kernel_model$new( X=x, Z=y, kernel=LatentFactorKernel$new(D=1, nlevels = 5, xindex = 1, latentdim = 2)) m5$kernel$p # We should see 1/4 and 2/3/4 in separate clusters m5$kernel$plotLatent() if (requireNamespace("dplyr", quietly=TRUE)) { library(dplyr) n <- 20 X <- cbind(matrix(runif(n,2,6), ncol=1), matrix(sample(1:2, size=n, replace=TRUE), ncol=1)) X <- rbind(X, c(3.3,3), c(3.7,3)) n <- nrow(X) Z <- X[,1] - (4-X[,2])^2 + rnorm(n,0,.1) plot(X[,1], Z, col=X[,2]) tibble(X=X, Z) %>% arrange(X,Z) k2a <- IgnoreIndsKernel$new(k=Gaussian$new(D=1), ignoreinds = 2) k2b <- LatentFactorKernel$new(D=2, nlevels=3, xind=2, latentdim=2) k2 <- k2a * k2b k2b$p_upper <- .65*k2b$p_upper gp <- GauPro_kernel_model$new(X=X, Z=Z, kernel = k2, verbose = 5, nug.min=1e-2, restarts=1) gp$kernel$k1$kernel$beta gp$kernel$k2$p gp$kernel$k(x = gp$X) tibble(X=X, Z=Z, pred=gp$predict(X)) %>% arrange(X, Z) tibble(X=X[,2], Z) %>% group_by(X) %>% summarize(n=n(), mean(Z)) curve(gp$pred(cbind(matrix(x,ncol=1),1)),2,6, ylim=c(min(Z), max(Z))) points(X[X[,2]==1,1], Z[X[,2]==1]) curve(gp$pred(cbind(matrix(x,ncol=1),2)), add=TRUE, col=2) points(X[X[,2]==2,1], Z[X[,2]==2], col=2) curve(gp$pred(cbind(matrix(x,ncol=1),3)), add=TRUE, col=3) points(X[X[,2]==3,1], Z[X[,2]==3], col=3) legend(legend=1:3, fill=1:3, x="topleft") # See which points affect (5.5, 3 themost) data.frame(X, cov=gp$kernel$k(X, c(5.5,3))) %>% arrange(-cov) plot(k2b) }
Matern 3/2 Kernel R6 class
Matern 3/2 Kernel R6 class
k_Matern32( beta, s2 = 1, D, beta_lower = -8, beta_upper = 6, beta_est = TRUE, s2_lower = 1e-08, s2_upper = 1e+08, s2_est = TRUE, useC = TRUE, isotropic = FALSE )k_Matern32( beta, s2 = 1, D, beta_lower = -8, beta_upper = 6, beta_est = TRUE, s2_lower = 1e-08, s2_upper = 1e+08, s2_est = TRUE, useC = TRUE, isotropic = FALSE )
beta |
Initial beta value |
s2 |
Initial variance |
D |
Number of input dimensions of data |
beta_lower |
Lower bound for beta |
beta_upper |
Upper bound for beta |
beta_est |
Should beta be estimated? |
s2_lower |
Lower bound for s2 |
s2_upper |
Upper bound for s2 |
s2_est |
Should s2 be estimated? |
useC |
Should C code used? Much faster. |
isotropic |
If isotropic then a single beta/theta is used for all dimensions. If not (anisotropic) then a separate beta/beta is used for each dimension. |
R6Class object.
Object of R6Class with methods for fitting GP model.
GauPro::GauPro_kernel -> GauPro::GauPro_kernel_beta -> GauPro_kernel_Matern32
sqrt3Saved value of square root of 3
GauPro::GauPro_kernel$plot()GauPro::GauPro_kernel_beta$C_dC_dparams()GauPro::GauPro_kernel_beta$initialize()GauPro::GauPro_kernel_beta$param_optim_lower()GauPro::GauPro_kernel_beta$param_optim_start()GauPro::GauPro_kernel_beta$param_optim_start0()GauPro::GauPro_kernel_beta$param_optim_upper()GauPro::GauPro_kernel_beta$s2_from_params()GauPro::GauPro_kernel_beta$set_params_from_optim()k()
Calculate covariance between two points
Matern32$k(x, y = NULL, beta = self$beta, s2 = self$s2, params = NULL)
xvector.
yvector, optional. If excluded, find correlation of x with itself.
betaCorrelation parameters.
s2Variance parameter.
paramsparameters to use instead of beta and s2.
kone()
Find covariance of two points
Matern32$kone(x, y, beta, theta, s2)
xvector
yvector
betacorrelation parameters on log scale
thetacorrelation parameters on regular scale
s2Variance parameter
dC_dparams()
Derivative of covariance with respect to parameters
Matern32$dC_dparams(params = NULL, X, C_nonug, C, nug)
paramsKernel parameters
Xmatrix of points in rows
C_nonugCovariance without nugget added to diagonal
CCovariance with nugget
nugValue of nugget
dC_dx()
Derivative of covariance with respect to X
Matern32$dC_dx(XX, X, theta, beta = self$beta, s2 = self$s2)
XXmatrix of points
Xmatrix of points to take derivative with respect to
thetaCorrelation parameters
betalog of theta
s2Variance parameter
print()
Print this object
Matern32$print()
clone()
The objects of this class are cloneable with this method.
Matern32$clone(deep = FALSE)
deepWhether to make a deep clone.
k1 <- Matern32$new(beta=0) plot(k1) 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=Matern32$new(1), parallel=FALSE) gp$predict(.454) gp$plot1D() gp$cool1Dplot()k1 <- Matern32$new(beta=0) plot(k1) 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=Matern32$new(1), parallel=FALSE) gp$predict(.454) gp$plot1D() gp$cool1Dplot()
Matern 5/2 Kernel R6 class
Matern 5/2 Kernel R6 class
k_Matern52( beta, s2 = 1, D, beta_lower = -8, beta_upper = 6, beta_est = TRUE, s2_lower = 1e-08, s2_upper = 1e+08, s2_est = TRUE, useC = TRUE, isotropic = FALSE )k_Matern52( beta, s2 = 1, D, beta_lower = -8, beta_upper = 6, beta_est = TRUE, s2_lower = 1e-08, s2_upper = 1e+08, s2_est = TRUE, useC = TRUE, isotropic = FALSE )
beta |
Initial beta value |
s2 |
Initial variance |
D |
Number of input dimensions of data |
beta_lower |
Lower bound for beta |
beta_upper |
Upper bound for beta |
beta_est |
Should beta be estimated? |
s2_lower |
Lower bound for s2 |
s2_upper |
Upper bound for s2 |
s2_est |
Should s2 be estimated? |
useC |
Should C code used? Much faster. |
isotropic |
If isotropic then a single beta/theta is used for all dimensions. If not (anisotropic) then a separate beta/beta is used for each dimension. |
R6Class object.
where
Object of R6Class with methods for fitting GP model.
GauPro::GauPro_kernel -> GauPro::GauPro_kernel_beta -> GauPro_kernel_Matern52
sqrt5Saved value of square root of 5
GauPro::GauPro_kernel$plot()GauPro::GauPro_kernel_beta$C_dC_dparams()GauPro::GauPro_kernel_beta$initialize()GauPro::GauPro_kernel_beta$param_optim_lower()GauPro::GauPro_kernel_beta$param_optim_start()GauPro::GauPro_kernel_beta$param_optim_start0()GauPro::GauPro_kernel_beta$param_optim_upper()GauPro::GauPro_kernel_beta$s2_from_params()GauPro::GauPro_kernel_beta$set_params_from_optim()k()
Calculate covariance between two points
Matern52$k(x, y = NULL, beta = self$beta, s2 = self$s2, params = NULL)
xvector.
yvector, optional. If excluded, find correlation of x with itself.
betaCorrelation parameters.
s2Variance parameter.
paramsparameters to use instead of beta and s2.
kone()
Find covariance of two points
Matern52$kone(x, y, beta, theta, s2)
xvector
yvector
betacorrelation parameters on log scale
thetacorrelation parameters on regular scale
s2Variance parameter
dC_dparams()
Derivative of covariance with respect to parameters
Matern52$dC_dparams(params = NULL, X, C_nonug, C, nug)
paramsKernel parameters
Xmatrix of points in rows
C_nonugCovariance without nugget added to diagonal
CCovariance with nugget
nugValue of nugget
dC_dx()
Derivative of covariance with respect to X
Matern52$dC_dx(XX, X, theta, beta = self$beta, s2 = self$s2)
XXmatrix of points
Xmatrix of points to take derivative with respect to
thetaCorrelation parameters
betalog of theta
s2Variance parameter
print()
Print this object
Matern52$print()
clone()
The objects of this class are cloneable with this method.
Matern52$clone(deep = FALSE)
deepWhether to make a deep clone.
k1 <- Matern52$new(beta=0) plot(k1) 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=Matern52$new(1), parallel=FALSE) gp$predict(.454) gp$plot1D() gp$cool1Dplot()k1 <- Matern52$new(beta=0) plot(k1) 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=Matern52$new(1), parallel=FALSE) gp$predict(.454) gp$plot1D() gp$cool1Dplot()
Ordered Factor Kernel R6 class
Ordered Factor Kernel R6 class
k_OrderedFactorKernel( s2 = 1, D, nlevels, xindex, p_lower = 1e-08, p_upper = 5, p_est = TRUE, s2_lower = 1e-08, s2_upper = 1e+08, s2_est = TRUE, useC = TRUE, offdiagequal = 1 - 1e-06 )k_OrderedFactorKernel( s2 = 1, D, nlevels, xindex, p_lower = 1e-08, p_upper = 5, p_est = TRUE, s2_lower = 1e-08, s2_upper = 1e+08, s2_est = TRUE, useC = TRUE, offdiagequal = 1 - 1e-06 )
s2 |
Initial variance |
D |
Number of input dimensions of data |
nlevels |
Number of levels for the factor |
xindex |
Index of the factor (which column of X) |
p_lower |
Lower bound for p |
p_upper |
Upper bound for p |
p_est |
Should p be estimated? |
s2_lower |
Lower bound for s2 |
s2_upper |
Upper bound for s2 |
s2_est |
Should s2 be estimated? |
useC |
Should C code used? Not implemented for FactorKernel yet. |
offdiagequal |
What should offdiagonal values be set to when the indices are the same? Use to avoid decomposition errors, similar to adding a nugget. |
R6Class object.
Use for factor inputs that are considered to have an ordering
Object of R6Class with methods for fitting GP model.
GauPro::GauPro_kernel -> GauPro_kernel_OrderedFactorKernel
pParameter for correlation
p_estShould p be estimated?
p_lowerLower bound of p
p_upperUpper bound of p
p_lengthlength of p
s2variance
s2_estIs s2 estimated?
logs2Log of s2
logs2_lowerLower bound of logs2
logs2_upperUpper bound of logs2
xindexIndex of the factor (which column of X)
nlevelsNumber of levels for the factor
offdiagequalWhat should offdiagonal values be set to when the indices are the same? Use to avoid decomposition errors, similar to adding a nugget.
new()
Initialize kernel object
OrderedFactorKernel$new( s2 = 1, D = NULL, nlevels, xindex, p_lower = 1e-08, p_upper = 5, p_est = TRUE, s2_lower = 1e-08, s2_upper = 1e+08, s2_est = TRUE, useC = TRUE, offdiagequal = 1 - 1e-06 )
s2Initial variance
DNumber of input dimensions of data
nlevelsNumber of levels for the factor
xindexIndex of X to use the kernel on
p_lowerLower bound for p
p_upperUpper bound for p
p_estShould p be estimated?
s2_lowerLower bound for s2
s2_upperUpper bound for s2
s2_estShould s2 be estimated?
useCShould C code used? Much faster.
offdiagequalWhat should offdiagonal values be set to when the indices are the same? Use to avoid decomposition errors, similar to adding a nugget.
pVector of distances in latent space
k()
Calculate covariance between two points
OrderedFactorKernel$k(x, y = NULL, p = self$p, s2 = self$s2, params = NULL)
xvector.
yvector, optional. If excluded, find correlation of x with itself.
pCorrelation parameters.
s2Variance parameter.
paramsparameters to use instead of beta and s2.
kone()
Find covariance of two points
OrderedFactorKernel$kone( x, y, p, s2, isdiag = TRUE, offdiagequal = self$offdiagequal )
xvector
yvector
pcorrelation parameters on regular scale
s2Variance parameter
isdiagIs this on the diagonal of the covariance?
offdiagequalWhat should offdiagonal values be set to when the indices are the same? Use to avoid decomposition errors, similar to adding a nugget.
dC_dparams()
Derivative of covariance with respect to parameters
OrderedFactorKernel$dC_dparams(params = NULL, X, C_nonug, C, nug)
paramsKernel parameters
Xmatrix of points in rows
C_nonugCovariance without nugget added to diagonal
CCovariance with nugget
nugValue of nugget
C_dC_dparams()
Calculate covariance matrix and its derivative with respect to parameters
OrderedFactorKernel$C_dC_dparams(params = NULL, X, nug)
paramsKernel parameters
Xmatrix of points in rows
nugValue of nugget
dC_dx()
Derivative of covariance with respect to X
OrderedFactorKernel$dC_dx(XX, X, ...)
XXmatrix of points
Xmatrix of points to take derivative with respect to
...Additional args, not used
param_optim_start()
Starting point for parameters for optimization
OrderedFactorKernel$param_optim_start( jitter = F, y, p_est = self$p_est, s2_est = self$s2_est )
jitterShould there be a jitter?
yOutput
p_estIs p being estimated?
s2_estIs s2 being estimated?
param_optim_start0()
Starting point for parameters for optimization
OrderedFactorKernel$param_optim_start0( jitter = F, y, p_est = self$p_est, s2_est = self$s2_est )
jitterShould there be a jitter?
yOutput
p_estIs p being estimated?
s2_estIs s2 being estimated?
param_optim_lower()
Lower bounds of parameters for optimization
OrderedFactorKernel$param_optim_lower(p_est = self$p_est, s2_est = self$s2_est)
p_estIs p being estimated?
s2_estIs s2 being estimated?
param_optim_upper()
Upper bounds of parameters for optimization
OrderedFactorKernel$param_optim_upper(p_est = self$p_est, s2_est = self$s2_est)
p_estIs p being estimated?
s2_estIs s2 being estimated?
set_params_from_optim()
Set parameters from optimization output
OrderedFactorKernel$set_params_from_optim( optim_out, p_est = self$p_est, s2_est = self$s2_est )
optim_outOutput from optimization
p_estIs p being estimated?
s2_estIs s2 being estimated?
s2_from_params()
Get s2 from params vector
OrderedFactorKernel$s2_from_params(params, s2_est = self$s2_est)
paramsparameter vector
s2_estIs s2 being estimated?
plotLatent()
Plot the points in the latent space
OrderedFactorKernel$plotLatent()
print()
Print this object
OrderedFactorKernel$print()
clone()
The objects of this class are cloneable with this method.
OrderedFactorKernel$clone(deep = FALSE)
deepWhether to make a deep clone.
https://stackoverflow.com/questions/27086195/linear-index-upper-triangular-matrix
kk <- OrderedFactorKernel$new(D=1, nlevels=5, xindex=1) kk$p <- (1:10)/100 kmat <- outer(1:5, 1:5, Vectorize(kk$k)) kmat if (requireNamespace("dplyr", quietly=TRUE)) { library(dplyr) n <- 20 X <- cbind(matrix(runif(n,2,6), ncol=1), matrix(sample(1:2, size=n, replace=TRUE), ncol=1)) X <- rbind(X, c(3.3,3), c(3.7,3)) n <- nrow(X) Z <- X[,1] - (4-X[,2])^2 + rnorm(n,0,.1) plot(X[,1], Z, col=X[,2]) tibble(X=X, Z) %>% arrange(X,Z) k2a <- IgnoreIndsKernel$new(k=Gaussian$new(D=1), ignoreinds = 2) k2b <- OrderedFactorKernel$new(D=2, nlevels=3, xind=2) k2 <- k2a * k2b k2b$p_upper <- .65*k2b$p_upper gp <- GauPro_kernel_model$new(X=X, Z=Z, kernel = k2, verbose = 5, nug.min=1e-2, restarts=0) gp$kernel$k1$kernel$beta gp$kernel$k2$p gp$kernel$k(x = gp$X) tibble(X=X, Z=Z, pred=gp$predict(X)) %>% arrange(X, Z) tibble(X=X[,2], Z) %>% group_by(X) %>% summarize(n=n(), mean(Z)) curve(gp$pred(cbind(matrix(x,ncol=1),1)),2,6, ylim=c(min(Z), max(Z))) points(X[X[,2]==1,1], Z[X[,2]==1]) curve(gp$pred(cbind(matrix(x,ncol=1),2)), add=TRUE, col=2) points(X[X[,2]==2,1], Z[X[,2]==2], col=2) curve(gp$pred(cbind(matrix(x,ncol=1),3)), add=TRUE, col=3) points(X[X[,2]==3,1], Z[X[,2]==3], col=3) legend(legend=1:3, fill=1:3, x="topleft") # See which points affect (5.5, 3 themost) data.frame(X, cov=gp$kernel$k(X, c(5.5,3))) %>% arrange(-cov) plot(k2b) }kk <- OrderedFactorKernel$new(D=1, nlevels=5, xindex=1) kk$p <- (1:10)/100 kmat <- outer(1:5, 1:5, Vectorize(kk$k)) kmat if (requireNamespace("dplyr", quietly=TRUE)) { library(dplyr) n <- 20 X <- cbind(matrix(runif(n,2,6), ncol=1), matrix(sample(1:2, size=n, replace=TRUE), ncol=1)) X <- rbind(X, c(3.3,3), c(3.7,3)) n <- nrow(X) Z <- X[,1] - (4-X[,2])^2 + rnorm(n,0,.1) plot(X[,1], Z, col=X[,2]) tibble(X=X, Z) %>% arrange(X,Z) k2a <- IgnoreIndsKernel$new(k=Gaussian$new(D=1), ignoreinds = 2) k2b <- OrderedFactorKernel$new(D=2, nlevels=3, xind=2) k2 <- k2a * k2b k2b$p_upper <- .65*k2b$p_upper gp <- GauPro_kernel_model$new(X=X, Z=Z, kernel = k2, verbose = 5, nug.min=1e-2, restarts=0) gp$kernel$k1$kernel$beta gp$kernel$k2$p gp$kernel$k(x = gp$X) tibble(X=X, Z=Z, pred=gp$predict(X)) %>% arrange(X, Z) tibble(X=X[,2], Z) %>% group_by(X) %>% summarize(n=n(), mean(Z)) curve(gp$pred(cbind(matrix(x,ncol=1),1)),2,6, ylim=c(min(Z), max(Z))) points(X[X[,2]==1,1], Z[X[,2]==1]) curve(gp$pred(cbind(matrix(x,ncol=1),2)), add=TRUE, col=2) points(X[X[,2]==2,1], Z[X[,2]==2], col=2) curve(gp$pred(cbind(matrix(x,ncol=1),3)), add=TRUE, col=3) points(X[X[,2]==3,1], Z[X[,2]==3], col=3) legend(legend=1:3, fill=1:3, x="topleft") # See which points affect (5.5, 3 themost) data.frame(X, cov=gp$kernel$k(X, c(5.5,3))) %>% arrange(-cov) plot(k2b) }
Periodic Kernel R6 class
Periodic Kernel R6 class
k_Periodic( p, alpha = 1, s2 = 1, D, p_lower = 0, p_upper = 100, p_est = TRUE, alpha_lower = 0, alpha_upper = 100, alpha_est = TRUE, s2_lower = 1e-08, s2_upper = 1e+08, s2_est = TRUE, useC = TRUE )k_Periodic( p, alpha = 1, s2 = 1, D, p_lower = 0, p_upper = 100, p_est = TRUE, alpha_lower = 0, alpha_upper = 100, alpha_est = TRUE, s2_lower = 1e-08, s2_upper = 1e+08, s2_est = TRUE, useC = TRUE )
p |
Periodic parameter |
alpha |
Periodic parameter |
s2 |
Initial variance |
D |
Number of input dimensions of data |
p_lower |
Lower bound for p |
p_upper |
Upper bound for p |
p_est |
Should p be estimated? |
alpha_lower |
Lower bound for alpha |
alpha_upper |
Upper bound for alpha |
alpha_est |
Should alpha be estimated? |
s2_lower |
Lower bound for s2 |
s2_upper |
Upper bound for s2 |
s2_est |
Should s2 be estimated? |
useC |
Should C code used? Much faster if implemented. |
R6Class object.
p is the period for each dimension, a is a single number for scaling
Object of R6Class with methods for fitting GP model.
GauPro::GauPro_kernel -> GauPro_kernel_Periodic
pParameter for correlation
p_estShould p be estimated?
logpLog of p
logp_lowerLower bound of logp
logp_upperUpper bound of logp
p_lengthlength of p
alphaParameter for correlation
alpha_estShould alpha be estimated?
logalphaLog of alpha
logalpha_lowerLower bound of logalpha
logalpha_upperUpper bound of logalpha
s2variance
s2_estIs s2 estimated?
logs2Log of s2
logs2_lowerLower bound of logs2
logs2_upperUpper bound of logs2
new()
Initialize kernel object
Periodic$new( p, alpha = 1, s2 = 1, D, p_lower = 0, p_upper = 100, p_est = TRUE, alpha_lower = 0, alpha_upper = 100, alpha_est = TRUE, s2_lower = 1e-08, s2_upper = 1e+08, s2_est = TRUE, useC = TRUE )
pPeriodic parameter
alphaPeriodic parameter
s2Initial variance
DNumber of input dimensions of data
p_lowerLower bound for p
p_upperUpper bound for p
p_estShould p be estimated?
alpha_lowerLower bound for alpha
alpha_upperUpper bound for alpha
alpha_estShould alpha be estimated?
s2_lowerLower bound for s2
s2_upperUpper bound for s2
s2_estShould s2 be estimated?
useCShould C code used? Much faster if implemented.
k()
Calculate covariance between two points
Periodic$k( x, y = NULL, logp = self$logp, logalpha = self$logalpha, s2 = self$s2, params = NULL )
xvector.
yvector, optional. If excluded, find correlation of x with itself.
logpCorrelation parameters.
logalphaCorrelation parameters.
s2Variance parameter.
paramsparameters to use instead of beta and s2.
kone()
Find covariance of two points
Periodic$kone(x, y, logp, p, alpha, s2)
xvector
yvector
logpcorrelation parameters on log scale
pcorrelation parameters on regular scale
alphacorrelation parameter
s2Variance parameter
dC_dparams()
Derivative of covariance with respect to parameters
Periodic$dC_dparams(params = NULL, X, C_nonug, C, nug)
paramsKernel parameters
Xmatrix of points in rows
C_nonugCovariance without nugget added to diagonal
CCovariance with nugget
nugValue of nugget
C_dC_dparams()
Calculate covariance matrix and its derivative with respect to parameters
Periodic$C_dC_dparams(params = NULL, X, nug)
paramsKernel parameters
Xmatrix of points in rows
nugValue of nugget
dC_dx()
Derivative of covariance with respect to X
Periodic$dC_dx(XX, X, logp = self$logp, logalpha = self$logalpha, s2 = self$s2)
XXmatrix of points
Xmatrix of points to take derivative with respect to
logplog of p
logalphalog of alpha
s2Variance parameter
param_optim_start()
Starting point for parameters for optimization
Periodic$param_optim_start( jitter = F, y, p_est = self$p_est, alpha_est = self$alpha_est, s2_est = self$s2_est )
jitterShould there be a jitter?
yOutput
p_estIs p being estimated?
alpha_estIs alpha being estimated?
s2_estIs s2 being estimated?
param_optim_start0()
Starting point for parameters for optimization
Periodic$param_optim_start0( jitter = F, y, p_est = self$p_est, alpha_est = self$alpha_est, s2_est = self$s2_est )
jitterShould there be a jitter?
yOutput
p_estIs p being estimated?
alpha_estIs alpha being estimated?
s2_estIs s2 being estimated?
param_optim_lower()
Lower bounds of parameters for optimization
Periodic$param_optim_lower( p_est = self$p_est, alpha_est = self$alpha_est, s2_est = self$s2_est )
p_estIs p being estimated?
alpha_estIs alpha being estimated?
s2_estIs s2 being estimated?
param_optim_upper()
Upper bounds of parameters for optimization
Periodic$param_optim_upper( p_est = self$p_est, alpha_est = self$alpha_est, s2_est = self$s2_est )
p_estIs p being estimated?
alpha_estIs alpha being estimated?
s2_estIs s2 being estimated?
set_params_from_optim()
Set parameters from optimization output
Periodic$set_params_from_optim( optim_out, p_est = self$p_est, alpha_est = self$alpha_est, s2_est = self$s2_est )
optim_outOutput from optimization
p_estIs p being estimated?
alpha_estIs alpha being estimated?
s2_estIs s2 being estimated?
s2_from_params()
Get s2 from params vector
Periodic$s2_from_params(params, s2_est = self$s2_est)
paramsparameter vector
s2_estIs s2 being estimated?
print()
Print this object
Periodic$print()
clone()
The objects of this class are cloneable with this method.
Periodic$clone(deep = FALSE)
deepWhether to make a deep clone.
k1 <- Periodic$new(p=1, alpha=1) plot(k1) 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=Periodic$new(D=1), parallel=FALSE) gp$predict(.454) gp$plot1D() gp$cool1Dplot() plot(gp$kernel)k1 <- Periodic$new(p=1, alpha=1) plot(k1) 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=Periodic$new(D=1), parallel=FALSE) gp$predict(.454) gp$plot1D() gp$cool1Dplot() plot(gp$kernel)
Power Exponential Kernel R6 class
Power Exponential Kernel R6 class
k_PowerExp( alpha = 1.95, beta, s2 = 1, D, beta_lower = -8, beta_upper = 6, beta_est = TRUE, alpha_lower = 1e-08, alpha_upper = 2, alpha_est = TRUE, s2_lower = 1e-08, s2_upper = 1e+08, s2_est = TRUE, useC = TRUE )k_PowerExp( alpha = 1.95, beta, s2 = 1, D, beta_lower = -8, beta_upper = 6, beta_est = TRUE, alpha_lower = 1e-08, alpha_upper = 2, alpha_est = TRUE, s2_lower = 1e-08, s2_upper = 1e+08, s2_est = TRUE, useC = TRUE )
alpha |
Initial alpha value (the exponent). Between 0 and 2. |
beta |
Initial beta value |
s2 |
Initial variance |
D |
Number of input dimensions of data |
beta_lower |
Lower bound for beta |
beta_upper |
Upper bound for beta |
beta_est |
Should beta be estimated? |
alpha_lower |
Lower bound for alpha |
alpha_upper |
Upper bound for alpha |
alpha_est |
Should alpha be estimated? |
s2_lower |
Lower bound for s2 |
s2_upper |
Upper bound for s2 |
s2_est |
Should s2 be estimated? |
useC |
Should C code used? Much faster if implemented. |
R6Class object.
Object of R6Class with methods for fitting GP model.
GauPro::GauPro_kernel -> GauPro::GauPro_kernel_beta -> GauPro_kernel_PowerExp
alphaalpha value (the exponent). Between 0 and 2.
alpha_lowerLower bound for alpha
alpha_upperUpper bound for alpha
alpha_estShould alpha be estimated?
new()
Initialize kernel object
PowerExp$new( alpha = 1.95, beta, s2 = 1, D, beta_lower = -8, beta_upper = 6, beta_est = TRUE, alpha_lower = 1e-08, alpha_upper = 2, alpha_est = TRUE, s2_lower = 1e-08, s2_upper = 1e+08, s2_est = TRUE, useC = TRUE )
alphaInitial alpha value (the exponent). Between 0 and 2.
betaInitial beta value
s2Initial variance
DNumber of input dimensions of data
beta_lowerLower bound for beta
beta_upperUpper bound for beta
beta_estShould beta be estimated?
alpha_lowerLower bound for alpha
alpha_upperUpper bound for alpha
alpha_estShould alpha be estimated?
s2_lowerLower bound for s2
s2_upperUpper bound for s2
s2_estShould s2 be estimated?
useCShould C code used? Much faster if implemented.
k()
Calculate covariance between two points
PowerExp$k( x, y = NULL, beta = self$beta, alpha = self$alpha, s2 = self$s2, params = NULL )
xvector.
yvector, optional. If excluded, find correlation of x with itself.
betaCorrelation parameters.
alphaalpha value (the exponent). Between 0 and 2.
s2Variance parameter.
paramsparameters to use instead of beta and s2.
kone()
Find covariance of two points
PowerExp$kone(x, y, beta, theta, alpha, s2)
xvector
yvector
betacorrelation parameters on log scale
thetacorrelation parameters on regular scale
alphaalpha value (the exponent). Between 0 and 2.
s2Variance parameter
dC_dparams()
Derivative of covariance with respect to parameters
PowerExp$dC_dparams(params = NULL, X, C_nonug, C, nug)
paramsKernel parameters
Xmatrix of points in rows
C_nonugCovariance without nugget added to diagonal
CCovariance with nugget
nugValue of nugget
dC_dx()
Derivative of covariance with respect to X
PowerExp$dC_dx( XX, X, theta, beta = self$beta, alpha = self$alpha, s2 = self$s2 )
XXmatrix of points
Xmatrix of points to take derivative with respect to
thetaCorrelation parameters
betalog of theta
alphaalpha value (the exponent). Between 0 and 2.
s2Variance parameter
param_optim_start()
Starting point for parameters for optimization
PowerExp$param_optim_start( jitter = F, y, beta_est = self$beta_est, alpha_est = self$alpha_est, s2_est = self$s2_est )
jitterShould there be a jitter?
yOutput
beta_estIs beta being estimated?
alpha_estIs alpha being estimated?
s2_estIs s2 being estimated?
param_optim_start0()
Starting point for parameters for optimization
PowerExp$param_optim_start0( jitter = F, y, beta_est = self$beta_est, alpha_est = self$alpha_est, s2_est = self$s2_est )
jitterShould there be a jitter?
yOutput
beta_estIs beta being estimated?
alpha_estIs alpha being estimated?
s2_estIs s2 being estimated?
param_optim_lower()
Lower bounds of parameters for optimization
PowerExp$param_optim_lower( beta_est = self$beta_est, alpha_est = self$alpha_est, s2_est = self$s2_est )
beta_estIs beta being estimated?
alpha_estIs alpha being estimated?
s2_estIs s2 being estimated?
param_optim_upper()
Upper bounds of parameters for optimization
PowerExp$param_optim_upper( beta_est = self$beta_est, alpha_est = self$alpha_est, s2_est = self$s2_est )
beta_estIs beta being estimated?
alpha_estIs alpha being estimated?
s2_estIs s2 being estimated?
set_params_from_optim()
Set parameters from optimization output
PowerExp$set_params_from_optim( optim_out, beta_est = self$beta_est, alpha_est = self$alpha_est, s2_est = self$s2_est )
optim_outOutput from optimization
beta_estIs beta estimate?
alpha_estIs alpha estimated?
s2_estIs s2 estimated?
print()
Print this object
PowerExp$print()
clone()
The objects of this class are cloneable with this method.
PowerExp$clone(deep = FALSE)
deepWhether to make a deep clone.
k1 <- PowerExp$new(beta=0, alpha=0)k1 <- PowerExp$new(beta=0, alpha=0)
Predict for class GauPro
## S3 method for class 'GauPro' predict(object, XX, se.fit = F, covmat = F, split_speed = T, ...)## S3 method for class 'GauPro' predict(object, XX, se.fit = F, covmat = F, split_speed = T, ...)
object |
Object of class GauPro |
XX |
new points to predict |
se.fit |
Should standard error be returned (and variance)? |
covmat |
Should the covariance matrix be returned? |
split_speed |
Should the calculation be split up to speed it up? |
... |
Additional parameters |
Prediction from object at XX
n <- 12 x <- matrix(seq(0,1,length.out = n), ncol=1) y <- sin(2*pi*x) + rnorm(n,0,1e-1) gp <- GauPro(X=x, Z=y, parallel=FALSE) predict(gp, .448)n <- 12 x <- matrix(seq(0,1,length.out = n), ncol=1) y <- sin(2*pi*x) + rnorm(n,0,1e-1) gp <- GauPro(X=x, Z=y, parallel=FALSE) predict(gp, .448)
Predict mean and se for given matrix
## S3 method for class 'GauPro_base' predict(object, XX, se.fit = F, covmat = F, split_speed = T, ...)## S3 method for class 'GauPro_base' predict(object, XX, se.fit = F, covmat = F, split_speed = T, ...)
object |
Object of class GauPro_base |
XX |
Points to predict at |
se.fit |
Should the se be returned? |
covmat |
Should the covariance matrix be returned? |
split_speed |
Should the predictions be split up for speed |
... |
Additional parameters |
Prediction from object at XX
Print summary.GauPro
## S3 method for class 'summary.GauPro' print(x, ...)## S3 method for class 'summary.GauPro' print(x, ...)
x |
summary.GauPro object |
... |
Additional args |
prints, returns invisible object
Rational Quadratic Kernel R6 class
Rational Quadratic Kernel R6 class
k_RatQuad( beta, alpha = 1, s2 = 1, D, beta_lower = -8, beta_upper = 6, beta_est = TRUE, alpha_lower = 1e-08, alpha_upper = 100, alpha_est = TRUE, s2_lower = 1e-08, s2_upper = 1e+08, s2_est = TRUE, useC = TRUE )k_RatQuad( beta, alpha = 1, s2 = 1, D, beta_lower = -8, beta_upper = 6, beta_est = TRUE, alpha_lower = 1e-08, alpha_upper = 100, alpha_est = TRUE, s2_lower = 1e-08, s2_upper = 1e+08, s2_est = TRUE, useC = TRUE )
beta |
Initial beta value |
alpha |
Initial alpha value |
s2 |
Initial variance |
D |
Number of input dimensions of data |
beta_lower |
Lower bound for beta |
beta_upper |
Upper bound for beta |
beta_est |
Should beta be estimated? |
alpha_lower |
Lower bound for alpha |
alpha_upper |
Upper bound for alpha |
alpha_est |
Should alpha be estimated? |
s2_lower |
Lower bound for s2 |
s2_upper |
Upper bound for s2 |
s2_est |
Should s2 be estimated? |
useC |
Should C code used? Much faster if implemented. |
R6Class object.
Object of R6Class with methods for fitting GP model.
GauPro::GauPro_kernel -> GauPro::GauPro_kernel_beta -> GauPro_kernel_RatQuad
alphaalpha value (the exponent). Between 0 and 2.
logalphaLog of alpha
logalpha_lowerLower bound for log of alpha
logalpha_upperUpper bound for log of alpha
alpha_estShould alpha be estimated?
new()
Initialize kernel object
RatQuad$new( beta, alpha = 1, s2 = 1, D, beta_lower = -8, beta_upper = 6, beta_est = TRUE, alpha_lower = 1e-08, alpha_upper = 100, alpha_est = TRUE, s2_lower = 1e-08, s2_upper = 1e+08, s2_est = TRUE, useC = TRUE )
betaInitial beta value
alphaInitial alpha value
s2Initial variance
DNumber of input dimensions of data
beta_lowerLower bound for beta
beta_upperUpper bound for beta
beta_estShould beta be estimated?
alpha_lowerLower bound for alpha
alpha_upperUpper bound for alpha
alpha_estShould alpha be estimated?
s2_lowerLower bound for s2
s2_upperUpper bound for s2
s2_estShould s2 be estimated?
useCShould C code used? Much faster if implemented.
k()
Calculate covariance between two points
RatQuad$k( x, y = NULL, beta = self$beta, logalpha = self$logalpha, s2 = self$s2, params = NULL )
xvector.
yvector, optional. If excluded, find correlation of x with itself.
betaCorrelation parameters.
logalphaA correlation parameter
s2Variance parameter.
paramsparameters to use instead of beta and s2.
kone()
Find covariance of two points
RatQuad$kone(x, y, beta, theta, alpha, s2)
xvector
yvector
betacorrelation parameters on log scale
thetacorrelation parameters on regular scale
alphaA correlation parameter
s2Variance parameter
dC_dparams()
Derivative of covariance with respect to parameters
RatQuad$dC_dparams(params = NULL, X, C_nonug, C, nug)
paramsKernel parameters
Xmatrix of points in rows
C_nonugCovariance without nugget added to diagonal
CCovariance with nugget
nugValue of nugget
dC_dx()
Derivative of covariance with respect to X
RatQuad$dC_dx(XX, X, theta, beta = self$beta, alpha = self$alpha, s2 = self$s2)
XXmatrix of points
Xmatrix of points to take derivative with respect to
thetaCorrelation parameters
betalog of theta
alphaparameter
s2Variance parameter
param_optim_start()
Starting point for parameters for optimization
RatQuad$param_optim_start( jitter = F, y, beta_est = self$beta_est, alpha_est = self$alpha_est, s2_est = self$s2_est )
jitterShould there be a jitter?
yOutput
beta_estIs beta being estimated?
alpha_estIs alpha being estimated?
s2_estIs s2 being estimated?
param_optim_start0()
Starting point for parameters for optimization
RatQuad$param_optim_start0( jitter = F, y, beta_est = self$beta_est, alpha_est = self$alpha_est, s2_est = self$s2_est )
jitterShould there be a jitter?
yOutput
beta_estIs beta being estimated?
alpha_estIs alpha being estimated?
s2_estIs s2 being estimated?
param_optim_lower()
Lower bounds of parameters for optimization
RatQuad$param_optim_lower( beta_est = self$beta_est, alpha_est = self$alpha_est, s2_est = self$s2_est )
beta_estIs beta being estimated?
alpha_estIs alpha being estimated?
s2_estIs s2 being estimated?
param_optim_upper()
Upper bounds of parameters for optimization
RatQuad$param_optim_upper( beta_est = self$beta_est, alpha_est = self$alpha_est, s2_est = self$s2_est )
beta_estIs beta being estimated?
alpha_estIs alpha being estimated?
s2_estIs s2 being estimated?
set_params_from_optim()
Set parameters from optimization output
RatQuad$set_params_from_optim( optim_out, beta_est = self$beta_est, alpha_est = self$alpha_est, s2_est = self$s2_est )
optim_outOutput from optimization
beta_estIs beta being estimated?
alpha_estIs alpha being estimated?
s2_estIs s2 being estimated?
print()
Print this object
RatQuad$print()
clone()
The objects of this class are cloneable with this method.
RatQuad$clone(deep = FALSE)
deepWhether to make a deep clone.
k1 <- RatQuad$new(beta=0, alpha=0)k1 <- RatQuad$new(beta=0, alpha=0)
Same thing as 'expm::sqrtm', but faster.
sqrt_matrix(mat, symmetric)sqrt_matrix(mat, symmetric)
mat |
Matrix to find square root matrix of |
symmetric |
Is it symmetric? Passed to eigen. |
Square root of mat
mat <- matrix(c(1,.1,.1,1), 2, 2) smat <- sqrt_matrix(mat=mat, symmetric=TRUE) smat %*% smatmat <- matrix(c(1,.1,.1,1), 2, 2) smat <- sqrt_matrix(mat=mat, symmetric=TRUE) smat %*% smat
Summary for GauPro object
## S3 method for class 'GauPro' summary(object, ...)## S3 method for class 'GauPro' summary(object, ...)
object |
GauPro R6 object |
... |
Additional arguments passed to summary |
Summary
Trend R6 class
Trend R6 class
R6Class object.
Object of R6Class with methods for fitting GP model.
GauPro::GauPro_trend -> GauPro_trend_0
mTrend parameters
m_lowerm lower bound
m_upperm upper bound
m_estShould m be estimated?
new()
Initialize trend object
trend_0$new(m = 0, m_lower = 0, m_upper = 0, m_est = FALSE, D = NA)
mtrend initial parameters
m_lowertrend lower bounds
m_uppertrend upper bounds
m_estLogical of whether each param should be estimated
DNumber of input dimensions of data
Z()
Get trend value for given matrix X
trend_0$Z(X, m = self$m, params = NULL)
Xmatrix of points
mtrend parameters
paramstrend parameters
dZ_dparams()
Derivative of trend with respect to trend parameters
trend_0$dZ_dparams(X, m = m$est, params = NULL)
Xmatrix of points
mtrend values
paramsoverrides m
dZ_dx()
Derivative of trend with respect to X
trend_0$dZ_dx(X, m = self$m, params = NULL)
Xmatrix of points
mtrend values
paramsoverrides m
param_optim_start()
Get parameter initial point for optimization
trend_0$param_optim_start(jitter, trend_est)
jitterNot used
trend_estIf the trend should be estimate.
param_optim_start0()
Get parameter initial point for optimization
trend_0$param_optim_start0(jitter, trend_est)
jitterNot used
trend_estIf the trend should be estimate.
param_optim_lower()
Get parameter lower bounds for optimization
trend_0$param_optim_lower(jitter, trend_est)
jitterNot used
trend_estIf the trend should be estimate.
param_optim_upper()
Get parameter upper bounds for optimization
trend_0$param_optim_upper(jitter, trend_est)
jitterNot used
trend_estIf the trend should be estimate.
set_params_from_optim()
Set parameters after optimization
trend_0$set_params_from_optim(optim_out)
optim_outOutput from optim
clone()
The objects of this class are cloneable with this method.
trend_0$clone(deep = FALSE)
deepWhether to make a deep clone.
t1 <- trend_0$new()t1 <- trend_0$new()
Trend R6 class
Trend R6 class
R6Class object.
Object of R6Class with methods for fitting GP model.
GauPro::GauPro_trend -> GauPro_trend_c
mTrend parameters
m_lowerm lower bound
m_upperm upper bound
m_estShould m be estimated?
new()
Initialize trend object
trend_c$new(m = 0, m_lower = -Inf, m_upper = Inf, m_est = TRUE, D = NA)
mtrend initial parameters
m_lowertrend lower bounds
m_uppertrend upper bounds
m_estLogical of whether each param should be estimated
DNumber of input dimensions of data
Z()
Get trend value for given matrix X
trend_c$Z(X, m = self$m, params = NULL)
Xmatrix of points
mtrend parameters
paramstrend parameters
dZ_dparams()
Derivative of trend with respect to trend parameters
trend_c$dZ_dparams(X, m = self$m, params = NULL)
Xmatrix of points
mtrend values
paramsoverrides m
dZ_dx()
Derivative of trend with respect to X
trend_c$dZ_dx(X, m = self$m, params = NULL)
Xmatrix of points
mtrend values
paramsoverrides m
param_optim_start()
Get parameter initial point for optimization
trend_c$param_optim_start(jitter = F, m_est = self$m_est)
jitterNot used
m_estIf the trend should be estimate.
param_optim_start0()
Get parameter initial point for optimization
trend_c$param_optim_start0(jitter = F, m_est = self$m_est)
jitterNot used
m_estIf the trend should be estimate.
param_optim_lower()
Get parameter lower bounds for optimization
trend_c$param_optim_lower(m_est = self$m_est)
m_estIf the trend should be estimate.
param_optim_upper()
Get parameter upper bounds for optimization
trend_c$param_optim_upper(m_est = self$m_est)
m_estIf the trend should be estimate.
set_params_from_optim()
Set parameters after optimization
trend_c$set_params_from_optim(optim_out)
optim_outOutput from optim
clone()
The objects of this class are cloneable with this method.
trend_c$clone(deep = FALSE)
deepWhether to make a deep clone.
t1 <- trend_c$new()t1 <- trend_c$new()
Trend R6 class
Trend R6 class
R6Class object.
Object of R6Class with methods for fitting GP model.
GauPro::GauPro_trend -> GauPro_trend_LM
mTrend parameters
m_lowerm lower bound
m_upperm upper bound
m_estShould m be estimated?
btrend parameter
b_lowertrend lower bounds
b_uppertrend upper bounds
b_estShould b be estimated?
new()
Initialize trend object
trend_LM$new( D, m = rep(0, D), m_lower = rep(-Inf, D), m_upper = rep(Inf, D), m_est = rep(TRUE, D), b = 0, b_lower = -Inf, b_upper = Inf, b_est = TRUE )
DNumber of input dimensions of data
mtrend initial parameters
m_lowertrend lower bounds
m_uppertrend upper bounds
m_estLogical of whether each param should be estimated
btrend parameter
b_lowertrend lower bounds
b_uppertrend upper bounds
b_estShould b be estimated?
Z()
Get trend value for given matrix X
trend_LM$Z(X, m = self$m, b = self$b, params = NULL)
Xmatrix of points
mtrend parameters
btrend parameters (slopes)
paramstrend parameters
dZ_dparams()
Derivative of trend with respect to trend parameters
trend_LM$dZ_dparams(X, m = self$m_est, b = self$b_est, params = NULL)
Xmatrix of points
mtrend values
btrend intercept
paramsoverrides m
dZ_dx()
Derivative of trend with respect to X
trend_LM$dZ_dx(X, m = self$m, params = NULL)
Xmatrix of points
mtrend values
paramsoverrides m
param_optim_start()
Get parameter initial point for optimization
trend_LM$param_optim_start( jitter = FALSE, b_est = self$b_est, m_est = self$m_est )
jitterNot used
b_estIf the mean should be estimated.
m_estIf the linear terms should be estimated.
param_optim_start0()
Get parameter initial point for optimization
trend_LM$param_optim_start0( jitter = FALSE, b_est = self$b_est, m_est = self$m_est )
jitterNot used
b_estIf the mean should be estimated.
m_estIf the linear terms should be estimated.
param_optim_lower()
Get parameter lower bounds for optimization
trend_LM$param_optim_lower(b_est = self$b_est, m_est = self$m_est)
b_estIf the mean should be estimated.
m_estIf the linear terms should be estimated.
param_optim_upper()
Get parameter upper bounds for optimization
trend_LM$param_optim_upper(b_est = self$b_est, m_est = self$m_est)
b_estIf the mean should be estimated.
m_estIf the linear terms should be estimated.
set_params_from_optim()
Set parameters after optimization
trend_LM$set_params_from_optim(optim_out)
optim_outOutput from optim
clone()
The objects of this class are cloneable with this method.
trend_LM$clone(deep = FALSE)
deepWhether to make a deep clone.
t1 <- trend_LM$new(D=2)t1 <- trend_LM$new(D=2)
Triangle Kernel R6 class
Triangle Kernel R6 class
k_Triangle( beta, s2 = 1, D, beta_lower = -8, beta_upper = 6, beta_est = TRUE, s2_lower = 1e-08, s2_upper = 1e+08, s2_est = TRUE, useC = TRUE, isotropic = FALSE )k_Triangle( beta, s2 = 1, D, beta_lower = -8, beta_upper = 6, beta_est = TRUE, s2_lower = 1e-08, s2_upper = 1e+08, s2_est = TRUE, useC = TRUE, isotropic = FALSE )
beta |
Initial beta value |
s2 |
Initial variance |
D |
Number of input dimensions of data |
beta_lower |
Lower bound for beta |
beta_upper |
Upper bound for beta |
beta_est |
Should beta be estimated? |
s2_lower |
Lower bound for s2 |
s2_upper |
Upper bound for s2 |
s2_est |
Should s2 be estimated? |
useC |
Should C code used? Much faster. |
isotropic |
If isotropic then a single beta/theta is used for all dimensions. If not (anisotropic) then a separate beta/beta is used for each dimension. |
R6Class object.
Object of R6Class with methods for fitting GP model.
GauPro::GauPro_kernel -> GauPro::GauPro_kernel_beta -> GauPro_kernel_Triangle
GauPro::GauPro_kernel$plot()GauPro::GauPro_kernel_beta$C_dC_dparams()GauPro::GauPro_kernel_beta$initialize()GauPro::GauPro_kernel_beta$param_optim_lower()GauPro::GauPro_kernel_beta$param_optim_start()GauPro::GauPro_kernel_beta$param_optim_start0()GauPro::GauPro_kernel_beta$param_optim_upper()GauPro::GauPro_kernel_beta$s2_from_params()GauPro::GauPro_kernel_beta$set_params_from_optim()k()
Calculate covariance between two points
Triangle$k(x, y = NULL, beta = self$beta, s2 = self$s2, params = NULL)
xvector.
yvector, optional. If excluded, find correlation of x with itself.
betaCorrelation parameters.
s2Variance parameter.
paramsparameters to use instead of beta and s2.
kone()
Find covariance of two points
Triangle$kone(x, y, beta, theta, s2)
xvector
yvector
betacorrelation parameters on log scale
thetacorrelation parameters on regular scale
s2Variance parameter
dC_dparams()
Derivative of covariance with respect to parameters
Triangle$dC_dparams(params = NULL, X, C_nonug, C, nug)
paramsKernel parameters
Xmatrix of points in rows
C_nonugCovariance without nugget added to diagonal
CCovariance with nugget
nugValue of nugget
dC_dx()
Derivative of covariance with respect to X
Triangle$dC_dx(XX, X, theta, beta = self$beta, s2 = self$s2)
XXmatrix of points
Xmatrix of points to take derivative with respect to
thetaCorrelation parameters
betalog of theta
s2Variance parameter
print()
Print this object
Triangle$print()
clone()
The objects of this class are cloneable with this method.
Triangle$clone(deep = FALSE)
deepWhether to make a deep clone.
k1 <- Triangle$new(beta=0) plot(k1) 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=Triangle$new(1), parallel=FALSE) gp$predict(.454) gp$plot1D() gp$cool1Dplot()k1 <- Triangle$new(beta=0) plot(k1) 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=Triangle$new(1), parallel=FALSE) gp$predict(.454) gp$plot1D() gp$cool1Dplot()
Initialize kernel object
k_White( s2 = 1, D, s2_lower = 1e-08, s2_upper = 1e+08, s2_est = TRUE, useC = TRUE )k_White( s2 = 1, D, s2_lower = 1e-08, s2_upper = 1e+08, s2_est = TRUE, useC = TRUE )
s2 |
Initial variance |
D |
Number of input dimensions of data |
s2_lower |
Lower bound for s2 |
s2_upper |
Upper bound for s2 |
s2_est |
Should s2 be estimated? |
useC |
Should C code used? Not implemented for White. |
R6Class object.
Object of R6Class with methods for fitting GP model.
GauPro::GauPro_kernel -> GauPro_kernel_White
s2variance
logs2Log of s2
logs2_lowerLower bound of logs2
logs2_upperUpper bound of logs2
s2_estShould s2 be estimated?
new()
Initialize kernel object
White$new( s2 = 1, D, s2_lower = 1e-08, s2_upper = 1e+08, s2_est = TRUE, useC = TRUE )
s2Initial variance
DNumber of input dimensions of data
s2_lowerLower bound for s2
s2_upperUpper bound for s2
s2_estShould s2 be estimated?
useCShould C code used? Not implemented for White.
k()
Calculate covariance between two points
White$k(x, y = NULL, s2 = self$s2, params = NULL)
xvector.
yvector, optional. If excluded, find correlation of x with itself.
s2Variance parameter.
paramsparameters to use instead of beta and s2.
kone()
Find covariance of two points
White$kone(x, y, s2)
xvector
yvector
s2Variance parameter
dC_dparams()
Derivative of covariance with respect to parameters
White$dC_dparams(params = NULL, X, C_nonug, C, nug)
paramsKernel parameters
Xmatrix of points in rows
C_nonugCovariance without nugget added to diagonal
CCovariance with nugget
nugValue of nugget
C_dC_dparams()
Calculate covariance matrix and its derivative with respect to parameters
White$C_dC_dparams(params = NULL, X, nug)
paramsKernel parameters
Xmatrix of points in rows
nugValue of nugget
dC_dx()
Derivative of covariance with respect to X
White$dC_dx(XX, X, s2 = self$s2)
XXmatrix of points
Xmatrix of points to take derivative with respect to
s2Variance parameter
thetaCorrelation parameters
betalog of theta
param_optim_start()
Starting point for parameters for optimization
White$param_optim_start(jitter = F, y, s2_est = self$s2_est)
jitterShould there be a jitter?
yOutput
s2_estIs s2 being estimated?
param_optim_start0()
Starting point for parameters for optimization
White$param_optim_start0(jitter = F, y, s2_est = self$s2_est)
jitterShould there be a jitter?
yOutput
s2_estIs s2 being estimated?
param_optim_lower()
Lower bounds of parameters for optimization
White$param_optim_lower(s2_est = self$s2_est)
s2_estIs s2 being estimated?
param_optim_upper()
Upper bounds of parameters for optimization
White$param_optim_upper(s2_est = self$s2_est)
s2_estIs s2 being estimated?
set_params_from_optim()
Set parameters from optimization output
White$set_params_from_optim(optim_out, s2_est = self$s2_est)
optim_outOutput from optimization
s2_ests2 estimate
s2_from_params()
Get s2 from params vector
White$s2_from_params(params, s2_est = self$s2_est)
paramsparameter vector
s2_estIs s2 being estimated?
print()
Print this object
White$print()
clone()
The objects of this class are cloneable with this method.
White$clone(deep = FALSE)
deepWhether to make a deep clone.
k1 <- White$new(s2=1e-8)k1 <- White$new(s2=1e-8)