In this blog post, we compare the Liquid closed-form continuous-time neural network (CfC), as described by ,  and , to the Long-Short Term Memory (LSTM) neural network and a simple Linear neural network to see how each model learns to track a simple Sine curve over time.
To keep things simple, each test uses the same number of 82 inputs and have a single output which is trained to follow the Sine curve. The same AdamW optimizer is used with each model and the train/run cycle consists of a single batch for each cycle.
The train/run cycle used looks as follows.
- Use the past 82 points from the current position on the Sine curve as the current input.
- Run a forward pass with batch size = 1
- Run a backward pass with batch size = 1
- Step and apply the weight updates with the optimizer.
- And apply the weight updates and repeat.
- Move to the next position on the curve and repeat step #1 above.
Simple Linear Model
In our first test, we ran a simple Linear neural network with the following model.
The Simple Linear model uses an InnerProduct layer which is sent the past 82 points on the Sine curve via the input blob x, the blobs tt and mask are ignored, and the target is set to the last of the 82 points for we want to learn to track the Sine curve.
When running, the model initially servos into the Sine curve after around 150 steps which is great!
However, shortly after around 200 steps the predictions start experiencing significant jitter.
LSTM and Linear Model
Next, we added a Long-Short Term Memory (LSTM) layer to the model to learn the temporal nature of the Sine curve.
The LSTM + Linear model adds an LSTM layer to the InnerProduct layer which has a single output for the prediction, like the Simple Linear model. In addition, the NVIDIA CuDnn implementation is used for the low-level LSTM implementation because of its fast computation speed. The LSTM layer is configured to use 2 layers internally.
First the LSTM Model starts with a considerable amount of noise.
However, after around 900 iterations, the model learns to lock onto the Sine curve.
Liquid Closed-form continuous-time (CfC) Model
And finally, lets see how the Liquid Closed-form continuous-time (CfC) model performs when learning the Sine curve.
The CfC Model locks onto the target Sine curve very quickly in around 126 steps.
And once locked on the CfC model does a good job of staying on target, which is one of the benefits of the CfC model.
We believe this quick locking onto the target can be attributed to the servoing action caused by the combination of the internal Sigmoid function and inverse Sigmoid function that are combined within the CfC Unit Layer. To read more about how this works, see our blog post Closed-form Continuous-time Liquid Neural Net Models – A Programmer’s Perspective.
When comparing the Liquid CfC Model to the LSTM and Simple Linear models, there really is no comparison as the CfC locks on target over 7x faster than the LSTM and the Simple Linear is too noisy to be usable.
As a side note, we have observed the CfC Model experience a very small amount of jitter (as can be seen on the right side of the CfC image above) during very short durations which may be caused by a vanishing gradient. However, combining the LSTM with the CfC may eliminate this jitter as doing so is recommended by the original paper to alleviate the vanishing gradient problem , .
Happy Deep Learning with MyCaffe and Liquid CfC Neural Networks!
 Closed-form Continuous-time Neural Models, by Ramin Hasani, Mathias Lechner, Alexander Amini, Lucas Liebenwein, Aaron Ray, Max Tschaikowski, Gerald Teschl, Daniela Rus, 2021, arXiv:2106.13898
 Closed-form continuous-time neural networks, by Ramin Hasani, Mathias Lechner, Alexander Amini, Lucas Liebenwein, Aaron Ray, Max Tschaikowski, Gerald Teschl, Daniela Rus, 2022, nature machine intelligence
 GitHub: Closed-form Continuous-time Models, by Ramin Hasani, 2021, GitHub