Skip to main content

Encoder

The Encoder maps input time series data into a latent representation. It is wrapped by the Encoder class in src/models/encoder/encoder.py.

Implementation

To add a new encoder:

  1. Create the File: Add a new file in src/models/encoder/models/ (e.g., my_encoder.py).
  2. Inherit: Create a class inheriting from HierarchisedModel (or a subclass like BaseEncoder).
  3. Implement Methods:
    • default_hyperparameters()
    • initialize_group_level_params(...)
    • initialize_subject_level_params(...)
    • construct_params(...)
    • forward(...)
    • Optional: restructure_hyperparameters(...) if you need to modify config structure (e.g., StackedConvolutions uses this).

Configuration Resolution & Registration

You must register the new encoder in src/models/encoder/encoder.py.

1. In Encoder.__init__

Add a case to the match encoder["name"]: block to instantiate your class.

match encoder["name"]:
case "MyEncoder":
self.encoder_model = MyEncoder

2. In Encoder.resolve_config

Add a case to the match encoder["name"]: block to get the class for default hyperparameters.

match encoder["name"]:
case "MyEncoder":
encoder_model = MyEncoder

The system will automatically merge user-provided hyperparameters in config["encoder"]["hyperparameters"] with your default_hyperparameters(). It also injects bottleneck_dim and latent_dim into the configuration.