View source: R/generate_stan_code.R
generate_stan_code_cat | R Documentation |
This function generates Stan code for modeling a categorical response using neural networks with multiple layers. The generated code supports customizable activation functions for each layer and softmax-based prediction for the categorical output.
generate_stan_code_cat(num_layers, nodes)
num_layers |
Integer. Number of layers in the neural network. |
nodes |
Integer vector. Number of nodes in each layer. The length of
this vector must match |
The Stan code includes the following components:
Data Block: Defines inputs, response variable, layer configurations, and activation functions.
Parameters Block: Declares weights and biases for all layers and the output layer.
Transformed Parameters Block: Computes intermediate outputs (z
and a
) for each layer
and calculates the final predictions (y_hat
) using the softmax function.
Model Block: Specifies priors for parameters and models the categorical response
using categorical_logit
.
Supported activation functions for the hidden layers:
1: Tanh
2: Sigmoid
3: Softplus
4: ReLU
5: linear
The categorical response (y
) is assumed to take integer values from 1 to K
,
where K
is the total number of categories.
A string containing the Stan code for the specified neural network architecture and categorical response model.
generate_stan_code_bin()
, generate_stan_code_cont()
# Generate Stan code for a neural network with 3 layers
num_layers <- 3
nodes <- c(10, 8, 6) # 10 nodes in the first layer, 8 in the second, 6 in the third
stan_code <- generate_stan_code_cat(num_layers, nodes)
cat(stan_code)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.