View source: R/generate_stan_code.R
generate_stan_code_cont | R Documentation |
This function generates Stan code for a Bayesian neural network model designed to predict continuous response variables. The Stan code is dynamically constructed based on the specified number of hidden layers and nodes per layer. It supports various activation functions for the hidden layers, including tanh, sigmoid, softplus and relu.
generate_stan_code_cont(num_layers, nodes)
num_layers |
An integer specifying the number of hidden layers in the neural network. |
nodes |
A vector of integers, where each element specifies the number of nodes
in the corresponding hidden layer. The length of the vector must match |
The generated Stan code models a continuous response variable using a neural network. The hidden layers apply the specified activation functions, while the output layer performs a linear transformation to predict the response. The likelihood assumes normally distributed residuals.
For one hidden layer: The function simplifies the Stan code structure.
For multiple hidden layers: The code dynamically includes additional layers based on the input arguments.
Supported activation functions for the hidden layers:
1: Tanh
2: Sigmoid
3: Softplus
4: ReLU
5: linear
A character string containing the Stan code for the specified Bayesian neural network model. The Stan model includes data, parameters, transformed parameters, and model blocks. The code is adjusted based on whether the network has one or multiple hidden layers.
# Generate Stan code for a single hidden layer with 10 nodes
stan_code <- generate_stan_code_cont(1, c(10))
cat(stan_code)
# Generate Stan code for two hidden layers with 8 and 4 nodes
stan_code <- generate_stan_code_cont(2, c(8, 4))
cat(stan_code)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.