Recurrent Models#
RNN-based architectures for sequential time-series modeling.
RecurrentAutoEncoder#
Multi-layer recurrent autoencoder supporting LSTM, GRU, and vanilla RNN cells. Uses time-reversed encoder output for sequence reconstruction.
Recurrent autoencoder based on PyLink88/Recurrent-Autoencoder.
- class chronocratic.models.recurrent.recurrentae.model.RecurrentAutoEncoder(input_dims: int, layers: tuple[int, ...], recurrent_cell_type: RecurrentCellType = RecurrentCellType.LSTM, dropout: float | tuple[float, ...] = 0.2, loss: ReconstructionLoss = ReconstructionLoss.MSE, optimizer: OptimizerName = OptimizerName.ADAM, learning_rate: float = 0.001, sync_dist: bool = False)#
Bases:
LightningModule,BasicEncodingMixinRecurrent autoencoder for time series representation learning.
Architecture based on PyLink88/Recurrent-Autoencoder. Supports LSTM, GRU, and RNN variants selected via
recurrent_cell_type. The encoder maps the input to a latent sequence via stacked RNN layers; the decoder reconstructs the original sequence from the time-reversed latent sequence using a mirrored RNN stack followed by a linear projection.- Parameters:
input_dims – Number of input features (channels) per timestep.
layers – Hidden sizes for each encoder RNN layer, e.g.
(64, 32). The decoder uses the reversed order.recurrent_cell_type – RNN variant — LSTM, GRU, or RNN.
dropout – Dropout probability applied between successive layers. A single float applies uniformly; a tuple must match
len(layers).loss – Reconstruction objective —
'mse'or'mae'.optimizer – Optimizer —
'adam','adamw', or'radam'.learning_rate – Base learning rate for the optimizer.
sync_dist – Whether to sync logged metrics across devices.
- property encoder: Module#
The encoder
nn.Module.
- property decoder: Module#
The decoder
nn.Module.
- forward(x: Tensor) Tensor#
Encode
x, reverse the latent sequence, and reconstruct.
- training_step(batch: Tensor, _batch_idx: int) Tensor#
Compute and log reconstruction loss for a training batch.
- validation_step(batch: Tensor, _batch_idx: int) Tensor#
Compute and log reconstruction loss for a validation batch.
- configure_optimizers() OptimizerLRScheduler#
Return the optimizer configured with the model’s learning rate.
Configuration for the RecurrentAutoEncoder model.
- class chronocratic.models.recurrent.recurrentae.config.RecurrentAutoEncoderModelParameters(*, input_dims: int, layers: tuple[int, ...], recurrent_cell_type: RecurrentCellType = RecurrentCellType.LSTM, dropout: float | tuple[float, ...] = 0.2, loss: ReconstructionLoss = ReconstructionLoss.MSE, optimizer: OptimizerName = OptimizerName.ADAM, learning_rate: float = 0.001, sync_dist: bool = False)#
Bases:
objectConfiguration for the recurrent autoencoder model.
- Parameters:
input_dims – Number of input features (channels) per timestep.
layers – Hidden sizes for each encoder RNN layer, e.g.
(64, 32). The decoder uses the reversed order.recurrent_cell_type – RNN variant — LSTM, GRU, or RNN.
dropout – Dropout probability applied between successive layers. A single float applies uniformly; a tuple must match
len(layers).loss – Reconstruction objective —
'mse'or'mae'.optimizer – Optimizer —
'adam','adamw', or'radam'.learning_rate – Base learning rate for the optimizer.
sync_dist – Whether to sync logged metrics across devices.
- class chronocratic.models.recurrent.enums.OptimizerName(*values)#
Bases:
StrEnumOptimizer variants for recurrent autoencoder training.
- class chronocratic.models.recurrent.enums.ReconstructionLoss(*values)#
Bases:
StrEnumReconstruction loss functions for the autoencoder objective.
- class chronocratic.models.recurrent.enums.RecurrentCellType(*values)#
Bases:
StrEnumRecurrent cell variants for the autoencoder backbone.
TimeNet#
GRU-based encoder-decoder with autoencoder pretraining. Uses BasicEncodingMixin for inference.
- class chronocratic.models.recurrent.timenet.model.TimeNet(hidden_dims: int, depth: int, input_dims: int = 1, dropout_rate: float = 0.1, learning_rate: float = 0.001)#
Bases:
LightningModule,BasicEncodingMixinTimeNet Model.
This model was implemented based on the code available on this GitHub repo paudan/TimeNet under MIT License.
- property encoder: Sequential#
Return the GRU encoder.
- property decoder: Sequential#
Return the GRU decoder.
- forward(x: Tensor) Tensor#
Reconstruct
xfrom the reversed encoder sequence.
- training_step(batch: Tensor, _batch_idx: int) Tensor#
Compute and log the training reconstruction loss.
- validation_step(batch: Tensor, _batch_idx: int) Tensor#
Compute and log the validation reconstruction loss.
- configure_optimizers() OptimizerLRScheduler#
Return the Adam optimizer used to train TimeNet.
Configuration for the TimeNet model.
Provides TimeNetModelParameters with settings for the GRU encoder / decoder pair used by the autoencoder pretraining objective.
- class chronocratic.models.recurrent.timenet.config.TimeNetModelParameters(*, hidden_dims: int, depth: int, input_dims: int = 1, dropout_rate: float = 0.1, learning_rate: float = 0.001)#
Bases:
objectConfiguration for the TimeNet model.
- Parameters:
hidden_dims – Number of hidden units in each GRU layer of the encoder and decoder.
depth – Number of stacked GRU layers in each of the encoder and decoder.
input_dims – Number of input features (channels) in the time series.
dropout_rate – Dropout probability inserted between successive GRU layers.
0disables dropout.learning_rate – Base learning rate for the Adam optimizer.