In this tutorial, I showhow to share neural network layer weights and define custom loss functions. The example code assumes beginner knowledge of Tensorflow 2 and the Keras API.

For a recent project, I wanted to use Tensorflow 2 / Keras to re-implement DeepKoopman, an autoencoder-based neural network architecture described in “Deep learning for universal linear embeddings of nonlinear dynamics”. My end goal was to create a user-friendly version that I could eventually extend

DeepKoopman embeds time series *x* onto data into a low-dimensional coordinate system *y* in which the dynamics are linear.

The DeepKoopman schematic shows that there are three main components:

- The encoder φ, which maps the input to the latent code
- The decoder φ-inverse, which reconstructs the input from the latent code
- The linear dynamics
*K*, which describe how the the latent code evolves over time

To start building the model, we can define the three sub-models as follows: