Components

This section describes the main BELLA components you can use in your BEAST XML files. The core component is the BayesMLP, which implements a Bayesian multilayer perceptron (MLP) to map predictor variables to phylodynamic parameters. Additionally, BELLA includes several ActivationFunctions that can be used within the MLP. These components rely on standard BEAST interfaces such as CalculationNode, RealParameter, Function, and Loggable, and are designed to be flexible and integrate seamlessly with BEAST 2's MCMC framework.

bella.BayesMLP

BayesMLP is the main BELLA component you reference in a BEAST XML. It extends CalculationNode and implements Function and Loggable, which makes it:

A BayesMLP represents a fully connected feedforward neural network (multilayer perceptron, MLP) with arbitrary hidden layers, used to map predictor variables to phylodynamic parameters.

It has the following BEAST XML attributes:

When a BayesMLP object is initialized, the class builds the full layer sizes, using the number of predictors as the size of the input layer and 1 as the size of the output layer. So if you pass nodes="16 8" and you have 3 predictors, the internal layer sizes are: \([3, 16, 8, 1]\). That implies 3 weight matrices:

Because of this, the number of weights parameters must equal the number of hidden layers + 1. If not, an error is raised during initialization.

Predictor values are managed within the class as a matrix of size \((\text{num_observations} \times \text{num_predictors})\). Each row corresponds to one observation (e.g., a time bin), and each column to one predictor variable. When performing a forward pass, the entire matrix is processed at once, yielding an output vector of size \((\text{num_observations} \times 1)\). Thus, each observation gets its own predicted rate.

BayesMLP implements the Loggable interface, which makes it possible to log the network weights during MCMC. When you add a BayesMLP to the BEAST log, it will output one column per weight in the network, using the following format: <id>W.Layer<X>[<i>][<j>], where:

bella.activations

Activation functions are used within the BayesMLP to introduce nonlinearity. BELLA provides several built-in activation functions that you can specify in your BEAST XML configuration:

The output activation function is a useful way to enforce particular behaviors on the network’s output, such as bounding rates within a specific range using the sigmoid function. The hidden activation function is typically set to ReLU because its non-saturating linear regime avoids compression of activity and supports a wide dynamic range.