BLNN_Train: Train a BLNN object

Description Usage Arguments Value References

View source: R/BLNN_train.R

Description

This function allow the user to train the BLNN object. The user can choose from three training algorithms. "NUTS" and "HMC" for Bayesian training method, see references for detailed description. The third option is "BFGS" for quasi-Newton method which is done through optim function.

Usage

1
2
3
4
5
BLNN_Train(NET, x, y, iter = 2000, init = NULL, chains = 1,
  seeds = NULL, warmup = floor(iter/2), thin = 1, parallel = FALSE,
  cores = NULL, algorithm = c("NUTS", "HMC", "BFGS"),
  evidence = FALSE, ev.x = NULL, ev.y = NULL, ev.iter = 1,
  control = NULL, display = 0, path = getwd(), ...)

Arguments

NET

the BLNN object which is created using BLNN_Build.

x

A matrix or data frame of covariates. it is preferred that continuous variables are scaled before training.

y

response or target values. A vector for one unit in the output layer, or a matrix/dataframe for more than one unit in the output layer.

iter

is the number of samples to draw from the Posterior distribution. In case of "BFGS" algorithm it is the number of iterations.

init

A list of vectors containing the initial parameters values or a function. It is strongly recommended to have a different vector for each chain

chains

Number of chains to run. Needed for Bayesian training only.

seeds

A vector of seeds. One for each chain.

warmup

The number of warmup iterations/samples. Default is half the number of iter.

thin

The thinning rate to apply to samples

parallel

A boolean value to check whether to use Parallel cores or not. Snowfall package is needed if TRUE.

cores

Number of cores to be used if parallel is TRUE.

algorithm

choose one algorithm from three c("NUTS", "HMC", "BFGS"). NUTS for the NO-U-Turn algorithm, HMC for Hamiltonian Markov chain sampler. See references below for detailed descriptions of each algorithm. The BFGS for quasi-Newton algorithm.

evidence

A boolean value to use the evidence procedure for re-estimating the Hyper-parameters.

ev.x

matrix/dataframe of covariates to be used in evidence procedure. Prefered to be historical data or part of the current training data. If left blank while evidence is TRUE, x will be used.

ev.y

vector/matrix of targets to be used in evidence procedure. If left blank while evidence is TRUE, y will be used.

ev.iter

number of iterations in evidence procedure, see references for more detials. Default is set to 1.

control

A list containing several control arguments needed for tunning NUTS and HMC. These arguments are:

  • adapt_delta: The target acceptance rate. Default is 0.8, for HMC preferred is 0.65.

  • momentum.mass: A vector of the momentum variance, default is 1.

  • stepsize: The stepsize to be used if no adapt is used. If NULL it will be adapted during warmup. If UseDA is true then the stepsize is the initial step used in Pick Epsilon.

  • useDA: Whether dual averaging for adapting stepsize is used or not. Default is TRUE.

  • gamma: One of DA arguments, double, positive, defaults to 2.

  • t0: One of DA arguments, double, positive, defaults to 10.

  • kappa: One of DA arguments, double, positive, defaults to 0.75.

  • metric: The mass metric to use. Options are: "unit" for a unit diagonal matrix; NULL to estimate a diagonal matrix during warmup; a matrix to be used directly (in untransformed space)

  • adapt_mass: Whether adaptation of mass matrix is turned on. Currently only allowed for diagonal metric.

  • w1: integer, positive, defaults to 75.

  • w2: integer, positive, defaults to 50.

  • w3: integer, positive, defaults to 25. In addition one argument used only for NUTS:

  • max_treedepth: integer, positive, defaults to 10 For HMC algorithm we can also set:

  • Lambda: Simulation length of one trajectory, double,[0,1].

display

Help track the sampler algorithm by displaying several results. Value 0 display nothing, 1 display the neural network error after each iteration. 2 (HMC only) will display the stepsize and number of leapfrog steps during and after warmup for each iteration. 3 (HMC only) In addition to error function,stepsize, and leapfrog steps it will display the old and new energy for each iteration.

Value

In case of BFGS algorithm the return is the trained BLNN object. In case of NUTS or HMC the returned is a list containing the posterior samples and other algorithm details such as stepsize, acceptance probabilities, effective sample size, Rhat, among others.

References


BLNNdevs/BLNN documentation built on Dec. 10, 2019, 3:31 a.m.