braindecode.modules.MLP#

class braindecode.modules.MLP(in_features, hidden_features=None, out_features=None, activation=<class 'torch.nn.modules.activation.GELU'>, drop=0.0, normalize=False)[source]#

Multilayer Perceptron (MLP) with GELU activation and optional dropout.

Also known as fully connected feedforward network, an MLP is a sequence of non-linear parametric functions

\[h_{i + 1} = a_{i + 1}(h_i W_{i + 1}^T + b_{i + 1}),\]

over feature vectors \(h_i\), with the input and output feature vectors \(x = h_0\) and \(y = h_L\), respectively. The non-linear functions \(a_i\) are called activation functions. The trainable parameters of an MLP are its weights and biases \(\\phi = \{W_i, b_i | i = 1, \dots, L\}\).

Parameters:
  • in_features (int) – Number of input features.

  • hidden_features (Sequential[int] (default=None)) – Number of hidden features, if None, set to in_features. You can increase the size of MLP just passing more int in the hidden features vector. The model size increase follow the rule 2n (hidden layers)+2 (in and out layers)

  • out_features (int (default=None)) – Number of output features, if None, set to in_features.

  • act_layer (nn.GELU (default)) – The activation function constructor. If None, use torch.nn.GELU instead.

  • drop (float (default=0.0)) – Dropout rate.

  • normalize (bool (default=False)) – Whether to apply layer normalization.