bnns | R Documentation |
This is a generic function for fitting Bayesian Neural Network (BNN) models. It dispatches to methods based on the class of the input data.
bnns(
formula,
data,
L = 1,
nodes = rep(2, L),
act_fn = rep(2, L),
out_act_fn = 1,
iter = 1000,
warmup = 200,
thin = 1,
chains = 2,
cores = 2,
seed = 123,
prior_weights = NULL,
prior_bias = NULL,
prior_sigma = NULL,
verbose = FALSE,
refresh = max(iter/10, 1),
normalize = TRUE,
...
)
formula |
A symbolic description of the model to be fitted. The formula should specify the response variable and predictors (e.g., |
data |
A data frame containing the variables in the model. |
L |
An integer specifying the number of hidden layers in the neural network. Default is 1. |
nodes |
An integer or vector specifying the number of nodes in each hidden layer. If a single value is provided, it is applied to all layers. Default is 16. |
act_fn |
An integer or vector specifying the activation function(s) for the hidden layers. Options are:
|
out_act_fn |
An integer specifying the activation function for the output layer. Options are:
|
iter |
An integer specifying the total number of iterations for the Stan sampler. Default is |
warmup |
An integer specifying the number of warmup iterations for the Stan sampler. Default is |
thin |
An integer specifying the thinning interval for Stan samples. Default is 1. |
chains |
An integer specifying the number of Markov chains. Default is 2. |
cores |
An integer specifying the number of CPU cores to use for parallel sampling. Default is 2. |
seed |
An integer specifying the random seed for reproducibility. Default is 123. |
prior_weights |
A list specifying the prior distribution for the weights in the neural network. The list must include two components:
If
|
prior_bias |
A list specifying the prior distribution for the biases in the neural network. The list must include two components:
If
|
prior_sigma |
A list specifying the prior distribution for the
If
|
verbose |
TRUE or FALSE: flag indicating whether to print intermediate output from Stan on the console, which might be helpful for model debugging. |
refresh |
refresh (integer) can be used to control how often the progress of the sampling is reported (i.e. show the progress every refresh iterations). By default, refresh = max(iter/10, 1). The progress indicator is turned off if refresh <= 0. |
normalize |
Logical. If |
... |
Currently not in use. |
The function serves as a generic interface to different methods of fitting Bayesian Neural Networks. The specific method dispatched depends on the class of the input arguments, allowing for flexibility in the types of inputs supported.
The result of the method dispatched by the class of the input data. Typically, this would be an object of class "bnns"
containing the fitted model and associated information.
Bishop, C.M., 1995. Neural networks for pattern recognition. Oxford university press.
Carpenter, B., Gelman, A., Hoffman, M.D., Lee, D., Goodrich, B., Betancourt, M., Brubaker, M.A., Guo, J., Li, P. and Riddell, A., 2017. Stan: A probabilistic programming language. Journal of statistical software, 76.
Neal, R.M., 2012. Bayesian learning for neural networks (Vol. 118). Springer Science & Business Media.
bnns.default
# Example usage with formula interface:
data <- data.frame(x1 = runif(10), x2 = runif(10), y = rnorm(10))
model <- bnns(y ~ -1 + x1 + x2,
data = data, L = 1, nodes = 2, act_fn = 1,
iter = 1e1, warmup = 5, chains = 1
)
# See the documentation for bnns.default for more details on the default implementation.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.