raminmh/liquid_time_constant_networks

Code Repository for Liquid Time-Constant Networks (LTCs)

Python

1,867

9 commits

updated Jun 3, 2024

See the code

README

Liquid time-constant Networks (LTCs)

[Update] A Pytorch version together with tutorials are added to our sister repository: https://github.com/mlech26l/ncps

This is the official repository for LTC networks described in the paper: https://arxiv.org/abs/2006.04439 This repository allows you to train continuous-time models with backpropagation through-time (BPTT). Available Continuous-time models are:

Requisites

All models were implemented and tested with TensorFlow 1.14.0 and python3 on Ubuntu 16.04 and 18.04 machines. All the following steps assume that they are executed under these conditions.

Preparation

First, we have to download all datasets by running

source download_datasets.sh

This script creates a folder data, where all downloaded datasets are stored.

Training and evaluating the models

There is exactly one Python module per dataset:

  • Hand gesture segmentation: gesture.py
  • Room occupancy detection: occupancy.py
  • Human activity recognition: har.py
  • Traffic volume prediction: traffic.py
  • Ozone level forecasting: ozone.py

Each script accepts the following four arguments:

  • --model: lstm | ctrnn | ltc | ltc_rk | ltc_ex
  • --epochs: number of training epochs (default 200)
  • --size: number of hidden RNN units (default 32)
  • --log: interval of how often to evaluate validation metric (default 1)

Each script trains the specified model for the given number of epochs and evaluates the validation performance after every log steps. At the end of the training, the best-performing checkpoint is restored and the model is evaluated on the test set. All results are stored in the results folder by appending the result to CSV file.

For example, we can train and evaluate the CT-RNN by executing

python3 har.py --model ctrnn

After the script is finished there should be a file results/har/ctrnn_32.csv created, containing the following columns:

  • best epoch: Epoch number that achieved the best validation metric
  • train loss: Training loss achieved at the best epoch
  • train accuracy: Training metric achieved at the best epoch
  • valid loss: Validation loss achieved at the best epoch
  • valid accuracy: Best validation metric achieved during training
  • test loss: Loss on the test set
  • test accuracy: Metric on the test set

Hyperparameters

ParameterValueDescription
Minibatch size16Number of training samples over which the gradient descent update is computed
Learning rate0.001/0.020.01-0.02 for LTC, 0.001 for all other models.
Hidden units32Number of hidden units of each model
OptimizerAdamSee (Kingma and Ba, 2014)
beta_10.9Parameter of the Adam method
beta_20.999Parameter of the Adam method
epsilon1e-08Epsilon-hat parameter of the Adam method
Number of epochs200Maximum number of training epochs
BPTT length32Backpropagation through time length in time-steps
ODE solver sreps1/6relative to input sampling period
Validation evaluation interval1Interval of training epochs when the metrics on the validation are evaluated

Trajectory Length Analysis

Run the main.m file to get trajectory length results for the desired setting tuneable in the code.

deep-learning
liquid-neural-networks
recurrent-neural-networks
sequence-modeling
state-space-models
time-series

raminmh/liquid_time_constant_networks

Code Repository for Liquid Time-Constant Networks (LTCs)

Python

1,867

9 commits

updated Jun 3, 2024

See the code

README

Liquid time-constant Networks (LTCs)

[Update] A Pytorch version together with tutorials are added to our sister repository: https://github.com/mlech26l/ncps

This is the official repository for LTC networks described in the paper: https://arxiv.org/abs/2006.04439 This repository allows you to train continuous-time models with backpropagation through-time (BPTT). Available Continuous-time models are:

Requisites

All models were implemented and tested with TensorFlow 1.14.0 and python3 on Ubuntu 16.04 and 18.04 machines. All the following steps assume that they are executed under these conditions.

Preparation

First, we have to download all datasets by running

source download_datasets.sh

This script creates a folder data, where all downloaded datasets are stored.

Training and evaluating the models

There is exactly one Python module per dataset:

  • Hand gesture segmentation: gesture.py
  • Room occupancy detection: occupancy.py
  • Human activity recognition: har.py
  • Traffic volume prediction: traffic.py
  • Ozone level forecasting: ozone.py

Each script accepts the following four arguments:

  • --model: lstm | ctrnn | ltc | ltc_rk | ltc_ex
  • --epochs: number of training epochs (default 200)
  • --size: number of hidden RNN units (default 32)
  • --log: interval of how often to evaluate validation metric (default 1)

Each script trains the specified model for the given number of epochs and evaluates the validation performance after every log steps. At the end of the training, the best-performing checkpoint is restored and the model is evaluated on the test set. All results are stored in the results folder by appending the result to CSV file.

For example, we can train and evaluate the CT-RNN by executing

python3 har.py --model ctrnn

After the script is finished there should be a file results/har/ctrnn_32.csv created, containing the following columns:

  • best epoch: Epoch number that achieved the best validation metric
  • train loss: Training loss achieved at the best epoch
  • train accuracy: Training metric achieved at the best epoch
  • valid loss: Validation loss achieved at the best epoch
  • valid accuracy: Best validation metric achieved during training
  • test loss: Loss on the test set
  • test accuracy: Metric on the test set

Hyperparameters

ParameterValueDescription
Minibatch size16Number of training samples over which the gradient descent update is computed
Learning rate0.001/0.020.01-0.02 for LTC, 0.001 for all other models.
Hidden units32Number of hidden units of each model
OptimizerAdamSee (Kingma and Ba, 2014)
beta_10.9Parameter of the Adam method
beta_20.999Parameter of the Adam method
epsilon1e-08Epsilon-hat parameter of the Adam method
Number of epochs200Maximum number of training epochs
BPTT length32Backpropagation through time length in time-steps
ODE solver sreps1/6relative to input sampling period
Validation evaluation interval1Interval of training epochs when the metrics on the validation are evaluated

Trajectory Length Analysis

Run the main.m file to get trajectory length results for the desired setting tuneable in the code.

deep-learning
liquid-neural-networks
recurrent-neural-networks
sequence-modeling
state-space-models
time-series

Significant stargazers

Jinheng Xie

300 followers · starred Jan 2022

brockelmore

874 followers · starred Oct 2021

Harry Julian

31 followers · starred Jan 2024

Weston Platter

175 followers · starred Feb 2023