Fits SPQR using either MLE or MAP method and computes K-fold cross-validation error based on pre-computed folds.
cv.SPQR(
folds,
X,
Y,
n.knots = 10,
n.hidden = 10,
activation = c("tanh", "relu", "sigmoid"),
method = c("MLE", "MAP", "MCMC"),
prior = c("ARD", "GP", "GSM"),
hyperpar = list(),
control = list(),
normalize = FALSE,
verbose = TRUE,
seed = NULL,
...
)
A list of CV folds, possibly that generated from createFolds.SPQR()
.
The covariate matrix (without intercept column)
The response vector.
The number of basis functions. Default: 10.
A vector specifying the number of hidden neurons in each hidden layer. Default: 10.
The hidden layer activation. Either "tanh"
(default) or "relu"
.
Method for estimating SPQR. One of "MLE"
, "MAP"
(default) or "MCMC"
.
The prior model for variance hyperparameters. One of "GP"
, "ARD"
(default) or "GSM"
.
A list of named hyper-prior hyperparameters to use instead of the default values, including
a_lambda
, b_lambda
, a_sigma
and b_sigma
. The default value is 0.001 for all four
hyperparameters.
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.GPU
If TRUE
GPU computing will be used if torch::cuda_is_available()
returns TRUE
. Default: FALSE
.
lr
The learning rate used by the Adam optimizer, i.e., torch::optim_adam()
.
dropout
A length two vector specifying the dropout probabilities in the input and hidden layers respectively. The default is c(0,0)
indicating no dropout.
batchnorm
If TRUE
batch normalization will be used after each hidden activation.
epochs
The number of passes of the entire training dataset in gradient descent optimization. If early.stopping.epochs
is used then this is the maximum number of passes. Default: 200.
batch.size
The size of mini batches for gradient calculation. Default: 128.
valid.pct
The fraction of data used as validation set. Default: 0.2.
early.stopping.epochs
The number of epochs before stopping if the validation loss does not decrease. Default: 10.
print.every.epochs
The number of epochs before next training progress in printed. Default: 10.
save.path
The 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.name
The 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.
algorithm
The sampling algorithm; "HMC"
: Hamiltonian Monte Carlo with dual-averaging, "NUTS"
: No-U-Turn sampler (default).
iter
The number of MCMC iterations (including warmup). Default: 2000.
warmup
The number of warm-up/burn-in iterations for step-size and mass matrix adaptation. Default: 500.
thin
The number of iterations before saving next post-warmup samples. Default: 1.
stepsize
The discretization interval/step-size \(\epsilon\) of leap-frog integrator. Default is NULL
which indicates that it will be adaptively selected during warm-up iterations.
metric
The 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.
delta
The target Metropolis acceptance rate. Default: 0.9.
max.treedepth
The maximum tree depth in NUTS. Default: 6.
int.time
The integration time in HMC. The number of leap-frog steps is calculated as \(L_{\epsilon}=\lfloor t/\epsilon\rfloor\). Default: 0.3.
If TRUE
, all covariates will be normalized to take values between [0,1].
If TRUE
(default), training progress will be printed.
Random number generation seed.
other parameters to pass to control
.
the list of all control parameters.
the cross-validation error.
the CV folds.
# NOT RUN {
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)
# }
Run the code above in your browser using DataLab