View source: R/generate_stan_code.R
generate_stan_code | R Documentation |
This function serves as a wrapper to generate Stan code for Bayesian neural networks
tailored to different types of response variables. Based on the specified output
activation function (out_act_fn
), it delegates the code generation to the
appropriate function for continuous, binary, or categorical response models.
generate_stan_code(num_layers, nodes, out_act_fn = 1)
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 |
out_act_fn |
An integer specifying the output activation function, determining the type of response variable. Supported values are:
|
This function dynamically calls one of the following functions based on the value of out_act_fn
:
Continuous response: Calls generate_stan_code_cont
.
Binary response: Calls generate_stan_code_bin
.
Categorical response: Calls generate_stan_code_cat
.
If an unsupported value is provided for out_act_fn
, the function throws an error.
The generated Stan code is adapted for the response type, including appropriate
likelihood functions and transformations.
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, adjusted based on the specified response type.
generate_stan_code_cont: For continuous response models.
generate_stan_code_bin: For binary response models.
generate_stan_code_cat: For categorical response models.
# Generate Stan code for a continuous response model
stan_code <- generate_stan_code(num_layers = 2, nodes = c(10, 5), out_act_fn = 1)
cat(stan_code)
# Generate Stan code for a binary response model
stan_code <- generate_stan_code(num_layers = 2, nodes = c(10, 5), out_act_fn = 2)
cat(stan_code)
# Generate Stan code for a categorical response model
stan_code <- generate_stan_code(num_layers = 2, nodes = c(10, 5), out_act_fn = 3)
cat(stan_code)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.