generate_stan_code {bnns} | R Documentation |
Internal function to generate Stan Code Based on Output Activation Function
Description
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.
Usage
generate_stan_code(num_layers, nodes, out_act_fn = 1)
Arguments
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:
|
Details
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.
Value
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.
See Also
-
generate_stan_code_cont: For continuous response models.
-
generate_stan_code_bin: For binary response models.
-
generate_stan_code_cat: For categorical response models.
Examples
# 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)