Evolvable Long Short-Term Memory (LSTM)

Parameters

class agilerl.modules.lstm.EvolvableLSTM(*args, **kwargs)

The Evolvable Long Short-Term Memory (LSTM) class.

Parameters:
  • input_size (int) – Size of input features

  • hidden_size (int) – Size of hidden state

  • num_outputs (int) – Output dimension

  • num_layers (int) – Number of LSTM layers stacked together

  • output_activation (str, optional) – Output activation layer, defaults to None

  • min_hidden_size (int, optional) – Minimum hidden state size, defaults to 32

  • max_hidden_size (int, optional) – Maximum hidden state size, defaults to 512

  • min_layers (int, optional) – Minimum number of LSTM layers, defaults to 1

  • max_layers (int, optional) – Maximum number of LSTM layers, defaults to 3

  • dropout (float, optional) – Dropout probability between LSTM layers, defaults to 0.0

  • device (str, optional) – Device for accelerated computing, ‘cpu’ or ‘cuda’, defaults to ‘cpu’

  • name (str, optional) – Name of the network, defaults to ‘lstm’

property activation: str

Returns activation function.

add_layer() None

Adds an LSTM layer to the network. Falls back on add_node() if max layers reached.

add_node(numb_new_nodes: int | None = None) Dict[str, int]

Increases hidden size of the LSTM.

Parameters:

numb_new_nodes (int, optional) – Number of nodes to add to hidden size, defaults to None

Returns:

Dictionary with number of new nodes

Return type:

Dict[str, int]

change_activation(activation: str, output: bool = False) None

Set the output activation function for the network.

Parameters:
  • activation (str) – Activation function to use.

  • output (bool, optional) – Flag indicating whether to set the output activation function, defaults to False

create_lstm() ModuleDict

Creates and returns an LSTM network with the current configuration.

Returns:

LSTM network

Return type:

nn.ModuleDict

forward(x: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes] | Tensor, states: Tuple[Tensor, Tensor] | None = None) Tensor

Forward pass of the network.

Parameters:
  • x (ArrayOrTensor) – Input tensor

  • states (Tuple[torch.Tensor, torch.Tensor], optional) – Tuple of hidden and cell states, defaults to None

Returns:

Output tensor

Return type:

torch.Tensor

get_output_dense() Module

Returns output layer of neural network.

property net_config: Dict[str, Any]

Returns model configuration in dictionary format.

recreate_network() None

Recreates the LSTM network with current parameters.

remove_layer() None

Removes an LSTM layer from the network. Falls back on add_node() if min layers reached.

remove_node(numb_new_nodes: int | None = None) Dict[str, int]

Decreases hidden size of the LSTM.

Parameters:

numb_new_nodes (int, optional) – Number of nodes to remove from hidden size, defaults to None

Returns:

Dictionary with number of new nodes

Return type:

Dict[str, int]