generate_stan_code_cont {bnns}R Documentation

Internal function to generate Stan Code for Continuous Response Models

Description

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.

Usage

generate_stan_code_cont(num_layers, nodes)

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.

Details

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.

Supported activation functions for the hidden layers:

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. The code is adjusted based on whether the network has one or multiple hidden layers.

Examples

# 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)


[Package bnns version 0.1.2 Index]