FeedForward#
- class FeedForward(input_dimensions, output_dimensions, inner_size=20, n_layers=2, func=<class 'torch.nn.modules.activation.Tanh'>, layers=None, bias=True)[source]#
Bases:
Module
Feed Forward neural network model class, also known as Multi-layer Perceptron.
Initialization of the
FeedForward
class.- Parameters:
input_dimensions (int) – The number of input components. The expected tensor shape is \((*, d)\), where * represents any number of preceding dimensions (including none), and \(d\) corresponds to
input_dimensions
.output_dimensions (int) – The number of output components . The expected tensor shape is \((*, d)\), where * represents any number of preceding dimensions (including none), and \(d\) corresponds to
output_dimensions
.inner_size (int) – The number of neurons for each hidden layer. Default is
20
.n_layers (int) – The number of hidden layers. Default is
2
.func (torch.nn.Module | list[torch.nn.Module]) – The activation function. If a list is passed, it must have the same length as
n_layers
. If a single function is passed, it is used for all layers, except for the last one. Default istorch.nn.Tanh
.layers (list[int]) – The list of the dimension of inner layers. If
None
,n_layers
of dimensioninner_size
are used. Otherwise, it overrides the values passed ton_layers
andinner_size
. Default isNone
.bias (bool) – If
True
bias is considered for the basis function neural network. Default isTrue
.
- Raises:
ValueError – If the input dimension is not an integer.
ValueError – If the output dimension is not an integer.
RuntimeError – If the number of layers and functions are inconsistent.
- forward(x)[source]#
Forward pass for the
FeedForward
model.- Parameters:
x (torch.Tensor | LabelTensor) – The input tensor.
- Returns:
The output tensor.
- Return type: