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.13.9000 |
Built: | 2024-11-22 02:52:09 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.85
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.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.85
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.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.85
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.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.85
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.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 )
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 )
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. |
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)
x
vector.
y
vector, optional. If excluded, find correlation of x with itself.
beta
Correlation parameters.
s2
Variance parameter.
params
parameters to use instead of beta and s2.
kone()
Find covariance of two points
Cubic$kone(x, y, beta, theta, s2)
x
vector
y
vector
beta
correlation parameters on log scale
theta
correlation parameters on regular scale
s2
Variance parameter
dC_dparams()
Derivative of covariance with respect to parameters
Cubic$dC_dparams(params = NULL, X, C_nonug, C, nug)
params
Kernel parameters
X
matrix of points in rows
C_nonug
Covariance without nugget added to diagonal
C
Covariance with nugget
nug
Value of nugget
dC_dx()
Derivative of covariance with respect to X
Cubic$dC_dx(XX, X, theta, beta = self$beta, s2 = self$s2)
XX
matrix of points
X
matrix of points to take derivative with respect to
theta
Correlation parameters
beta
log of theta
s2
Variance parameter
print()
Print this object
Cubic$print()
clone()
The objects of this class are cloneable with this method.
Cubic$clone(deep = FALSE)
deep
Whether 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 )
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 )
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. |
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)
x
vector.
y
vector, optional. If excluded, find correlation of x with itself.
beta
Correlation parameters.
s2
Variance parameter.
params
parameters to use instead of beta and s2.
kone()
Find covariance of two points
Exponential$kone(x, y, beta, theta, s2)
x
vector
y
vector
beta
correlation parameters on log scale
theta
correlation parameters on regular scale
s2
Variance parameter
dC_dparams()
Derivative of covariance with respect to parameters
Exponential$dC_dparams(params = NULL, X, C_nonug, C, nug)
params
Kernel parameters
X
matrix of points in rows
C_nonug
Covariance without nugget added to diagonal
C
Covariance with nugget
nug
Value of nugget
dC_dx()
Derivative of covariance with respect to X
Exponential$dC_dx(XX, X, theta, beta = self$beta, s2 = self$s2)
XX
matrix of points
X
matrix of points to take derivative with respect to
theta
Correlation parameters
beta
log of theta
s2
Variance parameter
print()
Print this object
Exponential$print()
clone()
The objects of this class are cloneable with this method.
Exponential$clone(deep = FALSE)
deep
Whether 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
p
Parameter for correlation
p_est
Should p be estimated?
p_lower
Lower bound of p
p_upper
Upper bound of p
p_length
length of p
s2
variance
s2_est
Is s2 estimated?
logs2
Log of s2
logs2_lower
Lower bound of logs2
logs2_upper
Upper bound of logs2
xindex
Index of the factor (which column of X)
nlevels
Number of levels for the factor
offdiagequal
What 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 )
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.
k()
Calculate covariance between two points
FactorKernel$k(x, y = NULL, p = self$p, s2 = self$s2, params = NULL)
x
vector.
y
vector, optional. If excluded, find correlation of x with itself.
p
Correlation parameters.
s2
Variance parameter.
params
parameters to use instead of beta and s2.
kone()
Find covariance of two points
FactorKernel$kone(x, y, p, s2, isdiag = TRUE, offdiagequal = self$offdiagequal)
x
vector
y
vector
p
correlation parameters on regular scale
s2
Variance parameter
isdiag
Is this on the diagonal of the covariance?
offdiagequal
What 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)
params
Kernel parameters
X
matrix of points in rows
C_nonug
Covariance without nugget added to diagonal
C
Covariance with nugget
nug
Value of nugget
C_dC_dparams()
Calculate covariance matrix and its derivative with respect to parameters
FactorKernel$C_dC_dparams(params = NULL, X, nug)
params
Kernel parameters
X
matrix of points in rows
nug
Value of nugget
dC_dx()
Derivative of covariance with respect to X
FactorKernel$dC_dx(XX, X, ...)
XX
matrix of points
X
matrix 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 )
jitter
Should there be a jitter?
y
Output
p_est
Is p being estimated?
s2_est
Is 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 )
jitter
Should there be a jitter?
y
Output
p_est
Is p being estimated?
s2_est
Is 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_est
Is p being estimated?
s2_est
Is 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_est
Is p being estimated?
s2_est
Is 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_out
Output from optimization
p_est
Is p being estimated?
s2_est
Is s2 being estimated?
s2_from_params()
Get s2 from params vector
FactorKernel$s2_from_params(params, s2_est = self$s2_est)
params
parameter vector
s2_est
Is s2 being estimated?
print()
Print this object
FactorKernel$print()
clone()
The objects of this class are cloneable with this method.
FactorKernel$clone(deep = FALSE)
deep
Whether 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.
X
Design matrix
Z
Responses
N
Number of data points
D
Dimension of data
nug.min
Minimum value of nugget
nug
Value of the nugget, is estimated unless told otherwise
verbose
0 means nothing printed, 1 prints some, 2 prints most.
useGrad
Should grad be used?
useC
Should C code be used?
parallel
Should the code be run in parallel?
parallel_cores
How many cores are there? It will self detect, do not set yourself.
nug.est
Should the nugget be estimated?
param.est
Should the parameters be estimated?
mu_hat
Mean estimate
s2_hat
Variance estimate
K
Covariance matrix
Kchol
Cholesky factorization of K
Kinv
Inverse 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, ... )
X
Matrix whose rows are the input points
Z
Output points corresponding to X
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.
nug
Value for the nugget. The starting value if estimating it.
nug.min
Minimum allowable value for the nugget.
nug.est
Should the nugget be estimated?
param.est
Should 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)
X
Not used
Z
Not 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)
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
pred()
Predict mean and se for given matrix
GauPro_base$pred(XX, se.fit = F, covmat = F, split_speed = T)
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
pred_one_matrix()
Predict mean and se for given matrix
GauPro_base$pred_one_matrix(XX, se.fit = F, covmat = F)
XX
Points to predict at
se.fit
Should the se be returned?
covmat
Should the covariance matrix be returned?
pred_mean()
Predict mean
GauPro_base$pred_mean(XX, kx.xx)
XX
Points to predict at
kx.xx
Covariance matrix between X and XX
pred_meanC()
Predict mean using C code
GauPro_base$pred_meanC(XX, kx.xx)
XX
Points to predict at
kx.xx
Covariance matrix between X and XX
pred_var()
Predict variance
GauPro_base$pred_var(XX, kxx, kx.xx, covmat = F)
XX
Points to predict at
kxx
Covariance matrix of XX with itself
kx.xx
Covariance matrix between X and XX
covmat
Not used
pred_LOO()
Predict at X using leave-one-out. Can use for diagnostics.
GauPro_base$pred_LOO(se.fit = FALSE)
se.fit
Should 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 )
n2
Number of things to plot
nn
Number of things to plot
col2
color
xlab
x label
ylab
y label
xmin
xmin
xmax
xmax
ymin
ymin
ymax
ymax
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 )
n2
Number of things to plot
nn
Number of things to plot
col2
Color of the prediction interval
xlab
x label
ylab
y label
xmin
xmin
xmax
xmax
ymin
ymin
ymax
ymax
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)
mu
Mean vector
s2
s2 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 )
restarts
Number of restarts to do
param_update
Should parameters be updated?
nug.update
Should nugget be updated?
parallel
Should restarts be done in parallel?
parallel_cores
If 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.par
Starting parameters
start.par0
Starting parameters
param_update
Should parameters be updated?
nug.update
Should nugget be updated?
optim.func
Function to optimize.
optim.grad
Gradient of function to optimize.
optim.fngr
Function that returns the function value and its gradient.
lower
Lower bounds for optimization
upper
Upper bounds for optimization
jit
Is 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 )
Xnew
New X matrix
Znew
New Z values
Xall
Matrix with all X values
Zall
All Z values
restarts
Number of optimization restarts
param_update
Should the parameters be updated?
nug.update
Should the nugget be updated?
no_update
Should none of the parameters/nugget be updated?
update_data()
Update the data
GauPro_base$update_data(Xnew = NULL, Znew = NULL, Xall = NULL, Zall = NULL)
Xnew
New X matrix
Znew
New Z values
Xall
Matrix with all X values
Zall
All 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)
XX
Points to calculate at
sample()
Sample at XX
GauPro_base$sample(XX, n = 1)
XX
Input points to sample at
n
Number of samples
print()
Print object
GauPro_base$print()
clone()
The objects of this class are cloneable with this method.
GauPro_base$clone(deep = FALSE)
deep
Whether 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
-> GauPro_Gauss
corr
Name of correlation
theta
Correlation parameters
theta_length
Length of theta
theta_map
Map for theta
theta_short
Short vector for theta
separable
Are the dimensions separable?
GauPro::GauPro$cool1Dplot()
GauPro::GauPro$deviance_searchnug()
GauPro::GauPro$fit()
GauPro::GauPro$grad_norm()
GauPro::GauPro$initialize_GauPr()
GauPro::GauPro$loglikelihood()
GauPro::GauPro$nugget_update()
GauPro::GauPro$optim()
GauPro::GauPro$optimRestart()
GauPro::GauPro$plot()
GauPro::GauPro$plot1D()
GauPro::GauPro$plot2D()
GauPro::GauPro$pred()
GauPro::GauPro$pred_LOO()
GauPro::GauPro$pred_mean()
GauPro::GauPro$pred_meanC()
GauPro::GauPro$pred_one_matrix()
GauPro::GauPro$pred_var()
GauPro::GauPro$predict()
GauPro::GauPro$sample()
GauPro::GauPro$update()
GauPro::GauPro$update_K_and_estimates()
GauPro::GauPro$update_corrparams()
GauPro::GauPro$update_data()
GauPro::GauPro$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, ... )
X
Matrix whose rows are the input points
Z
Output points corresponding to X
verbose
Amount of stuff to print. 0 is little, 2 is a lot.
separable
Are dimensions separable?
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.
nug
Value for the nugget. The starting value if estimating it.
nug.min
Minimum allowable value for the nugget.
nug.est
Should the nugget be estimated?
param.est
Should the kernel parameters be estimated?
theta
Correlation parameters
theta_short
Correlation parameters, not recommended
theta_map
Correlation parameters, not recommended
...
Not used
corr_func()
Correlation function
GauPro_Gauss$corr_func(x, x2 = NULL, theta = self$theta)
x
First point
x2
Second point
theta
Correlation parameter
deviance_theta()
Calculate deviance
GauPro_Gauss$deviance_theta(theta)
theta
Correlation parameter
deviance_theta_log()
Calculate deviance
GauPro_Gauss$deviance_theta_log(beta)
beta
Correlation parameter on log scale
deviance()
Calculate deviance
GauPro_Gauss$deviance(theta = self$theta, nug = self$nug)
theta
Correlation parameter
nug
Nugget
deviance_grad()
Calculate deviance gradient
GauPro_Gauss$deviance_grad( theta = NULL, nug = self$nug, joint = NULL, overwhat = if (self$nug.est) "joint" else "theta" )
theta
Correlation parameter
nug
Nugget
joint
Calculate over theta and nug at same time?
overwhat
Calculate 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" )
theta
Correlation parameter
nug
Nugget
overwhat
Calculate over theta and nug at same time?
joint
Calculate over theta and nug at same time?
deviance_log()
Calculate deviance gradient
GauPro_Gauss$deviance_log(beta = NULL, nug = self$nug, joint = NULL)
beta
Correlation parameter on log scale
nug
Nugget
joint
Calculate over theta and nug at same time?
deviance_log2()
Calculate deviance on log scale
GauPro_Gauss$deviance_log2(beta = NULL, lognug = NULL, joint = NULL)
beta
Correlation parameter on log scale
lognug
Log of nugget
joint
Calculate 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" )
beta
Correlation parameter
nug
Nugget
joint
Calculate over theta and nug at same time?
overwhat
Calculate 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" )
beta
Correlation parameter
lognug
Log of nugget
joint
Calculate over theta and nug at same time?
overwhat
Calculate 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" )
beta
Correlation parameter
lognug
Log of nugget
joint
Calculate over theta and nug at same time?
overwhat
Calculate over theta and nug at same time?
get_optim_functions()
Get optimization functions
GauPro_Gauss$get_optim_functions(param_update, nug.update)
param_update
Should the parameters be updated?
nug.update
Should 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_value
param value to add jitter to
update_params()
Update value of params after optim
GauPro_Gauss$update_params(restarts, param_update, nug.update)
restarts
Number of restarts
param_update
Are the params being updated?
nug.update
Is the nugget being updated?
grad()
Calculate the gradient
GauPro_Gauss$grad(XX)
XX
Points to calculate grad at
grad_dist()
Calculate the gradient distribution
GauPro_Gauss$grad_dist(XX)
XX
Points to calculate grad at
hessian()
Calculate the hessian
GauPro_Gauss$hessian(XX, useC = self$useC)
XX
Points to calculate grad at
useC
Should 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)
deep
Whether 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
-> GauPro::GauPro_Gauss
-> GauPro_Gauss_LOO
use_LOO
Should the leave-one-out correction be used?
tmod
Second GP model fit to the t-values of leave-one-out predictions
GauPro::GauPro$cool1Dplot()
GauPro::GauPro$deviance_searchnug()
GauPro::GauPro$fit()
GauPro::GauPro$grad_norm()
GauPro::GauPro$initialize_GauPr()
GauPro::GauPro$loglikelihood()
GauPro::GauPro$nugget_update()
GauPro::GauPro$optim()
GauPro::GauPro$optimRestart()
GauPro::GauPro$plot()
GauPro::GauPro$plot1D()
GauPro::GauPro$plot2D()
GauPro::GauPro$pred()
GauPro::GauPro$pred_LOO()
GauPro::GauPro$pred_mean()
GauPro::GauPro$pred_meanC()
GauPro::GauPro$pred_var()
GauPro::GauPro$predict()
GauPro::GauPro$sample()
GauPro::GauPro$update_K_and_estimates()
GauPro::GauPro$update_corrparams()
GauPro::GauPro$update_data()
GauPro::GauPro$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 )
Xnew
New X matrix
Znew
New Z values
Xall
Matrix with all X values
Zall
All Z values
restarts
Number of optimization restarts
param_update
Should the parameters be updated?
nug.update
Should the nugget be updated?
no_update
Should 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)
XX
Points to predict at
se.fit
Should the se be returned?
covmat
Should 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)
deep
Whether 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.
D
Number of input dimensions of data
useC
Should C code be used when possible? Can be much faster.
plot()
Plot kernel decay.
GauPro_kernel$plot(X = NULL)
X
Matrix 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)
deep
Whether 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
beta
Parameter for correlation. Log of theta.
beta_est
Should beta be estimated?
beta_lower
Lower bound of beta
beta_upper
Upper bound of beta
beta_length
length of beta
s2
variance
logs2
Log of s2
logs2_lower
Lower bound of logs2
logs2_upper
Upper bound of logs2
s2_est
Should s2 be estimated?
useC
Should C code used? Much faster.
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 )
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.
k()
Calculate covariance between two points
GauPro_kernel_beta$k( x, y = NULL, beta = self$beta, s2 = self$s2, params = NULL )
x
vector.
y
vector, optional. If excluded, find correlation of x with itself.
beta
Correlation parameters. Log of theta.
s2
Variance parameter.
params
parameters to use instead of beta and s2.
kone()
Calculate covariance between two points
GauPro_kernel_beta$kone(x, y, beta, theta, s2)
x
vector.
y
vector.
beta
Correlation parameters. Log of theta.
theta
Correlation parameters.
s2
Variance 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 )
jitter
Should there be a jitter?
y
Output
beta_est
Is beta being estimated?
s2_est
Is 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 )
jitter
Should there be a jitter?
y
Output
beta_est
Is beta being estimated?
s2_est
Is 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_est
Is beta being estimated?
s2_est
Is s2 being estimated?
p_est
Is 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_est
Is beta being estimated?
s2_est
Is s2 being estimated?
p_est
Is 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_out
Output from optimization
beta_est
Is beta being estimated?
s2_est
Is 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)
params
Kernel parameters
X
matrix of points in rows
nug
Value of nugget
s2_from_params()
Get s2 from params vector
GauPro_kernel_beta$s2_from_params(params, s2_est = self$s2_est)
params
parameter vector
s2_est
Is s2 being estimated?
clone()
The objects of this class are cloneable with this method.
GauPro_kernel_beta$clone(deep = FALSE)
deep
Whether 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.
X
Design matrix
Z
Responses
N
Number of data points
D
Dimension of data
nug.min
Minimum value of nugget
nug.max
Maximum value of the nugget.
nug.est
Should the nugget be estimated?
nug
Value of the nugget, is estimated unless told otherwise
param.est
Should the kernel parameters be estimated?
verbose
0 means nothing printed, 1 prints some, 2 prints most.
useGrad
Should grad be used?
useC
Should C code be used?
parallel
Should the code be run in parallel?
parallel_cores
How many cores are there? By default it detects.
kernel
The kernel to determine the correlations.
trend
The trend.
mu_hatX
Predicted trend value for each point in X.
s2_hat
Variance parameter estimate
K
Covariance matrix
Kchol
Cholesky factorization of K
Kinv
Inverse of K
Kinv_Z_minus_mu_hatX
K inverse times Z minus the predicted trend at X.
restarts
Number of optimization restarts to do when updating.
normalize
Should the inputs be normalized?
normalize_mean
If using normalize, the mean of each column.
normalize_sd
If using normalize, the standard deviation of each column.
optimizer
What algorithm should be used to optimize the parameters.
track_optim
Should it track the parameters evaluated while optimizing?
track_optim_inputs
If track_optim is TRUE, this will keep a list of parameters evaluated. View them with plot_track_optim.
track_optim_dev
If track_optim is TRUE, this will keep a vector of the deviance values calculated while optimizing parameters. View them with plot_track_optim.
formula
Formula
convert_formula_data
List 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, ... )
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
fit()
Fit model
GauPro_kernel_model$fit(X, Z)
X
Inputs
Z
Outputs
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 )
XX
points to predict at
se.fit
Should standard error be returned?
covmat
Should covariance matrix be returned?
split_speed
Should the matrix be split for faster predictions?
mean_dist
Should the error be for the distribution of the mean?
return_df
When 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 )
XX
points to predict at
se.fit
Should standard error be returned?
covmat
Should covariance matrix be returned?
split_speed
Should the matrix be split for faster predictions?
mean_dist
Should the error be for the distribution of the mean?
return_df
When 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 )
XX
points to predict at
se.fit
Should standard error be returned?
covmat
Should covariance matrix be returned?
return_df
When returning se.fit, should it be returned in a data frame? Otherwise it will be a list, which is faster.
mean_dist
Should the error be for the distribution of the mean?
pred_mean()
Predict mean
GauPro_kernel_model$pred_mean(XX, kx.xx)
XX
points to predict at
kx.xx
Covariance of X with XX
pred_meanC()
Predict mean using C
GauPro_kernel_model$pred_meanC(XX, kx.xx)
XX
points to predict at
kx.xx
Covariance of X with XX
pred_var()
Predict variance
GauPro_kernel_model$pred_var(XX, kxx, kx.xx, covmat = F)
XX
points to predict at
kxx
Covariance of XX with itself
kx.xx
Covariance of X with XX
covmat
Should the covariance matrix be returned?
pred_LOO()
leave one out predictions
GauPro_kernel_model$pred_LOO(se.fit = FALSE)
se.fit
Should 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_points
Points to add
pred_points
Points 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_points
Points to add
pred_points
Points to predict at
pred_var_reduction()
Predict variance reduction for a single point
GauPro_kernel_model$pred_var_reduction(add_point, pred_points)
add_point
Point to add
pred_points
Points to predict at
pred_var_reductions()
Predict variance reductions
GauPro_kernel_model$pred_var_reductions(add_points, pred_points)
add_points
Points to add
pred_points
Points 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 )
n2
Number of things to plot
nn
Number of things to plot
col2
color
xlab
x label
ylab
y label
xmin
xmin
xmax
xmax
ymin
ymin
ymax
ymax
gg
Should 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 )
n2
Number of things to plot
nn
Number of things to plot
col2
Color of the prediction interval
col3
Color of the interval for the mean
xlab
x label
ylab
y label
xmin
xmin
xmax
xmax
ymin
ymin
ymax
ymax
gg
Should ggplot2 be used to make plot?
plot2D()
Make 2D plot
GauPro_kernel_model$plot2D(se = FALSE, mean = TRUE, horizontal = TRUE, n = 50)
se
Should the standard error of prediction be plotted?
mean
Should the mean be plotted?
horizontal
If plotting mean and se, should they be next to each other?
n
Number 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)
npt
Number of lines to make. Each line represents changing a single variable while holding the others at the same values.
ncol
Number of columnsfor the plot
plotmarginalrandom()
Plot marginal prediction for random sample of inputs
GauPro_kernel_model$plotmarginalrandom(npt = 100, ncol = NULL)
npt
Number of random points to evaluate
ncol
Number of columns in the plot
plotkernel()
Plot the kernel
GauPro_kernel_model$plotkernel(X = self$X)
X
X 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)
minindex
Minimum index to plot.
loglikelihood()
Calculate loglikelihood of parameters
GauPro_kernel_model$loglikelihood(mu = self$mu_hatX, s2 = self$s2_hat)
mu
Mean parameters
s2
Variance parameter
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_update
Should parameters be updated?
nug.update
Should nugget be updated?
param_optim_lower()
Lower bounds of parameters for optimization
GauPro_kernel_model$param_optim_lower(nug.update)
nug.update
Is the nugget being updated?
param_optim_upper()
Upper bounds of parameters for optimization
GauPro_kernel_model$param_optim_upper(nug.update)
nug.update
Is the nugget being updated?
param_optim_start()
Starting point for parameters for optimization
GauPro_kernel_model$param_optim_start(nug.update, jitter)
nug.update
Is nugget being updated?
jitter
Should there be a jitter?
param_optim_start0()
Starting point for parameters for optimization
GauPro_kernel_model$param_optim_start0(nug.update, jitter)
nug.update
Is nugget being updated?
jitter
Should 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)
restarts
Number of restarts to use
nug.update
Is nugget being updated?
l
Not 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 )
restarts
Number of restarts to do
n0
This many starting parameters are chosen and evaluated. The best ones are used as the starting points for optimization.
param_update
Should parameters be updated?
nug.update
Should nugget be updated?
parallel
Should restarts be done in parallel?
parallel_cores
If 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.par
Starting parameters
start.par0
Starting parameters
param_update
Should parameters be updated?
nug.update
Should nugget be updated?
optim.func
Function to optimize.
optim.grad
Gradient of function to optimize.
optim.fngr
Function that returns the function value and its gradient.
lower
Lower bounds for optimization
upper
Upper bounds for optimization
jit
Is jitter being used?
start.par.i
Starting 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 )
Xnew
New X values to add.
Znew
New Z values to add.
Xall
All X values to be used. Will replace existing X.
Zall
All Z values to be used. Will replace existing Z.
restarts
Number of optimization restarts.
param_update
Are the parameters being updated?
nug.update
Is the nugget being updated?
no_update
Are no parameters being updated?
update_fast()
Fast update when adding new data.
GauPro_kernel_model$update_fast(Xnew = NULL, Znew = NULL)
Xnew
New X values to add.
Znew
New Z values to add.
update_params()
Update the parameters.
GauPro_kernel_model$update_params(..., nug.update)
...
Passed to optim.
nug.update
Is 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 )
Xnew
New X values to add.
Znew
New Z values to add.
Xall
All X values to be used. Will replace existing X.
Zall
All Z values to be used. Will replace existing Z.
update_corrparams()
Update correlation parameters. Not the nugget.
GauPro_kernel_model$update_corrparams(...)
...
Passed to self$update()
update_nugget()
Update nugget Not the correlation parameters.
GauPro_kernel_model$update_nugget(...)
...
Passed to self$update()
deviance()
Calculate the deviance.
GauPro_kernel_model$deviance( params = NULL, nug = self$nug, nuglog, trend_params = NULL )
params
Kernel parameters
nug
Nugget
nuglog
Log of nugget. Only give in nug or nuglog.
trend_params
Parameters 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 )
params
Kernel parameters
kernel_update
Is the kernel being updated? If yes, it's part of the gradient.
X
Input matrix
nug
Nugget
nug.update
Is the nugget being updated? If yes, it's part of the gradient.
nuglog
Log of the nugget.
trend_params
Trend parameters
trend_update
Is 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 )
params
Kernel parameters
kernel_update
Is the kernel being updated? If yes, it's part of the gradient.
X
Input matrix
nug
Nugget
nug.update
Is the nugget being updated? If yes, it's part of the gradient.
nuglog
Log of the nugget.
trend_params
Trend parameters
trend_update
Is 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)
XX
points to calculate at
X
X points
Z
output points
grad_norm()
Calculate norm of gradient
GauPro_kernel_model$grad_norm(XX)
XX
points to calculate at
grad_dist()
Calculate distribution of gradient
GauPro_kernel_model$grad_dist(XX)
XX
points to calculate at
grad_sample()
Sample gradient at points
GauPro_kernel_model$grad_sample(XX, n)
XX
points to calculate at
n
Number of samples
grad_norm2_mean()
Calculate mean of gradient norm squared
GauPro_kernel_model$grad_norm2_mean(XX)
XX
points to calculate at
grad_norm2_dist()
Calculate distribution of gradient norm squared
GauPro_kernel_model$grad_norm2_dist(XX)
XX
points to calculate at
grad_norm2_sample()
Get samples of squared norm of gradient
GauPro_kernel_model$grad_norm2_sample(XX, n)
XX
points to sample at
n
Number of samples
hessian()
Calculate Hessian
GauPro_kernel_model$hessian(XX, as_array = FALSE)
XX
Points to calculate Hessian at
as_array
Should result be an array?
gradpredvar()
Calculate gradient of the predictive variance
GauPro_kernel_model$gradpredvar(XX)
XX
points to calculate at
sample()
Sample at rows of XX
GauPro_kernel_model$sample(XX, n = 1)
XX
Input matrix
n
Number 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 )
fn
Function to optimize
lower
Lower bounds to search within
upper
Upper bounds to search within
n0
Number of points to evaluate in initial stage
minimize
Are you trying to minimize the output?
fn_args
Arguments to pass to the function fn.
gr
Gradient of function to optimize.
fngr
Function 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.
mopar
List of parameters using mixopt
groupeval
Can 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, ...)
x
Vector to calculate EI of, or matrix for whose rows it should be calculated
minimize
Are you trying to minimize the output?
eps
Exploration parameter
return_grad
Should 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 )
lower
Lower bounds to search within
upper
Upper bounds to search within
n0
Number of points to evaluate in initial stage
minimize
Are you trying to minimize the output?
eps
Exploration parameter
dontconvertback
If data was given in with a formula, should it converted back to the original scale?
EItype
Type of EI to calculate. One of "EI", "Augmented", or "Corrected"
mopar
List of parameters using mixopt
usegrad
Should 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 )
npoints
Number of points to add
method
Method 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.
lower
Lower bounds to search within
upper
Upper bounds to search within
n0
Number of points to evaluate in initial stage
minimize
Are you trying to minimize the output?
eps
Exploration parameter
EItype
Type of EI to calculate. One of "EI", "Augmented", or "Corrected"
dontconvertback
If data was given in with a formula, should it converted back to the original scale?
mopar
List of parameters using mixopt
KG()
Calculate Knowledge Gradient
GauPro_kernel_model$KG(x, minimize = FALSE, eps = 0, current_extreme = NULL)
x
Point to calculate at
minimize
Is the objective to minimize?
eps
Exploration parameter
current_extreme
Used for recursive solving
AugmentedEI()
Calculated Augmented EI
GauPro_kernel_model$AugmentedEI( x, minimize = FALSE, eps = 0, return_grad = F, ... )
x
Vector to calculate EI of, or matrix for whose rows it should be calculated
minimize
Are you trying to minimize the output?
eps
Exploration parameter
return_grad
Should the gradient be returned?
...
Additional args
f
The reference max, user shouldn't change this.
CorrectedEI()
Calculated Augmented EI
GauPro_kernel_model$CorrectedEI( x, minimize = FALSE, eps = 0, return_grad = F, ... )
x
Vector to calculate EI of, or matrix for whose rows it should be calculated
minimize
Are you trying to minimize the output?
eps
Exploration parameter
return_grad
Should the gradient be returned?
...
Additional args
importance()
Feature importance
GauPro_kernel_model$importance(plot = TRUE, print_bars = TRUE)
plot
Should the plot be made?
print_bars
Should 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)
deep
Whether 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
tmod
A second GP model for the t-values of leave-one-out predictions
use_LOO
Should 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_kernel
The kernel that should be used for the leave-one-out model. Shouldn't be too smooth.
LOO_options
Options 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 )
Xnew
New X values to add.
Znew
New Z values to add.
Xall
All X values to be used. Will replace existing X.
Zall
All Z values to be used. Will replace existing Z.
restarts
Number of optimization restarts.
param_update
Are the parameters being updated?
nug.update
Is the nugget being updated?
no_update
Are 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 )
XX
points to predict at
se.fit
Should standard error be returned?
covmat
Should covariance matrix be returned?
return_df
When returning se.fit, should it be returned in a data frame?
mean_dist
Should mean distribution be returned?
clone()
The objects of this class are cloneable with this method.
GauPro_kernel_model_LOO$clone(deep = FALSE)
deep
Whether 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.
D
Number of input dimensions of data
clone()
The objects of this class are cloneable with this method.
GauPro_trend$clone(deep = FALSE)
deep
Whether 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 )
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 )
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. |
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)
x
vector.
y
vector, optional. If excluded, find correlation of x with itself.
beta
Correlation parameters.
s2
Variance parameter.
params
parameters to use instead of beta and s2.
kone()
Find covariance of two points
Gaussian$kone(x, y, beta, theta, s2)
x
vector
y
vector
beta
correlation parameters on log scale
theta
correlation parameters on regular scale
s2
Variance parameter
dC_dparams()
Derivative of covariance with respect to parameters
Gaussian$dC_dparams(params = NULL, X, C_nonug, C, nug)
params
Kernel parameters
X
matrix of points in rows
C_nonug
Covariance without nugget added to diagonal
C
Covariance with nugget
nug
Value of nugget
C_dC_dparams()
Calculate covariance matrix and its derivative with respect to parameters
Gaussian$C_dC_dparams(params = NULL, X, nug)
params
Kernel parameters
X
matrix of points in rows
nug
Value of nugget
dC_dx()
Derivative of covariance with respect to X
Gaussian$dC_dx(XX, X, theta, beta = self$beta, s2 = self$s2)
XX
matrix of points
X
matrix of points to take derivative with respect to
theta
Correlation parameters
beta
log of theta
s2
Variance parameter
d2C_dx2()
Second derivative of covariance with respect to X
Gaussian$d2C_dx2(XX, X, theta, beta = self$beta, s2 = self$s2)
XX
matrix of points
X
matrix of points to take derivative with respect to
theta
Correlation parameters
beta
log of theta
s2
Variance 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)
XX
matrix of points
X
matrix of points to take derivative with respect to
theta
Correlation parameters
beta
log of theta
s2
Variance 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)
XX
matrix of points
theta
Correlation parameters
beta
log of theta
s2
Variance parameter
print()
Print this object
Gaussian$print()
clone()
The objects of this class are cloneable with this method.
Gaussian$clone(deep = FALSE)
deep
Whether 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 matrix
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 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 matrix
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 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
p
Parameter for correlation
p_est
Should p be estimated?
p_lower
Lower bound of p
p_upper
Upper bound of p
s2
variance
s2_est
Is s2 estimated?
logs2
Log of s2
logs2_lower
Lower bound of logs2
logs2_upper
Upper bound of logs2
xindex
Index of the factor (which column of X)
nlevels
Number of levels for the factor
offdiagequal
What 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 )
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.
k()
Calculate covariance between two points
GowerFactorKernel$k(x, y = NULL, p = self$p, s2 = self$s2, params = NULL)
x
vector.
y
vector, optional. If excluded, find correlation of x with itself.
p
Correlation parameters.
s2
Variance parameter.
params
parameters to use instead of beta and s2.
kone()
Find covariance of two points
GowerFactorKernel$kone( x, y, p, s2, isdiag = TRUE, offdiagequal = self$offdiagequal )
x
vector
y
vector
p
correlation parameters on regular scale
s2
Variance parameter
isdiag
Is this on the diagonal of the covariance?
offdiagequal
What 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)
params
Kernel parameters
X
matrix of points in rows
C_nonug
Covariance without nugget added to diagonal
C
Covariance with nugget
nug
Value of nugget
C_dC_dparams()
Calculate covariance matrix and its derivative with respect to parameters
GowerFactorKernel$C_dC_dparams(params = NULL, X, nug)
params
Kernel parameters
X
matrix of points in rows
nug
Value of nugget
dC_dx()
Derivative of covariance with respect to X
GowerFactorKernel$dC_dx(XX, X, ...)
XX
matrix of points
X
matrix 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 )
jitter
Should there be a jitter?
y
Output
p_est
Is p being estimated?
s2_est
Is s2 being estimated?
alpha_est
Is 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 )
jitter
Should there be a jitter?
y
Output
p_est
Is p being estimated?
s2_est
Is s2 being estimated?
alpha_est
Is 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_est
Is p being estimated?
s2_est
Is s2 being estimated?
alpha_est
Is 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_est
Is p being estimated?
s2_est
Is s2 being estimated?
alpha_est
Is 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_out
Output from optimization
p_est
Is p being estimated?
s2_est
Is s2 being estimated?
alpha_est
Is alpha being estimated?
s2_from_params()
Get s2 from params vector
GowerFactorKernel$s2_from_params(params, s2_est = self$s2_est)
params
parameter vector
s2_est
Is s2 being estimated?
print()
Print this object
GowerFactorKernel$print()
clone()
The objects of this class are cloneable with this method.
GowerFactorKernel$clone(deep = FALSE)
deep
Whether 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
D
Number of input dimensions of data
kernel
Kernel to use on indices that aren't ignored
ignoreinds
Indices 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_est
Is s2 being estimated?
s2
Value of s2 (variance)
new()
Initialize kernel object
IgnoreIndsKernel$new(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.
k()
Calculate covariance between two points
IgnoreIndsKernel$k(x, y = NULL, ...)
x
vector.
y
vector, optional. If excluded, find correlation of x with itself.
...
Passed to kernel
kone()
Find covariance of two points
IgnoreIndsKernel$kone(x, y, ...)
x
vector
y
vector
...
Passed to kernel
dC_dparams()
Derivative of covariance with respect to parameters
IgnoreIndsKernel$dC_dparams(params = NULL, X, ...)
params
Kernel parameters
X
matrix 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)
params
Kernel parameters
X
matrix of points in rows
nug
Value of nugget
dC_dx()
Derivative of covariance with respect to X
IgnoreIndsKernel$dC_dx(XX, X, ...)
XX
matrix of points
X
matrix 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)
deep
Whether 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
k1
kernel 1
k2
kernel 2
s2
Variance
k1pl
param length of kernel 1
k2pl
param length of kernel 2
s2_est
Is 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)
k1
Kernel 1
k2
Kernel 2
useC
Should C code used? Not applicable for kernel product.
k()
Calculate covariance between two points
kernel_product$k(x, y = NULL, params, ...)
x
vector.
y
vector, optional. If excluded, find correlation of x with itself.
params
parameters 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)
jitter
Should there be a jitter?
y
Output
param_optim_start0()
Starting point for parameters for optimization
kernel_product$param_optim_start0(jitter = F, y)
jitter
Should there be a jitter?
y
Output
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_out
Output from optimization
dC_dparams()
Derivative of covariance with respect to parameters
kernel_product$dC_dparams(params = NULL, C, X, C_nonug, nug)
params
Kernel parameters
C
Covariance with nugget
X
matrix of points in rows
C_nonug
Covariance without nugget added to diagonal
nug
Value of nugget
C_dC_dparams()
Calculate covariance matrix and its derivative with respect to parameters
kernel_product$C_dC_dparams(params = NULL, X, nug)
params
Kernel parameters
X
matrix of points in rows
nug
Value of nugget
dC_dx()
Derivative of covariance with respect to X
kernel_product$dC_dx(XX, X)
XX
matrix of points
X
matrix 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)
params
parameter vector
s2_est
Is 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)
deep
Whether 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
k1
kernel 1
k2
kernel 2
k1_param_length
param length of kernel 1
k2_param_length
param length of kernel 2
k1pl
param length of kernel 1
k2pl
param length of kernel 2
s2
variance
s2_est
Is s2 being estimated?
new()
Initialize kernel
kernel_sum$new(k1, k2, useC = TRUE)
k1
Kernel 1
k2
Kernel 2
useC
Should C code used? Not applicable for kernel sum.
k()
Calculate covariance between two points
kernel_sum$k(x, y = NULL, params, ...)
x
vector.
y
vector, optional. If excluded, find correlation of x with itself.
params
parameters 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)
jitter
Should there be a jitter?
y
Output
param_optim_start0()
Starting point for parameters for optimization
kernel_sum$param_optim_start0(jitter = F, y)
jitter
Should there be a jitter?
y
Output
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_out
Output from optimization
dC_dparams()
Derivative of covariance with respect to parameters
kernel_sum$dC_dparams(params = NULL, C, X, C_nonug, nug)
params
Kernel parameters
C
Covariance with nugget
X
matrix of points in rows
C_nonug
Covariance without nugget added to diagonal
nug
Value of nugget
C_dC_dparams()
Calculate covariance matrix and its derivative with respect to parameters
kernel_sum$C_dC_dparams(params = NULL, X, nug)
params
Kernel parameters
X
matrix of points in rows
nug
Value of nugget
dC_dx()
Derivative of covariance with respect to X
kernel_sum$dC_dx(XX, X)
XX
matrix of points
X
matrix of points to take derivative with respect to
s2_from_params()
Get s2 from params vector
kernel_sum$s2_from_params(params)
params
parameter vector
s2_est
Is 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)
deep
Whether 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
p
Parameter for correlation
p_est
Should p be estimated?
p_lower
Lower bound of p
p_upper
Upper bound of p
p_length
length of p
s2
variance
s2_est
Is s2 estimated?
logs2
Log of s2
logs2_lower
Lower bound of logs2
logs2_upper
Upper bound of logs2
xindex
Index of the factor (which column of X)
nlevels
Number of levels for the factor
latentdim
Dimension of embedding space
pf_to_p_log
Logical vector used to convert pf to p
p_to_pf_inds
Vector of indexes used to convert p to pf
offdiagequal
What 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 )
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.
k()
Calculate covariance between two points
LatentFactorKernel$k(x, y = NULL, p = self$p, s2 = self$s2, params = NULL)
x
vector.
y
vector, optional. If excluded, find correlation of x with itself.
p
Correlation parameters.
s2
Variance parameter.
params
parameters to use instead of beta and s2.
kone()
Find covariance of two points
LatentFactorKernel$kone( x, y, pf, s2, isdiag = TRUE, offdiagequal = self$offdiagequal )
x
vector
y
vector
pf
correlation parameters on regular scale, includes zeroes for first level.
s2
Variance parameter
isdiag
Is this on the diagonal of the covariance?
offdiagequal
What 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)
params
Kernel parameters
X
matrix of points in rows
C_nonug
Covariance without nugget added to diagonal
C
Covariance with nugget
nug
Value of nugget
C_dC_dparams()
Calculate covariance matrix and its derivative with respect to parameters
LatentFactorKernel$C_dC_dparams(params = NULL, X, nug)
params
Kernel parameters
X
matrix of points in rows
nug
Value of nugget
dC_dx()
Derivative of covariance with respect to X
LatentFactorKernel$dC_dx(XX, X, ...)
XX
matrix of points
X
matrix 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 )
jitter
Should there be a jitter?
y
Output
p_est
Is p being estimated?
s2_est
Is 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 )
jitter
Should there be a jitter?
y
Output
p_est
Is p being estimated?
s2_est
Is 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_est
Is p being estimated?
s2_est
Is 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_est
Is p being estimated?
s2_est
Is 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_out
Output from optimization
p_est
Is p being estimated?
s2_est
Is s2 being estimated?
p_to_pf()
Convert p (short parameter vector) to pf (long parameter vector with zeros).
LatentFactorKernel$p_to_pf(p)
p
Parameter vector
s2_from_params()
Get s2 from params vector
LatentFactorKernel$s2_from_params(params, s2_est = self$s2_est)
params
parameter vector
s2_est
Is 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)
deep
Whether 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 )
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 )
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. |
R6Class
object.
Object of R6Class
with methods for fitting GP model.
GauPro::GauPro_kernel
-> GauPro::GauPro_kernel_beta
-> GauPro_kernel_Matern32
sqrt3
Saved 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)
x
vector.
y
vector, optional. If excluded, find correlation of x with itself.
beta
Correlation parameters.
s2
Variance parameter.
params
parameters to use instead of beta and s2.
kone()
Find covariance of two points
Matern32$kone(x, y, beta, theta, s2)
x
vector
y
vector
beta
correlation parameters on log scale
theta
correlation parameters on regular scale
s2
Variance parameter
dC_dparams()
Derivative of covariance with respect to parameters
Matern32$dC_dparams(params = NULL, X, C_nonug, C, nug)
params
Kernel parameters
X
matrix of points in rows
C_nonug
Covariance without nugget added to diagonal
C
Covariance with nugget
nug
Value of nugget
dC_dx()
Derivative of covariance with respect to X
Matern32$dC_dx(XX, X, theta, beta = self$beta, s2 = self$s2)
XX
matrix of points
X
matrix of points to take derivative with respect to
theta
Correlation parameters
beta
log of theta
s2
Variance parameter
print()
Print this object
Matern32$print()
clone()
The objects of this class are cloneable with this method.
Matern32$clone(deep = FALSE)
deep
Whether 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 )
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 )
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. |
R6Class
object.
where
Object of R6Class
with methods for fitting GP model.
GauPro::GauPro_kernel
-> GauPro::GauPro_kernel_beta
-> GauPro_kernel_Matern52
sqrt5
Saved 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)
x
vector.
y
vector, optional. If excluded, find correlation of x with itself.
beta
Correlation parameters.
s2
Variance parameter.
params
parameters to use instead of beta and s2.
kone()
Find covariance of two points
Matern52$kone(x, y, beta, theta, s2)
x
vector
y
vector
beta
correlation parameters on log scale
theta
correlation parameters on regular scale
s2
Variance parameter
dC_dparams()
Derivative of covariance with respect to parameters
Matern52$dC_dparams(params = NULL, X, C_nonug, C, nug)
params
Kernel parameters
X
matrix of points in rows
C_nonug
Covariance without nugget added to diagonal
C
Covariance with nugget
nug
Value of nugget
dC_dx()
Derivative of covariance with respect to X
Matern52$dC_dx(XX, X, theta, beta = self$beta, s2 = self$s2)
XX
matrix of points
X
matrix of points to take derivative with respect to
theta
Correlation parameters
beta
log of theta
s2
Variance parameter
print()
Print this object
Matern52$print()
clone()
The objects of this class are cloneable with this method.
Matern52$clone(deep = FALSE)
deep
Whether 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
p
Parameter for correlation
p_est
Should p be estimated?
p_lower
Lower bound of p
p_upper
Upper bound of p
p_length
length of p
s2
variance
s2_est
Is s2 estimated?
logs2
Log of s2
logs2_lower
Lower bound of logs2
logs2_upper
Upper bound of logs2
xindex
Index of the factor (which column of X)
nlevels
Number of levels for the factor
offdiagequal
What 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 )
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
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.
p
Vector of distances in latent space
k()
Calculate covariance between two points
OrderedFactorKernel$k(x, y = NULL, p = self$p, s2 = self$s2, params = NULL)
x
vector.
y
vector, optional. If excluded, find correlation of x with itself.
p
Correlation parameters.
s2
Variance parameter.
params
parameters to use instead of beta and s2.
kone()
Find covariance of two points
OrderedFactorKernel$kone( x, y, p, s2, isdiag = TRUE, offdiagequal = self$offdiagequal )
x
vector
y
vector
p
correlation parameters on regular scale
s2
Variance parameter
isdiag
Is this on the diagonal of the covariance?
offdiagequal
What 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)
params
Kernel parameters
X
matrix of points in rows
C_nonug
Covariance without nugget added to diagonal
C
Covariance with nugget
nug
Value of nugget
C_dC_dparams()
Calculate covariance matrix and its derivative with respect to parameters
OrderedFactorKernel$C_dC_dparams(params = NULL, X, nug)
params
Kernel parameters
X
matrix of points in rows
nug
Value of nugget
dC_dx()
Derivative of covariance with respect to X
OrderedFactorKernel$dC_dx(XX, X, ...)
XX
matrix of points
X
matrix 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 )
jitter
Should there be a jitter?
y
Output
p_est
Is p being estimated?
s2_est
Is 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 )
jitter
Should there be a jitter?
y
Output
p_est
Is p being estimated?
s2_est
Is 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_est
Is p being estimated?
s2_est
Is 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_est
Is p being estimated?
s2_est
Is 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_out
Output from optimization
p_est
Is p being estimated?
s2_est
Is s2 being estimated?
s2_from_params()
Get s2 from params vector
OrderedFactorKernel$s2_from_params(params, s2_est = self$s2_est)
params
parameter vector
s2_est
Is 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)
deep
Whether 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
p
Parameter for correlation
p_est
Should p be estimated?
logp
Log of p
logp_lower
Lower bound of logp
logp_upper
Upper bound of logp
p_length
length of p
alpha
Parameter for correlation
alpha_est
Should alpha be estimated?
logalpha
Log of alpha
logalpha_lower
Lower bound of logalpha
logalpha_upper
Upper bound of logalpha
s2
variance
s2_est
Is s2 estimated?
logs2
Log of s2
logs2_lower
Lower bound of logs2
logs2_upper
Upper 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 )
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.
k()
Calculate covariance between two points
Periodic$k( x, y = NULL, logp = self$logp, logalpha = self$logalpha, s2 = self$s2, params = NULL )
x
vector.
y
vector, optional. If excluded, find correlation of x with itself.
logp
Correlation parameters.
logalpha
Correlation parameters.
s2
Variance parameter.
params
parameters to use instead of beta and s2.
kone()
Find covariance of two points
Periodic$kone(x, y, logp, p, alpha, s2)
x
vector
y
vector
logp
correlation parameters on log scale
p
correlation parameters on regular scale
alpha
correlation parameter
s2
Variance parameter
dC_dparams()
Derivative of covariance with respect to parameters
Periodic$dC_dparams(params = NULL, X, C_nonug, C, nug)
params
Kernel parameters
X
matrix of points in rows
C_nonug
Covariance without nugget added to diagonal
C
Covariance with nugget
nug
Value of nugget
C_dC_dparams()
Calculate covariance matrix and its derivative with respect to parameters
Periodic$C_dC_dparams(params = NULL, X, nug)
params
Kernel parameters
X
matrix of points in rows
nug
Value 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)
XX
matrix of points
X
matrix of points to take derivative with respect to
logp
log of p
logalpha
log of alpha
s2
Variance 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 )
jitter
Should there be a jitter?
y
Output
p_est
Is p being estimated?
alpha_est
Is alpha being estimated?
s2_est
Is 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 )
jitter
Should there be a jitter?
y
Output
p_est
Is p being estimated?
alpha_est
Is alpha being estimated?
s2_est
Is 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_est
Is p being estimated?
alpha_est
Is alpha being estimated?
s2_est
Is 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_est
Is p being estimated?
alpha_est
Is alpha being estimated?
s2_est
Is 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_out
Output from optimization
p_est
Is p being estimated?
alpha_est
Is alpha being estimated?
s2_est
Is s2 being estimated?
s2_from_params()
Get s2 from params vector
Periodic$s2_from_params(params, s2_est = self$s2_est)
params
parameter vector
s2_est
Is s2 being estimated?
print()
Print this object
Periodic$print()
clone()
The objects of this class are cloneable with this method.
Periodic$clone(deep = FALSE)
deep
Whether 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
alpha
alpha value (the exponent). Between 0 and 2.
alpha_lower
Lower bound for alpha
alpha_upper
Upper bound for alpha
alpha_est
Should 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 )
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.
k()
Calculate covariance between two points
PowerExp$k( x, y = NULL, beta = self$beta, alpha = self$alpha, s2 = self$s2, params = NULL )
x
vector.
y
vector, optional. If excluded, find correlation of x with itself.
beta
Correlation parameters.
alpha
alpha value (the exponent). Between 0 and 2.
s2
Variance parameter.
params
parameters to use instead of beta and s2.
kone()
Find covariance of two points
PowerExp$kone(x, y, beta, theta, alpha, s2)
x
vector
y
vector
beta
correlation parameters on log scale
theta
correlation parameters on regular scale
alpha
alpha value (the exponent). Between 0 and 2.
s2
Variance parameter
dC_dparams()
Derivative of covariance with respect to parameters
PowerExp$dC_dparams(params = NULL, X, C_nonug, C, nug)
params
Kernel parameters
X
matrix of points in rows
C_nonug
Covariance without nugget added to diagonal
C
Covariance with nugget
nug
Value 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 )
XX
matrix of points
X
matrix of points to take derivative with respect to
theta
Correlation parameters
beta
log of theta
alpha
alpha value (the exponent). Between 0 and 2.
s2
Variance 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 )
jitter
Should there be a jitter?
y
Output
beta_est
Is beta being estimated?
alpha_est
Is alpha being estimated?
s2_est
Is 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 )
jitter
Should there be a jitter?
y
Output
beta_est
Is beta being estimated?
alpha_est
Is alpha being estimated?
s2_est
Is 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_est
Is beta being estimated?
alpha_est
Is alpha being estimated?
s2_est
Is 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_est
Is beta being estimated?
alpha_est
Is alpha being estimated?
s2_est
Is 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_out
Output from optimization
beta_est
Is beta estimate?
alpha_est
Is alpha estimated?
s2_est
Is s2 estimated?
print()
Print this object
PowerExp$print()
clone()
The objects of this class are cloneable with this method.
PowerExp$clone(deep = FALSE)
deep
Whether 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)
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
alpha
alpha value (the exponent). Between 0 and 2.
logalpha
Log of alpha
logalpha_lower
Lower bound for log of alpha
logalpha_upper
Upper bound for log of alpha
alpha_est
Should 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 )
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.
k()
Calculate covariance between two points
RatQuad$k( x, y = NULL, beta = self$beta, logalpha = self$logalpha, s2 = self$s2, params = NULL )
x
vector.
y
vector, optional. If excluded, find correlation of x with itself.
beta
Correlation parameters.
logalpha
A correlation parameter
s2
Variance parameter.
params
parameters to use instead of beta and s2.
kone()
Find covariance of two points
RatQuad$kone(x, y, beta, theta, alpha, s2)
x
vector
y
vector
beta
correlation parameters on log scale
theta
correlation parameters on regular scale
alpha
A correlation parameter
s2
Variance parameter
dC_dparams()
Derivative of covariance with respect to parameters
RatQuad$dC_dparams(params = NULL, X, C_nonug, C, nug)
params
Kernel parameters
X
matrix of points in rows
C_nonug
Covariance without nugget added to diagonal
C
Covariance with nugget
nug
Value 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)
XX
matrix of points
X
matrix of points to take derivative with respect to
theta
Correlation parameters
beta
log of theta
alpha
parameter
s2
Variance 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 )
jitter
Should there be a jitter?
y
Output
beta_est
Is beta being estimated?
alpha_est
Is alpha being estimated?
s2_est
Is 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 )
jitter
Should there be a jitter?
y
Output
beta_est
Is beta being estimated?
alpha_est
Is alpha being estimated?
s2_est
Is 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_est
Is beta being estimated?
alpha_est
Is alpha being estimated?
s2_est
Is 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_est
Is beta being estimated?
alpha_est
Is alpha being estimated?
s2_est
Is 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_out
Output from optimization
beta_est
Is beta being estimated?
alpha_est
Is alpha being estimated?
s2_est
Is s2 being estimated?
print()
Print this object
RatQuad$print()
clone()
The objects of this class are cloneable with this method.
RatQuad$clone(deep = FALSE)
deep
Whether 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 %*% smat
mat <- 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
m
Trend parameters
m_lower
m lower bound
m_upper
m upper bound
m_est
Should m be estimated?
new()
Initialize trend object
trend_0$new(m = 0, m_lower = 0, m_upper = 0, m_est = FALSE, D = NA)
m
trend initial parameters
m_lower
trend lower bounds
m_upper
trend upper bounds
m_est
Logical of whether each param should be estimated
D
Number of input dimensions of data
Z()
Get trend value for given matrix X
trend_0$Z(X, m = self$m, params = NULL)
X
matrix of points
m
trend parameters
params
trend parameters
dZ_dparams()
Derivative of trend with respect to trend parameters
trend_0$dZ_dparams(X, m = m$est, params = NULL)
X
matrix of points
m
trend values
params
overrides m
dZ_dx()
Derivative of trend with respect to X
trend_0$dZ_dx(X, m = self$m, params = NULL)
X
matrix of points
m
trend values
params
overrides m
param_optim_start()
Get parameter initial point for optimization
trend_0$param_optim_start(jitter, trend_est)
jitter
Not used
trend_est
If the trend should be estimate.
param_optim_start0()
Get parameter initial point for optimization
trend_0$param_optim_start0(jitter, trend_est)
jitter
Not used
trend_est
If the trend should be estimate.
param_optim_lower()
Get parameter lower bounds for optimization
trend_0$param_optim_lower(jitter, trend_est)
jitter
Not used
trend_est
If the trend should be estimate.
param_optim_upper()
Get parameter upper bounds for optimization
trend_0$param_optim_upper(jitter, trend_est)
jitter
Not used
trend_est
If the trend should be estimate.
set_params_from_optim()
Set parameters after optimization
trend_0$set_params_from_optim(optim_out)
optim_out
Output from optim
clone()
The objects of this class are cloneable with this method.
trend_0$clone(deep = FALSE)
deep
Whether 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
m
Trend parameters
m_lower
m lower bound
m_upper
m upper bound
m_est
Should m be estimated?
new()
Initialize trend object
trend_c$new(m = 0, m_lower = -Inf, m_upper = Inf, m_est = TRUE, D = NA)
m
trend initial parameters
m_lower
trend lower bounds
m_upper
trend upper bounds
m_est
Logical of whether each param should be estimated
D
Number of input dimensions of data
Z()
Get trend value for given matrix X
trend_c$Z(X, m = self$m, params = NULL)
X
matrix of points
m
trend parameters
params
trend parameters
dZ_dparams()
Derivative of trend with respect to trend parameters
trend_c$dZ_dparams(X, m = self$m, params = NULL)
X
matrix of points
m
trend values
params
overrides m
dZ_dx()
Derivative of trend with respect to X
trend_c$dZ_dx(X, m = self$m, params = NULL)
X
matrix of points
m
trend values
params
overrides m
param_optim_start()
Get parameter initial point for optimization
trend_c$param_optim_start(jitter = F, m_est = self$m_est)
jitter
Not used
m_est
If 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)
jitter
Not used
m_est
If 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_est
If 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_est
If the trend should be estimate.
set_params_from_optim()
Set parameters after optimization
trend_c$set_params_from_optim(optim_out)
optim_out
Output from optim
clone()
The objects of this class are cloneable with this method.
trend_c$clone(deep = FALSE)
deep
Whether 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
m
Trend parameters
m_lower
m lower bound
m_upper
m upper bound
m_est
Should m be estimated?
b
trend parameter
b_lower
trend lower bounds
b_upper
trend upper bounds
b_est
Should 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 )
D
Number of input dimensions of data
m
trend initial parameters
m_lower
trend lower bounds
m_upper
trend upper bounds
m_est
Logical of whether each param should be estimated
b
trend parameter
b_lower
trend lower bounds
b_upper
trend upper bounds
b_est
Should b be estimated?
Z()
Get trend value for given matrix X
trend_LM$Z(X, m = self$m, b = self$b, params = NULL)
X
matrix of points
m
trend parameters
b
trend parameters (slopes)
params
trend 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)
X
matrix of points
m
trend values
b
trend intercept
params
overrides m
dZ_dx()
Derivative of trend with respect to X
trend_LM$dZ_dx(X, m = self$m, params = NULL)
X
matrix of points
m
trend values
params
overrides 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 )
jitter
Not used
b_est
If the mean should be estimated.
m_est
If 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 )
jitter
Not used
b_est
If the mean should be estimated.
m_est
If 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_est
If the mean should be estimated.
m_est
If 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_est
If the mean should be estimated.
m_est
If the linear terms should be estimated.
set_params_from_optim()
Set parameters after optimization
trend_LM$set_params_from_optim(optim_out)
optim_out
Output from optim
clone()
The objects of this class are cloneable with this method.
trend_LM$clone(deep = FALSE)
deep
Whether 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 )
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 )
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. |
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)
x
vector.
y
vector, optional. If excluded, find correlation of x with itself.
beta
Correlation parameters.
s2
Variance parameter.
params
parameters to use instead of beta and s2.
kone()
Find covariance of two points
Triangle$kone(x, y, beta, theta, s2)
x
vector
y
vector
beta
correlation parameters on log scale
theta
correlation parameters on regular scale
s2
Variance parameter
dC_dparams()
Derivative of covariance with respect to parameters
Triangle$dC_dparams(params = NULL, X, C_nonug, C, nug)
params
Kernel parameters
X
matrix of points in rows
C_nonug
Covariance without nugget added to diagonal
C
Covariance with nugget
nug
Value of nugget
dC_dx()
Derivative of covariance with respect to X
Triangle$dC_dx(XX, X, theta, beta = self$beta, s2 = self$s2)
XX
matrix of points
X
matrix of points to take derivative with respect to
theta
Correlation parameters
beta
log of theta
s2
Variance parameter
print()
Print this object
Triangle$print()
clone()
The objects of this class are cloneable with this method.
Triangle$clone(deep = FALSE)
deep
Whether 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
s2
variance
logs2
Log of s2
logs2_lower
Lower bound of logs2
logs2_upper
Upper bound of logs2
s2_est
Should 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 )
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.
k()
Calculate covariance between two points
White$k(x, y = NULL, s2 = self$s2, params = NULL)
x
vector.
y
vector, optional. If excluded, find correlation of x with itself.
s2
Variance parameter.
params
parameters to use instead of beta and s2.
kone()
Find covariance of two points
White$kone(x, y, s2)
x
vector
y
vector
s2
Variance parameter
dC_dparams()
Derivative of covariance with respect to parameters
White$dC_dparams(params = NULL, X, C_nonug, C, nug)
params
Kernel parameters
X
matrix of points in rows
C_nonug
Covariance without nugget added to diagonal
C
Covariance with nugget
nug
Value of nugget
C_dC_dparams()
Calculate covariance matrix and its derivative with respect to parameters
White$C_dC_dparams(params = NULL, X, nug)
params
Kernel parameters
X
matrix of points in rows
nug
Value of nugget
dC_dx()
Derivative of covariance with respect to X
White$dC_dx(XX, X, s2 = self$s2)
XX
matrix of points
X
matrix of points to take derivative with respect to
s2
Variance parameter
theta
Correlation parameters
beta
log of theta
param_optim_start()
Starting point for parameters for optimization
White$param_optim_start(jitter = F, y, s2_est = self$s2_est)
jitter
Should there be a jitter?
y
Output
s2_est
Is s2 being estimated?
param_optim_start0()
Starting point for parameters for optimization
White$param_optim_start0(jitter = F, y, s2_est = self$s2_est)
jitter
Should there be a jitter?
y
Output
s2_est
Is s2 being estimated?
param_optim_lower()
Lower bounds of parameters for optimization
White$param_optim_lower(s2_est = self$s2_est)
s2_est
Is s2 being estimated?
param_optim_upper()
Upper bounds of parameters for optimization
White$param_optim_upper(s2_est = self$s2_est)
s2_est
Is 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_out
Output from optimization
s2_est
s2 estimate
s2_from_params()
Get s2 from params vector
White$s2_from_params(params, s2_est = self$s2_est)
params
parameter vector
s2_est
Is s2 being estimated?
print()
Print this object
White$print()
clone()
The objects of this class are cloneable with this method.
White$clone(deep = FALSE)
deep
Whether to make a deep clone.
k1 <- White$new(s2=1e-8)
k1 <- White$new(s2=1e-8)