Title: | Gaussian Process for Functional Data Analysis |
---|---|
Description: | Functionalities for modelling functional data with multidimensional inputs, multivariate functional data, and non-separable and/or non-stationary covariance structure of function-valued processes. In addition, there are functionalities for functional regression models where the mean function depends on scalar and/or functional covariates and the covariance structure depends on functional covariates. The development version of the package can be found on <https://github.com/gpfda/GPFDA-dev>. |
Authors: | Jian Qing Shi, Yafeng Cheng, Evandro Konzen |
Maintainer: | Evandro Konzen <[email protected]> |
License: | GPL-3 |
Version: | 3.1.3 |
Built: | 2024-10-31 07:00:10 UTC |
Source: | CRAN |
Calculates matrices 'ScaleMat' and 'DistMat', which are used to obtain NSGP covariance matrices
calcScaleDistMats(A_List, coords)
calcScaleDistMats(A_List, coords)
A_List |
List of anisotropy matrices |
coords |
Matrix of input coordinates (covariates) |
A list of ScaleMat and DistMat matrices
## See examples in vignette: # vignette("nsgpr", package = "GPFDA")
## See examples in vignette: # vignette("nsgpr", package = "GPFDA")
Evaluates one of the following covariance functions at input vectors t and t':
Powered exponential
Rational quadratic
Matern
Linear
cov.pow.ex(hyper, input, inputNew = NULL, gamma = 2) cov.rat.qu(hyper, input, inputNew = NULL) cov.matern(hyper, input, inputNew = NULL, nu) cov.linear(hyper, input, inputNew = NULL)
cov.pow.ex(hyper, input, inputNew = NULL, gamma = 2) cov.rat.qu(hyper, input, inputNew = NULL) cov.matern(hyper, input, inputNew = NULL, nu) cov.linear(hyper, input, inputNew = NULL)
hyper |
The hyperparameters. It must be a list with certain names. See details. |
input |
The covariate t. It must be either a matrix, where each column represents a covariate, or a vector if there is only one covariate. |
inputNew |
The covariate t'. It also must be a vector or a matrix. If NULL (default), 'inputNew' will be set to be equal to ‘input’ and the function will return a squared, symmetric covariance matrix. |
gamma |
Power parameter used in powered exponential kernel function. It must be 0<gamma<=2. Default to 2, which gives the squared exponential covariance function. |
nu |
Smoothness parameter of the Matern class. It must be a positive value. |
The names for the hyperparameters should be:
"pow.ex.v" and "pow.ex.w" (powered exponential);
"rat.qu.v", "rat.qu.w" and "rat.qu.a" (rational quadratic);
"matern.v" and "matern.w" (Matern);
"linear.i" and "linear.a" (linear);
"vv" (Gaussian white noise).
A covariance matrix
Shi, J. Q., and Choi, T. (2011), “Gaussian Process Regression Analysis for Functional input”, CRC Press.
Calculate the second derivative of the likelihood function with respect to one of the hyperparameters, given the first and second derivative of the kernel with respect to that hyperparameter.
D2(d1, d2, inv.Q, Alpha.Q)
D2(d1, d2, inv.Q, Alpha.Q)
d1 |
First derivative of the kernel function with respect to the required hyperparameter. |
d2 |
Second derivative of the kernel function with respect to the required hyperparameter. |
inv.Q |
Inverse of covariance matrix Q. |
Alpha.Q |
This is alpha * alpha'- invQ, where invQ is the inverse of the covariance matrix Q, and alpha = invQ * Y, where Y is the response. |
The function calculates the second derivative of the log-likelihood, using the first and second derivative of the kernel functions.
A number.
Shi, J. Q., and Choi, T. (2011), “Gaussian Process Regression Analysis for Functional Data”, CRC Press.
## This function is used in the vignette 'co2': # vignette("co2", package = "GPFDA")
## This function is used in the vignette 'co2': # vignette("co2", package = "GPFDA")
A list containing training and test data simulated from a functional
regression model.
In the training set, there are M=20 independent realisations and
the functional response and the functional covariate are observed on a grid
of n=20 time points.
The test set includes a single realisation observed on a grid of n_new=60
time points.
Both training and test sets also have a scalar covariate.
dataExampleGPFR
dataExampleGPFR
A list with seven elements:
A vector of length 50
A (20 x 50) matrix
A (20 x 50) matrix
A (20 x 2) matrix
A vector of length 60
A vector of length 60
A vector of length 60
A (1 x 2) matrix
Data used in the GPFR example, see vignette("gpfr").
A list containing data simulated from a MGPR model.
The dataset contains 30 realisations from a trivariate process. Each of the
three functions is observed on 250 time points on [0,1].
dataExampleMGPR
dataExampleMGPR
A list with two elements:
List of 3 numeric vectors, each one being the time points where the corresponding function is observed.
List of 3 matrices containing the observed 250 datapoints. Each column is an independent realisation.
Data used in the MGPR example, see vignette("mgpr").
Calculate the generalised distance between vectors t and t' using an anisotropy matrix A.
distMat
and distMatSq
calculate:
distMatLinear
and distMatLinearSq
calculate:
distMat(input, inputNew, A, power) distMatSq(input, A, power) distMatLinear(input, inputNew, A) distMatLinearSq(input, A)
distMat(input, inputNew, A, power) distMatSq(input, A, power) distMatLinear(input, inputNew, A) distMatLinearSq(input, A)
input |
Vector of the input coordinate t |
inputNew |
Vector of the input coordinate t' |
A |
Anisotropy matrix A |
power |
Power value p |
The distMatSq
and distMatLinearSq
functions are
used when input vectors t and t' are identical, returning a symmetric matrix.
When distMat
and distMatSq
functions are used in
powered exponential kernels, power=1 gives the exponential kernel and
power=2 gives the squared exponential one. distMatLinear
and distMatLinearSq
functions are used in the
linear covariance kernel.
A matrix
Use functional regression (FR) model for the mean structure and Gaussian
Process (GP) for the covariance structure.
Let 'n' be the number of
time points 't' of functional objects and 'nrep' the number of independent
replications in the sample.
gpfr( response, time = NULL, uReg = NULL, fxReg = NULL, fyList = NULL, uCoefList = NULL, fxList = NULL, concurrent = TRUE, fxCoefList = NULL, gpReg = NULL, hyper = NULL, NewHyper = NULL, Cov = "pow.ex", gamma = 2, nu = 1.5, useGradient = T, rel.tol = 1e-10, trace.iter = 5, fitting = FALSE )
gpfr( response, time = NULL, uReg = NULL, fxReg = NULL, fyList = NULL, uCoefList = NULL, fxList = NULL, concurrent = TRUE, fxCoefList = NULL, gpReg = NULL, hyper = NULL, NewHyper = NULL, Cov = "pow.ex", gamma = 2, nu = 1.5, useGradient = T, rel.tol = 1e-10, trace.iter = 5, fitting = FALSE )
response |
Response data. It can be an 'fd' object or a matrix with 'nrep' rows and 'n' columns. |
time |
Input 't' of functional objects. It is a numeric vector of length 'n'. |
uReg |
Scalar covariates for the FR model. It should be a matrix with 'nrep' rows. |
fxReg |
Functional covariates for the FR model. It can be a matrix with 'nrep' rows and 'n' columns, an 'fd' object, or a list of matrices or 'fd' objects. |
fyList |
A list to control the smoothing of response. |
uCoefList |
A list to control the smoothing of the regression coefficient function of the scalar covariates in the FR model. |
fxList |
A list to control the smoothing of functional covariates in the FR model. |
concurrent |
Logical. If TRUE (default), concurrent functional regression will be carried out; otherwise, the full functional regression will be carried out. |
fxCoefList |
A list to control the smoothing of the regression coefficient function of functional covariates in the functional concurrent model. |
gpReg |
Covariates in the GP model. It should be a matrix, a numeric vector, an 'fd' object, a list of matrices or a list of 'fd' objects. |
hyper |
Vector of initial hyperparameters. Default to NULL. |
NewHyper |
Vector of names of new hyperparameters from the customized kernel function. |
Cov |
Covariance function(s) to use. Options are: 'linear', 'pow.ex', 'rat.qu', and 'matern'. Default to 'power.ex'. |
gamma |
Power parameter used in powered exponential kernel function. It must be 0<gamma<=2. |
nu |
Smoothness parameter of the Matern class. It must be a positive value. |
useGradient |
Logical. If TRUE, first derivatives will be used in the optimization. |
rel.tol |
Relative tolerance passed to nlminb(). Default to be 1e-10. |
trace.iter |
Print the processing of iterations of optimization. |
fitting |
Logical. If TRUE, fitting is carried out. Default to FALSE. |
fyList
is a list with the following items:
time
: a sequence of time points; default to be 100
points from 0 to 1.
nbasis
: number of basis functions used in
smoothing, default to be less than or equal to 23.
norder
:
order of the functional curves; default to be 6.
bSpline
:
logical. If TRUE (default), B-splines basis is used; otherwise, Fourier
basis is used.
Pen
: default to be c(0,0), meaning that the
penalty is only applied to the second order derivative of the curve, with
no penalty for the zero-th and first order derivatives of the curve.
lambda
: smoothing parameter for the penalty, default to be 1e-4.
fxList
is similar to fyList
. However, it is a list of lists
to allow for different specifications for each functional covariate if
there are multiple ones.
uCoefList
and fxCoefList
are similar to
each other. Each one is expected to be a list of lists. If a list of one
element is provided, then the items of this element are applied to each of
the functional coefficients of scalar covariates and of functional covariates,
respectively.
rtime
: range of time, default to be c(0,1).
nbasis
: nnumber of basis functions used in smoothing, default to be
less than or equal to 19.
norder
: order of the functional
curves; default to be 6.
bSpline
: logical. If TRUE (default),
B-splines basis is used; otherwise, Fourier basis is used.
Pen
: default to be c(0,0).
lambda
: smoothing parameter
for the penalty, default to be 1e4.
bivar
:logical. Used for
non-concurrent models; if TRUE, bivariate basis will be used; if FALSE
(default), normal basis will be used; see details in
bifdPar
.
lambdas
: smoothing parameter for
the penalty of the additional basis, default to be 1.
Note that all items have default settings.
A list containing:
Estimated hyperparameters
A vector of estimated standard deviation of hyperparameters
List of FR models fitted before Gaussian process
Covariance function used
Parameter 'gamma' used in Gaussian process with powered exponential kernel
Parameter 'nu' used in Gaussian process with Matern kernel
Raw response data
Residual after the fitted values from FR models have been taken out
Fitted values
Standard deviation of the fitted values
The type of the model applied in the function.
Training scalar covariates for the FR model
Training functional covariates for the FR model
List of 'fd' objects from training data for FR model with functional covariates
Training data for Gaussian Process
Input time 't'
Inverse of covariance matrix for uReg
Inverse of covariance matrix for fxReg
Fitted values from the FR model
fyList object used
Ramsay, J., and Silverman, B. W. (2006), “Functional Data Analysis”, 2nd ed., Springer, New York.
Shi, J. Q., and Choi, T. (2011), “Gaussian Process Regression Analysis for Functional Data”, CRC Press.
## See examples in vignette: # vignette("gpfr", package = "GPFDA")
## See examples in vignette: # vignette("gpfr", package = "GPFDA")
Make predictions for test input data based on the GPFR model learnt by the 'gpfr' function. Both Type I and Type II predictions can be made.
gpfrPredict( train, testInputGP, testTime = NULL, uReg = NULL, fxReg = NULL, gpReg = NULL, GPpredict = TRUE )
gpfrPredict( train, testInputGP, testTime = NULL, uReg = NULL, fxReg = NULL, gpReg = NULL, GPpredict = TRUE )
train |
An object of class 'gpfr' obtained by the the 'gpfr' function. |
testInputGP |
Test input data for the GP prediction. It must be a numeric vector, a matrix or an 'fd' object. |
testTime |
Test time points for prediction. If NULL, default settings will be applied. |
uReg |
Scalar covariates data of a new batch for the FR model. |
fxReg |
Functional covariates data of a new batch for the FR model. |
gpReg |
Input data for the GP part used for Type I prediction. It must be a list of three items. The names of the items must be 'response', 'input', and 'time'. The item 'response' is the observed response for a new batch; 'input' is the observed functional covariates for a new batch,;'time' is the observed time for the previous two. If NULL (default), Type II prediction is carried out. |
GPpredict |
Logical. If TRUE (default), GPFR prediction is carried out; otherwise only predictions based on the FR model is carried out. |
If 'gpReg' is provided, then Type I prediction is made. Otherwise, Type II prediction is made.
A list containing:
The mean values of the prediction.
The standard deviation of the predictions.
Prediction type if GPFR prediction is carried out.
All items trained by 'gpfr'.
Ramsay, J., and Silverman, B. W. (2006), “Functional Data Analysis”, 2nd ed., Springer, New York.
Shi, J. Q., and Choi, T. (2011), “Gaussian Process Regression Analysis for Functional Data”, CRC Press.
## See examples in vignette: # vignette("gpfr", package = "GPFDA")
## See examples in vignette: # vignette("gpfr", package = "GPFDA")
Gaussian process regression for a single or multiple independent realisations.
gpr( response, input, Cov = "pow.ex", m = NULL, hyper = NULL, NewHyper = NULL, meanModel = 0, mu = NULL, gamma = 2, nu = 1.5, useGradient = T, iter.max = 100, rel.tol = 8e-10, trace = 0, nInitCandidates = 1000 )
gpr( response, input, Cov = "pow.ex", m = NULL, hyper = NULL, NewHyper = NULL, meanModel = 0, mu = NULL, gamma = 2, nu = 1.5, useGradient = T, iter.max = 100, rel.tol = 8e-10, trace = 0, nInitCandidates = 1000 )
response |
Response data. It should be a matrix, where each column is a realisation. It can be a vector if there is only one realisation. |
input |
Input covariates. It must be either a matrix, where each column represents a covariate, or a vector if there is only one covariate. |
Cov |
Covariance function(s) to use. Options are: 'linear', 'pow.ex', 'rat.qu', and 'matern'. Default to 'power.ex'. |
m |
If Subset of Data is to be used, m denotes the subset size and cannot be larger than the total sample size. Default to NULL. |
hyper |
The hyperparameters. Default to NULL. If not NULL, then it must be a list with appropriate names. |
NewHyper |
Vector of names of the new hyperparameters of the customized kernel function. These names must have the format: xxxxxx.x, i.e. '6 digit' followed by 'a dot' followed by '1 digit'. This is required for both 'hyper' and 'NewHyper' |
meanModel |
Type of mean function. It can be
Default to 0. If argument 'mu' is specified, then 'meanModel' will be set to 'userDefined'. |
mu |
Mean function specified by the user. It must be a vector. Its length must be the same as the sample size, that is, nrow(response). |
gamma |
Power parameter used in powered exponential kernel function. It must be 0<gamma<=2. |
nu |
Smoothness parameter of the Matern class. It must be a positive value. |
useGradient |
Logical. If TRUE, first derivatives will be used in the optimization. |
iter.max |
Maximum number of iterations allowed. Default to 100. If 'rel.tol' is reduced, then the number of iterations needed will be less. |
rel.tol |
Relative convergence tolerance. Default to 8e-10. Smaller rel.tol means higher accuracy and more time to converge. |
trace |
The value of the objective function and the parameters is printed every trace'th iteration. Defaults to 0 which indicates no trace information is to be printed. |
nInitCandidates |
Number of initial hyperparameter vectors. The optimization starts with the best. |
The most important function of the package. It fits the GPR model and stores everything necessary for prediction. The optimization used in the function is 'nlminb'. The names for the hyperparameters should be: "linear.a" for linear covariance function, "pow.ex.w", "pow.ex.v" for power exponential, "rat.qu.s", "rat.qu.a" for rational quadratic, "matern.w", "matern.v" for Matern, "vv" for variance of Gaussian white noise. All hyperparameters should be in one list.
A list containing:
Hyperparameters vector estimated from training data
Variance of the estimated hyperparameters
Fitted values for the training data
Standard deviation of the fitted values for the training data
Training covariates
Training response
Original training response
Original training covariates
Index vector identifying which observations were selected if Subset of Data was used.
Covariance function type
Parameter used in powered exponential covariance function
Parameter used in Matern covariance function
Covariance matrix
Mean function
Mean model used
'lm' object if mean is a linear regression. NULL otherwise.
An integer. 0 means converge; 1 otherwise.
Starting point of the hyperparameters vector.
Shi, J. Q., and Choi, T. (2011), “Gaussian Process Regression Analysis for Functional Data”, CRC Press.
## See examples in vignettes: # vignette("gpr_ex1", package = "GPFDA") # vignette("gpr_ex2", package = "GPFDA") # vignette("co2", package = "GPFDA")
## See examples in vignettes: # vignette("gpr_ex1", package = "GPFDA") # vignette("gpr_ex2", package = "GPFDA") # vignette("co2", package = "GPFDA")
Prediction of GPR model
gprPredict( train = NULL, inputNew = NULL, noiseFreePred = F, hyper = NULL, input = NULL, Y = NULL, mSR = NULL, Cov = NULL, gamma = NULL, nu = NULL, meanModel = 0, mu = 0 )
gprPredict( train = NULL, inputNew = NULL, noiseFreePred = F, hyper = NULL, input = NULL, Y = NULL, mSR = NULL, Cov = NULL, gamma = NULL, nu = NULL, meanModel = 0, mu = 0 )
train |
A 'gpr' object obtained from 'gpr' function. Default to NULL. If NULL, learning is done based on the other given arguments; otherwise, prediction is made based on the trained model of class gpr'. |
inputNew |
Test input covariates. It must be either a matrix, where each column represents a covariate, or a vector if there is only one covariate. |
noiseFreePred |
Logical. If TRUE, predictions will be noise-free. |
hyper |
The hyperparameters. Default to NULL. If not NULL, then it must be a list with appropriate names. |
input |
Input covariates. It must be either a matrix, where each column represents a covariate, or a vector if there is only one covariate. |
Y |
Training response. It should be a matrix, where each column is a realisation. It can be a vector if there is only one realisation. |
mSR |
Subset size m if Subset of Regressors method is used for prediction. It must be smaller than the total sample size. |
Cov |
Covariance function(s) to use. Options are: 'linear', 'pow.ex', 'rat.qu', and 'matern'. Default to 'power.ex'. |
gamma |
Power parameter used in powered exponential kernel function. It must be 0<gamma<=2. |
nu |
Smoothness parameter of the Matern class. It must be a positive value. |
meanModel |
Type of mean function. It can be
Default to 0. If argument 'mu' is specified, then 'meanModel' will be set to 'userDefined'. |
mu |
Mean function specified by the user. It must be a vector. Its length must be the same as the sample size, that is, nrow(response). |
A list containing
Mean of predictions
Standard deviation of predictions
Test input data
Logical. If TRUE, predictions are noise-free.
Objects of 'gpr' class.
## See examples in vignettes: # vignette("gpr_ex1", package = "GPFDA") # vignette("gpr_ex2", package = "GPFDA") # vignette("co2", package = "GPFDA")
## See examples in vignettes: # vignette("gpr_ex1", package = "GPFDA") # vignette("gpr_ex2", package = "GPFDA") # vignette("co2", package = "GPFDA")
Easy setting up for creating an 'fd' object
mat2fd(mat, fdList = NULL)
mat2fd(mat, fdList = NULL)
mat |
Input data, should be a matrix with ncol time points and nrow replications or samples. |
fdList |
A list with following items:
|
All items listed above have default values. If any item is required to change, add that item into the list; otherwise, leave it as NULL. For example, if one only wants to change the number of basis functions, do:
mat2fd(SomeMatrix,list(nbasis=21))
An 'fd' object
Ramsay, J., and Silverman, B. W. (2006),
require(fda) require(fda.usc) nrep <- 20 # number of replications n <- 100 # number of time points input <- seq(-1, pi, length.out=n) # time points ry <- rnorm(nrep, sd=10) y <- matrix(NA, ncol=n, nrow=nrep) for(i in 1:nrep) y[i,] <- sin(2*input)*ry[i] plot.fdata(fdata(y,input)) yfd <- mat2fd(y, list(lambda=0.01)) plot(yfd) yfd <- mat2fd(y, list(lambda=0.00001)) plot(yfd)
require(fda) require(fda.usc) nrep <- 20 # number of replications n <- 100 # number of time points input <- seq(-1, pi, length.out=n) # time points ry <- rnorm(nrep, sd=10) y <- matrix(NA, ncol=n, nrow=nrep) for(i in 1:nrep) y[i,] <- sin(2*input)*ry[i] plot.fdata(fdata(y,input)) yfd <- mat2fd(y, list(lambda=0.01)) plot(yfd) yfd <- mat2fd(y, list(lambda=0.00001)) plot(yfd)
Calculate a multivariate Gaussian processes covariance matrix given a vector of hyperparameters
mgpCovMat(Data, hp)
mgpCovMat(Data, hp)
Data |
List of two elements: 'input' and 'response'. The element 'input' is a list of N vectors, where each vector represents the input covariate values for a particular output. The element 'response' is the corresponding list of N matrices (if there are multiple realisations) or vectors (for a single realisation) representing the response variables. |
hp |
Vector of hyperparameters |
Covariance matrix
Shi, J. Q., and Choi, T. (2011), “Gaussian Process Regression Analysis for Functional Data”, CRC Press.
## See examples in vignette: # vignette("mgpr", package = "GPFDA")
## See examples in vignette: # vignette("mgpr", package = "GPFDA")
Multivariate Gaussian process regression where each of the N outputs is unidimensional. The multivariate output is allowed to have multiple independent realisations.
mgpr(Data, m = NULL, meanModel = 0, mu = NULL)
mgpr(Data, m = NULL, meanModel = 0, mu = NULL)
Data |
List of two elements: 'input' and 'response'. The element 'input' is a list of N vectors, where each vector represents the input covariate values for a particular output. The element 'response' is the corresponding list of N matrices (if there are multiple realisations) or vectors (for a single realisation) representing the response variables. |
m |
If Subset of Data is to be used in the estimation, m denotes the subset size. It cannot be larger than the total sample size. Default to NULL (Subsetting is not used). |
meanModel |
Type of mean function applied to all outputs. It can be
Default to 0. If argument 'mu' is specified, then 'meanModel' will be set to 'userDefined'. |
mu |
Vector of concatenated mean function values defined by the user. Default to NULL. |
A list containing:
Fitted values for the training data
Standard deviation of the fitted values for training data
Number of response variables
Original input variables
Original response
Index vector identifying to which output the elements of concatenated vectors correspond to.
Covariance matrix
Concatenated mean function
Mean model used for each output
'lm' object for each output if the linear regression model is used for the mean functions. NULL otherwise.
Shi, J. Q., and Choi, T. (2011), “Gaussian Process Regression Analysis for Functional Data”, CRC Press.
## See examples in vignette: # vignette("mgpr", package = "GPFDA")
## See examples in vignette: # vignette("mgpr", package = "GPFDA")
Prediction of MGPR model
mgprPredict( train, DataObs = NULL, DataNew, noiseFreePred = F, meanModel = NULL, mu = 0 )
mgprPredict( train, DataObs = NULL, DataNew, noiseFreePred = F, meanModel = NULL, mu = 0 )
train |
A 'mgpr' object obtained from 'mgpr' function. If NULL, predictions are made based on DataObs informed by the user. |
DataObs |
List of observed data. Default to NULL. If NULL, predictions are made based on the trained data (included in the object of class 'mgpr') used for learning. |
DataNew |
List of test input data. |
noiseFreePred |
Logical. If TRUE, predictions will be noise-free. |
meanModel |
Type of mean function applied to all outputs. It can be
Default to 0. If argument 'mu' is specified, then 'meanModel' will be set to 'userDefined'. |
mu |
Vector of concatenated mean function values defined by the user. Default to NULL. |
A list containing
Mean of predictions for the test set.
Standard deviation of predictions for the test set.
Logical. If TRUE, predictions are noise-free.
## See examples in vignette: # vignette("mgpr", package = "GPFDA")
## See examples in vignette: # vignette("mgpr", package = "GPFDA")
Calculate a NSGP covariance matrix given a vector of hyperparameters
nsgpCovMat( hp, input, inputSubsetIdx = NULL, nBasis = 5, corrModel = corrModel, gamma = NULL, nu = NULL, cyclic = NULL, whichTau = NULL, calcCov = T )
nsgpCovMat( hp, input, inputSubsetIdx = NULL, nBasis = 5, corrModel = corrModel, gamma = NULL, nu = NULL, cyclic = NULL, whichTau = NULL, calcCov = T )
hp |
Vector of hyperparameters estimated by function nsgpr. |
input |
List of Q input variables (see Details). |
inputSubsetIdx |
A list identifying a subset of the input values to be used in the estimation (see Details). |
nBasis |
Number of B-spline basis functions in each coordinate direction along which parameters change. |
corrModel |
Correlation function specification used for g(.). It can be either "pow.ex" or "matern". |
gamma |
Power parameter used in powered exponential kernel function. It must be 0<gamma<=2. |
nu |
Smoothness parameter of the Matern class. It must be a positive value. |
cyclic |
Logical vector of dimension Q which defines which covariates are cyclic (periodic). For example, if basis functions should be cyclic only in the first coordinate direction, then cyclic=c(T,F). cyclic must have the same dimension of whichTau. If cyclic is TRUE for some coordinate direction, then cyclic B-spline functions will be used and the varying parameters (and their first two derivatives) will match at the boundaries of that coordinate direction. |
whichTau |
Logical vector of dimension Q identifying which input coordinates the parameters are function of. For example, if Q=2 and parameters change only with respect to the first coordinate, then we set whichTau=c(T,F). |
calcCov |
Logical. Calculate covariance matrix or not. If FALSE, time or spatially-varying parameters are still provided. |
A list containing
Covariance matrix
Noise variance
List of varying anisotropy matrix over the input space
Vector of signal variance over the input space
Konzen, E., Shi, J. Q. and Wang, Z. (2020) "Modeling Function-Valued Processes with Nonseparable and/or Nonstationary Covariance Structure" <arXiv:1903.09981>.
## See examples in vignette: # vignette("nsgpr", package = "GPFDA")
## See examples in vignette: # vignette("nsgpr", package = "GPFDA")
Calculate an asymmetric NSGP covariance matrix
nsgpCovMatAsym( hp, input, inputNew, nBasis = 5, corrModel = corrModel, gamma = NULL, nu = NULL, cyclic = NULL, whichTau = NULL )
nsgpCovMatAsym( hp, input, inputNew, nBasis = 5, corrModel = corrModel, gamma = NULL, nu = NULL, cyclic = NULL, whichTau = NULL )
hp |
Vector of hyperparameters estimated by function nsgpr. |
input |
List of Q input variables (see Details). |
inputNew |
List of Q test set input variables. |
nBasis |
Number of B-spline basis functions in each coordinate direction along which parameters change. |
corrModel |
Correlation function specification used for g(.). It can be either "pow.ex" or "matern". |
gamma |
Power parameter used in powered exponential kernel function. It must be 0<gamma<=2. |
nu |
Smoothness parameter of the Matern class. It must be a positive value. |
cyclic |
Logical vector of dimension Q which defines which covariates are cyclic (periodic). For example, if basis functions should be cyclic only in the first coordinate direction, then cyclic=c(T,F). cyclic must have the same dimension of whichTau. If cyclic is TRUE for some coordinate direction, then cyclic B-spline functions will be used and the varying parameters (and their first two derivatives) will match at the boundaries of that coordinate direction. |
whichTau |
Logical vector of dimension Q identifying which input coordinates the parameters are function of. For example, if Q=2 and parameters change only with respect to the first coordinate, then we set whichTau=c(T,F). |
An asymmetric covariance matrix
Konzen, E., Shi, J. Q. and Wang, Z. (2020) "Modeling Function-Valued Processes with Nonseparable and/or Nonstationary Covariance Structure" <arXiv:1903.09981>.
Estimate the covariance structure of a zero-mean Gaussian Process with
Q-dimensional input coordinates (covariates).
Multiple realisations
for the response variable can be used, provided they are observed on the same
grid of dimension n_1 x n_2 x ... x n_Q.
Let n = n_1 x n_2 x ... x n_Q
and let nSamples be the number of realisations.
nsgpr( response, input, corrModel = "pow.ex", gamma = 2, nu = 1.5, whichTau = NULL, nBasis = 5, cyclic = NULL, unitSignalVariance = F, zeroNoiseVariance = F, sepCov = F, nInitCandidates = 300, absBounds = 6, inputSubsetIdx = NULL )
nsgpr( response, input, corrModel = "pow.ex", gamma = 2, nu = 1.5, whichTau = NULL, nBasis = 5, cyclic = NULL, unitSignalVariance = F, zeroNoiseVariance = F, sepCov = F, nInitCandidates = 300, absBounds = 6, inputSubsetIdx = NULL )
response |
Response variable. This should be a (n x nSamples) matrix where each column is a realisation |
input |
List of Q input variables (see Details). |
corrModel |
Correlation function specification used for g(.). It can be either "pow.ex" or "matern". |
gamma |
Power parameter used in powered exponential kernel function. It must be 0<gamma<=2. |
nu |
Smoothness parameter of the Matern class. It must be a positive value. |
whichTau |
Logical vector of dimension Q identifying which input coordinates the parameters are function of. For example, if Q=2 and parameters change only with respect to the first coordinate, then we set whichTau=c(T,F). |
nBasis |
Number of B-spline basis functions in each coordinate direction along which parameters change. |
cyclic |
Logical vector of dimension Q which defines which covariates are cyclic (periodic). For example, if basis functions should be cyclic only in the first coordinate direction, then cyclic=c(T,F). cyclic must have the same dimension of whichTau. If cyclic is TRUE for some coordinate direction, then cyclic B-spline functions will be used and the varying parameters (and their first two derivatives) will match at the boundaries of that coordinate direction. |
unitSignalVariance |
Logical. TRUE if we assume realisations have variance 1. This is useful when we want to estimate an NSGP correlation function. |
zeroNoiseVariance |
Logical. TRUE if we assume the realisations are noise-free. |
sepCov |
Logical. TRUE only if we fix to zero all off-diagonal elements of the varying anisotropy matrix. Default to FALSE, allowing for a separable covariance function. |
nInitCandidates |
number of initial hyperparameter vectors which are used to evaluate the log-likelihood function at a first step. After evaluating the log-likelihood using these 'nInitCandidates' vectors, the optimisation via nlminb() begins with the best of these vectors. |
absBounds |
lower and upper boundaries for B-spline coefficients (if wanted). |
inputSubsetIdx |
A list identifying a subset of the input values to be used in the estimation (see Details). |
The input argument for Q=2 can be constructed as follows:
n1 <- 10 n2 <- 1000 input <- list() input[[1]] <- seq(0,1,length.out = n1) input[[2]] <- seq(0,1,length.out = n2)
If we want to use every third lattice point in the second input variable (using Subset of Data), then we can set
inputSubsetIdx <- list() inputSubsetIdx[[1]] <- 1:n1 inputSubsetIdx[[2]] <- seq(1,n2, by=3)
A list containing:
Maximum likelihood estimates of B-spline coefficients and noise variance.
Matrix of response.
Input coordinates in a matrix form
Correlation function specification used for g(.)
Konzen, E., Shi, J. Q. and Wang, Z. (2020) "Modeling Function-Valued Processes with Nonseparable and/or Nonstationary Covariance Structure" <arXiv:1903.09981>.
## See examples in vignette: # vignette("nsgpr", package = "GPFDA")
## See examples in vignette: # vignette("nsgpr", package = "GPFDA")
Prediction of NSGPR model
nsgprPredict( hp, response, input, inputNew, noiseFreePred = F, nBasis = nBasis, corrModel = corrModel, gamma = gamma, nu = nu, cyclic = cyclic, whichTau = whichTau )
nsgprPredict( hp, response, input, inputNew, noiseFreePred = F, nBasis = nBasis, corrModel = corrModel, gamma = gamma, nu = nu, cyclic = cyclic, whichTau = whichTau )
hp |
Vector of hyperparameters estimated by function nsgpr. |
response |
Response variable. This should be a (n x nSamples) matrix where each column is a realisation |
input |
List of Q input variables (see Details). |
inputNew |
List of Q test set input variables. |
noiseFreePred |
Logical. If TRUE, predictions will be noise-free. |
nBasis |
Number of B-spline basis functions in each coordinate direction along which parameters change. |
corrModel |
Correlation function specification used for g(.). It can be either "pow.ex" or "matern". |
gamma |
Power parameter used in powered exponential kernel function. It must be 0<gamma<=2. |
nu |
Smoothness parameter of the Matern class. It must be a positive value. |
cyclic |
Logical vector of dimension Q which defines which covariates are cyclic (periodic). For example, if basis functions should be cyclic only in the first coordinate direction, then cyclic=c(T,F). cyclic must have the same dimension of whichTau. If cyclic is TRUE for some coordinate direction, then cyclic B-spline functions will be used and the varying parameters (and their first two derivatives) will match at the boundaries of that coordinate direction. |
whichTau |
Logical vector of dimension Q identifying which input coordinates the parameters are function of. For example, if Q=2 and parameters change only with respect to the first coordinate, then we set whichTau=c(T,F). |
A list containing
Mean of predictions for the test set.
Standard deviation of predictions for the test set.
Logical. If TRUE, predictions are noise-free.
Konzen, E., Shi, J. Q. and Wang, Z. (2020) "Modeling Function-Valued Processes with Nonseparable and/or Nonstationary Covariance Structure" <arXiv:1903.09981>.
## See examples in vignette: # vignette("nsgpr", package = "GPFDA")
## See examples in vignette: # vignette("nsgpr", package = "GPFDA")
Plot GPFR model for either training or prediction
## S3 method for class 'gpfr' plot( x, type = c("raw", "meanFunction", "fitted", "prediction"), ylab = "y", xlab = "t", ylim = NULL, realisations = NULL, alpha = 0.05, colourTrain = 2, colourNew = 4, mar = c(4.5, 5.1, 2.2, 0.8), oma = c(0, 0, 1, 0), cex.lab = 1.5, cex.axis = 1, cex.main = 1.5, ... )
## S3 method for class 'gpfr' plot( x, type = c("raw", "meanFunction", "fitted", "prediction"), ylab = "y", xlab = "t", ylim = NULL, realisations = NULL, alpha = 0.05, colourTrain = 2, colourNew = 4, mar = c(4.5, 5.1, 2.2, 0.8), oma = c(0, 0, 1, 0), cex.lab = 1.5, cex.axis = 1, cex.main = 1.5, ... )
x |
Plot GPFR for training or prediction from a given object of 'gpfr' class. |
type |
Required type of plots. Options are: 'raw', 'meanFunction', 'fitted' and 'prediction'. |
ylab |
Title for the y axis. |
xlab |
Title for the x axis. |
ylim |
Graphical parameter. If NULL (default), it is chosen automatically. |
realisations |
Index vector identifying which training realisations should be plotted. If NULL (default), all training realisations are plotted. For predictions, 'realisations' should be '0' if no training realisation is to be plotted. |
alpha |
Significance level used for 'fitted' or 'prediction'. Default is 0.05. |
colourTrain |
Colour for training realisations when 'type' is set to 'prediction' and 'realisations' is positive. |
colourNew |
Colour for predictive mean for the new curve when 'type' is set to 'prediction'. |
mar |
Graphical parameter passed to par(). |
oma |
Graphical parameter passed to par(). |
cex.lab |
Graphical parameter passed to par(). |
cex.axis |
Graphical parameter passed to par(). |
cex.main |
Graphical parameter passed to par(). |
... |
Other graphical parameters passed to plot(). |
A plot.
## See examples in vignette: # vignette("gpfr", package = "GPFDA")
## See examples in vignette: # vignette("gpfr", package = "GPFDA")
Plot Gaussian process for a given an object of class 'gpr'.
## S3 method for class 'gpr' plot( x, fitted = F, col.no = 1, ylim = NULL, realisation = NULL, main = NULL, cex.points = NULL, lwd.points = NULL, pch = NULL, lwd = NULL, ... )
## S3 method for class 'gpr' plot( x, fitted = F, col.no = 1, ylim = NULL, realisation = NULL, main = NULL, cex.points = NULL, lwd.points = NULL, pch = NULL, lwd = NULL, ... )
x |
The 'gpr' object from either training or predicting of the Gaussian Process. |
fitted |
Logical. Plot fitted values or not. Default to FALSE. If FALSE, plot the predictions. |
col.no |
Column number of the input matrix. If the input matrix has more than one columns, than one of them will be used in the plot. Default to be the first one. |
ylim |
Range value for y-axis. |
realisation |
Integer identifying which realisation should be plotted (if there are multiple). |
main |
Title for the plot |
cex.points |
Graphical parameter |
lwd.points |
Graphical parameter |
pch |
Graphical parameter |
lwd |
Graphical parameter |
... |
Graphical parameters passed to plot(). |
A plot
## See examples in vignette: # vignette("gpr_ex1", package = "GPFDA")
## See examples in vignette: # vignette("gpr_ex1", package = "GPFDA")
Plot predictons of each element of the multivariate Gaussian Process for a given an object of class 'mgpr'.
## S3 method for class 'mgpr' plot( x, DataObs, DataNew, realisation, alpha = 0.05, ylim = NULL, mfrow = NULL, cex = 2, mar = c(4.5, 7.1, 0.2, 0.8), oma = c(0, 0, 0, 0), cex.lab = 2, cex.axis = 1.5, ... )
## S3 method for class 'mgpr' plot( x, DataObs, DataNew, realisation, alpha = 0.05, ylim = NULL, mfrow = NULL, cex = 2, mar = c(4.5, 7.1, 0.2, 0.8), oma = c(0, 0, 0, 0), cex.lab = 2, cex.axis = 1.5, ... )
x |
An object of class 'mgpr'. |
DataObs |
List of observed data. |
DataNew |
List of test data. |
realisation |
Index identifying which realisation should be plotted. |
alpha |
Significance level used for MGPR predictions. Default is 0.05. |
ylim |
Range of y-axis. |
mfrow |
Graphical parameter. |
cex |
Graphical parameter. |
mar |
Graphical parameter passed to par(). |
oma |
Graphical parameter passed to par(). |
cex.lab |
Graphical parameter passed to par(). |
cex.axis |
Graphical parameter passed to par(). |
... |
Graphical parameters passed to plot(). |
A plot showing predictions of each element of the multivariate process.
## See examples in vignette: # vignette("mgpr", package = "GPFDA")
## See examples in vignette: # vignette("mgpr", package = "GPFDA")
Draw an image plot for a given two-dimensional input
plotImage( response, input, realisation = 1, n1, n2, main = " ", zlim = NULL, cex.axis = 1, cex.lab = 2.5, legend.cex.axis = 1, font.main = 2, cex.main = 2, legend.width = 2, mar = c(2.1, 2.1, 3.1, 6.1), oma = c(0, 1, 0, 0), nGrid = 200, enlarge_zlim = NULL )
plotImage( response, input, realisation = 1, n1, n2, main = " ", zlim = NULL, cex.axis = 1, cex.lab = 2.5, legend.cex.axis = 1, font.main = 2, cex.main = 2, legend.width = 2, mar = c(2.1, 2.1, 3.1, 6.1), oma = c(0, 1, 0, 0), nGrid = 200, enlarge_zlim = NULL )
response |
Data to be plotted (e.g. matrix of predictions) |
input |
Matrix of two columns representing the input coordinates. |
realisation |
Integer identifying which realisation should be plotted (if there are multiple). |
n1 |
Number of datapoints in the first coordinate direction |
n2 |
Number of datapoints in the second coordinate direction |
main |
Title for the plot |
zlim |
Range of z-axis |
cex.axis |
Graphical parameter |
cex.lab |
Graphical parameter |
legend.cex.axis |
Graphical parameter |
font.main |
Graphical parameter |
cex.main |
Graphical parameter |
legend.width |
Graphical parameter |
mar |
Graphical parameter |
oma |
Graphical parameter |
nGrid |
Dimension of output grid in each coordinate direction |
enlarge_zlim |
Additional quantity to increase the range of zlim |
A plot
## See examples in vignette: # vignette("gpr_ex2", package = "GPFDA")
## See examples in vignette: # vignette("gpr_ex2", package = "GPFDA")
Plot auto- or cross-covariance function of a multivariate Gaussian process
plotmgpCovFun( type = "Cov", output, outputp, Data, hp, idx, ylim = NULL, xlim = NULL, mar = c(4.5, 5.1, 2.2, 0.8), oma = c(0, 0, 0, 0), cex.lab = 1.5, cex.axis = 1, cex.main = 1.5 )
plotmgpCovFun( type = "Cov", output, outputp, Data, hp, idx, ylim = NULL, xlim = NULL, mar = c(4.5, 5.1, 2.2, 0.8), oma = c(0, 0, 0, 0), cex.lab = 1.5, cex.axis = 1, cex.main = 1.5 )
type |
Logical. It can be either 'Cov' (for covariance function) or 'Cor' (for corresponding correlation function). |
output |
Integer identifying one element of the multivariate process. |
outputp |
Integer identifying one element of the multivariate process. If 'output' and 'outputp' are the same, the auto-covariance function will be plotted. Otherwise, the cross-covariance function between 'output' and 'outputp' will be plotted. |
Data |
List of two elements: 'input' and 'response'. The element 'input' is a list of N vectors, where each vector represents the input covariate values for a particular output. The element 'response' is the corresponding list of N matrices (if there are multiple realisations) or vectors (for a single realisation) representing the response variables. |
hp |
Vector of hyperparameters |
idx |
Index vector identifying to which output the elements of concatenated vectors correspond to. |
ylim |
Graphical parameter |
xlim |
Graphical parameter |
mar |
Graphical parameter passed to par(). |
oma |
Graphical parameter passed to par(). |
cex.lab |
Graphical parameter passed to par(). |
cex.axis |
Graphical parameter passed to par(). |
cex.main |
Graphical parameter passed to par(). |
A plot
## See examples in vignette: # vignette("mgpr", package = "GPFDA")
## See examples in vignette: # vignette("mgpr", package = "GPFDA")
Calculate an unscaled NSGP correlation matrix
unscaledCorr(Dist.mat, corrModel, gamma = NULL, nu = NULL)
unscaledCorr(Dist.mat, corrModel, gamma = NULL, nu = NULL)
Dist.mat |
Distance matrix |
corrModel |
Correlation function specification used for g(.). It can be either "pow.ex" or "matern". |
gamma |
Power parameter used in powered exponential kernel function. It must be 0<gamma<=2. |
nu |
Smoothness parameter of the Matern class. It must be a positive value. |
A matrix
Konzen, E., Shi, J. Q. and Wang, Z. (2020) "Modeling Function-Valued Processes with Nonseparable and/or Nonstationary Covariance Structure" <arXiv:1903.09981>.
## See examples in vignette: # vignette("nsgpr", package = "GPFDA")
## See examples in vignette: # vignette("nsgpr", package = "GPFDA")