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: Module

Define 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 length len(layers)-1, and activation[i] controls whether to add the activation to the i-layer.

  • dropout (float or list[float], optional) – Add dropout with this probability after each layer. If a list, this must have length len(layers)-1, and dropout[i] specifies the the dropout probability for the i-th layer.

  • batchnorm (bool or list[bool], optional) – Add batchnorm after each layer. If a list, this must have length len(layers)-1, and batchnorm[i] controls whether to add the batchnorm to the i-th layer.

  • last_layer_activation (bool, optional) – If True and activation, dropout, and batchnorm are added also to the output layer when activation, dropout, or batchnorm (i.e., they are not lists). Otherwise, the output layer will be linear. This option is ignored for the arguments among activation, dropout, and batchnorm that 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 Module instance 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