Fits SPQR using either MLE or MAP method and computes K-fold cross-validation error.
Arguments
- folds
A list of CV folds, possibly that generated from
createFolds.SPQR().- X
The covariate matrix (without intercept column)
- Y
The response vector.
- n.knots
The number of basis functions. Default: 10.
A vector specifying the number of hidden neurons in each hidden layer. Default: 10.
- activation
The hidden layer activation. Either
"tanh"(default) or"relu".- method
Method for estimating SPQR. One of
"MLE","MAP"(default) or"MCMC".- prior
The prior model for variance hyperparameters. One of
"GP","ARD"(default) or"GSM".- hyperpar
A list of named hyper-prior hyperparameters to use instead of the default values, including
a_lambda,b_lambda,a_sigmaandb_sigma. The default value is 0.001 for all four hyperparameters.- control
A list of named and method-dependent parameters that allows finer control of the behavior of the computational approaches.
1. Parameters for MLE and MAP methods
use.GPUIfTRUEGPU computing will be used iftorch::cuda_is_available()returnsTRUE. Default:FALSE.lrThe learning rate used by the Adam optimizer, i.e.,torch::optim_adam().dropoutA length two vector specifying the dropout probabilities in the input and hidden layers respectively. The default isc(0,0)indicating no dropout.batchnormIfTRUEbatch normalization will be used after each hidden activation.epochsThe number of passes of the entire training dataset in gradient descent optimization. Ifearly.stopping.epochsis used then this is the maximum number of passes. Default: 200.batch.sizeThe size of mini batches for gradient calculation. Default: 128.valid.pctThe fraction of data used as validation set. Default: 0.2.early.stopping.epochsThe number of epochs before stopping if the validation loss does not decrease. Default: 10.print.every.epochsThe number of epochs before next training progress in printed. Default: 10.save.pathThe path to save the fitted torch model. By default a folder named"SPQR_model"is created in the current working directory to store the model.save.nameThe name of the file to save the fitted torch model. Default is"SPQR.model.pt".
2. Parameters for MCMC method
These parameters are similar to those in
rstan::stan(). Detailed explanations can be found in the Stan reference manual.algorithmThe sampling algorithm;"HMC": Hamiltonian Monte Carlo with dual-averaging,"NUTS": No-U-Turn sampler (default).iterThe number of MCMC iterations (including warmup). Default: 2000.warmupThe number of warm-up/burn-in iterations for step-size and mass matrix adaptation. Default: 500.thinThe number of iterations before saving next post-warmup samples. Default: 1.stepsizeThe discretization interval/step-size \(\epsilon\) of leap-frog integrator. Default isNULLwhich indicates that it will be adaptively selected during warm-up iterations.metricThe type of mass matrix;"unit": diagonal matrix of ones,"diag": diagonal matrix with positive diagonal entries estimated during warmup iterations (default),"dense": a dense, symmetric positive definite matrix with entries estimated during warm-up iterations.deltaThe target Metropolis acceptance rate. Default: 0.9.max.treedepthThe maximum tree depth in NUTS. Default: 6.int.timeThe integration time in HMC. The number of leap-frog steps is calculated as \(L_{\epsilon}=\lfloor t/\epsilon\rfloor\). Default: 0.3.
- normalize
If
TRUE, all covariates will be normalized to take values between [0,1].- verbose
If
TRUE(default), training progress will be printed.- seed
Random number generation seed.
- ...
other parameters to pass to
control.
Value
- control
the list of all control parameters.
- cve
the cross-validation error.
- folds
the CV folds.
Examples
# \donttest{
set.seed(919)
n <- 200
X <- rbinom(n, 1, 0.5)
Y <- rnorm(n, X, 0.8)
folds <- createFolds.SPQR(Y, nfold = 5)
## compute 5-fold CV error
# cv.out <- cv.SPQR(folds=folds, X=X, Y=Y, method="MLE",
# normalize = TRUE, verbose = FALSE)
# }
