Evolvable CNN → LSTM encoder

Use with recurrent=True on algorithms such as PPO when observations are 3D image Box spaces (partial observability over pixels). The trainer and EvolvableNetwork select this encoder automatically; manifests declare arch: cnn_lstm under encoder_config.

Parameters

class agilerl.modules.cnn_lstm.EvolvableCnnLstm(*args: Any, **kwargs: Any)

Convolutional feature extractor followed by an LSTM for image POMDPs.

Hidden-state keys follow EvolvableLSTM: {name}_h and {name}_c. Architecture mutation is disabled until composite evolvable mutations exist.

Parameters:
  • input_shape (list[int]) – Channel-first image shape (channels, height, width).

  • num_outputs (int) – Encoder output dimension.

  • net_config (CnnLstmNetConfig | dict[str, Any]) – CNN trunk and LSTM head fields (CnnLstmNetConfig).

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

Set the activation function for the network.

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

  • output (bool) – Whether to set the activation function for the output layer.

create_network() → ModuleDict

Build the CNN trunk, LSTM, and output projection.

forward(x: ndarray[tuple[int, ...], dtype[_ScalarType_co]] | Tensor, hidden_state: dict[str, Tensor] | None = None) → tuple[Tensor, dict[str, Tensor]]

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.

init_weights_gaussian(std_coeff: float = 4, output_coeff: float = 4) → None

Initialise the LSTM output linear layer with a Gaussian distribution.

Parameters:
  • std_coeff – Standard deviation coefficient, defaults to 4

  • output_coeff – Unused; only the output linear layer is initialised.

recreate_network() → None

Recreate the network after a mutation has been applied. If the mutation methods of an EvolvableModule are only attributed to its nested modules, then the recreate_network method should be implemented in the nested modules and it is not required on the parent.