AutoEncoderLoss¶
- class kooplearn.torch.nn.AutoEncoderLoss(alpha_rec: float = 1.0, alpha_lin: float = 1.0, alpha_pred: float = 1.0)[source]¶
Bases:
ModuleSingle-step Dynamic Autoencoder (DAE) loss introduced by Lusch et al. [1].
This loss combines three objectives to train dynamic autoencoders:
Reconstruction loss — measures how well the autoencoder reconstructs inputs.
Linearity loss — enforces linear evolution in latent space.
Prediction loss — penalizes errors between predicted and actual encoded outputs.
The total loss is a weighted sum:
\[\mathcal{L} = \alpha_\mathrm{rec} \, \|x - \phi^{-1}(\phi(x)) \|^2 + \alpha_\mathrm{lin} \, \|\phi(y) - K\phi(x) \|^2 + \alpha_\mathrm{pred} \, \|y - \phi^{-1}(K\phi(x))\|^2\]where \(\phi^{-1}(\phi(x))\) is the reconstruction of \(x\), \(\phi(y)\) is the encoded output, \(K\phi(x)\) is the evolved input latent representation, and \(\phi^{-1}(K\phi(x))\) is the predicted decoded output.
Hint
Check out the Ordered MNIST example for a practical use of this loss function.
Methods
- forward(x: Tensor, y: Tensor, x_rec: Tensor, y_enc: Tensor, x_evo: Tensor, y_pred: Tensor) Tensor[source]¶
Compute the Dynamic Autoencoder loss.
- Parameters:
x (
torch.Tensor) – Input features of shape(N, D), whereNis the batch size andDis the feature dimension.y (
torch.Tensor) – Output (target) features. Same shape asx.x_rec (
torch.Tensor) – Reconstructed version of the inputxproduced by the decoder. Same shape asx.y_enc (
torch.Tensor) – Encoded latent representation of the targety.x_evo (
torch.Tensor) – Evolved latent representation obtained by applying the learned linear operator to the latent encoding ofx. Same shape asx.y_pred (
torch.Tensor) – Predicted decoded output corresponding to the evolved latent state. Same shape asx.
- Returns:
A scalar tensor representing the total dynamic autoencoder loss.
- Return type:
torch.Tensor
Bethany Lusch, J. Nathan Kutz, and Steven L. Brunton. Deep learning for universal linear embeddings of nonlinear dynamics. Nature Communications, November 2018. URL: https://doi.org/10.1038/s41467-018-07210-0, doi:10.1038/s41467-018-07210-0.