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 num_layers.

out_act_fn

An integer specifying the output activation function, determining the type of response variable. Supported values are:

  • 1: Continuous response (identity function as output layer).

  • 2: Binary response (sigmoid function as output layer).

  • 3: Categorical response (softmax function as output layer).

Details

This function dynamically calls one of the following functions based on the value of out_act_fn:

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

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)


[Package bnns version 0.1.2 Index]