mlcolvar.core.nn.FeedForward¶
- class mlcolvar.core.nn.FeedForward(layers: list, activation: str | list = 'relu', dropout: float | list | None = None, batchnorm: bool | list = False, last_layer_activation: bool = False, **kwargs)[source]¶
Bases:
ModuleDefine a feedforward neural network given the list of layers.
Optionally dropout and batchnorm can be applied (the order is batchnorm -> dropout -> activation).
- __init__(layers: list, activation: str | list = 'relu', dropout: float | list | None = None, batchnorm: bool | list = False, last_layer_activation: bool = False, **kwargs)[source]¶
Constructor.
- Parameters:
layers (list) – Number of neurons per layer.
activation (string or list[str], optional) – Add activation function (options: relu, tanh, elu, linear). If a
list, this must have lengthlen(layers)-1, andactivation[i]controls whether to add the activation to thei-layer.dropout (float or list[float], optional) – Add dropout with this probability after each layer. If a
list, this must have lengthlen(layers)-1, anddropout[i]specifies the the dropout probability for thei-th layer.batchnorm (bool or list[bool], optional) – Add batchnorm after each layer. If a
list, this must have lengthlen(layers)-1, andbatchnorm[i]controls whether to add the batchnorm to thei-th layer.last_layer_activation (bool, optional) – If
Trueand activation, dropout, and batchnorm are added also to the output layer whenactivation,dropout, orbatchnorm(i.e., they are not lists). Otherwise, the output layer will be linear. This option is ignored for the arguments amongactivation,dropout, andbatchnormthat are passed as lists.**kwargs – Optional arguments passed to torch.nn.Module
Methods
__init__(layers[, activation, dropout, ...])Constructor.
backward(loss, *args, **kwargs)forward(x)Define the computation performed at every call.
- forward(x: Tensor) Tensor[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
Attributes
T_destination
call_super_init
dump_patches
training