Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


Code to fully reproduce benchmark results (and to extend for your own purposes) from the paper:

Krishnan, Shalit, Sontag. Structured Inference Networks for Nonlinear State Space Models, arXiv:1609.09869, 2016.


The goal of this package is to provide a black box inference algorithm for learning models of time-series data. Inference during learning and at test time is based on compiled recognition or inference network.


The figure below describes a simple model of time-series data.

This method is a good fit if:

  • You have an arbitrarily specified state space model whose parameters you're interested in fitting.
  • You would like to have a method for fast posterior inference at train and test time
  • Your temporal generative model has Gaussian latent variables (mean/variance can be a nonlinear function of previous timestep's variables).

Deep Kalman Filter

The code uses variational inference during learning to maximize the likelihood of the observed data:

Evidence Lower Bound

Generative Model

  • The latent variables z1...zT and the observations x1...xT describe the generative process for the data.
  • The figure depicts a state space model for time-varying data.
  • The emission and transition functions may be pre-specified to have a fixed functional form, a parametric functional form, a function parameterized by a deep neural networks or some combination thereof.

Inference Model

The box q(z1..zT | x1...xT) represents the inference network. There are several supported inference networks within this package.

  • Inference implemented with a bi-directional LSTM
  • Inference implemented with an LSTM conditioned on observations in the future
  • Inference implemented with an LSTM conditioned on observations from the past



This package has the following requirements:


Theano Used for automatic differentiations

[theanomodels] ( Wrapper around theano that takes care of bookkeeping, saving/loading models etc. Clone the github repository and add its location to the PYTHONPATH environment variable so that it is accessible by python.

[pykalman] ( [Optional: For running baseline UKFs/KFs]

An NVIDIA GPU w/ atleast 6G of memory is recommended.

Once the requirements have been met, clone this repository and it's ready to run.

Folder Structure

The following folders contain code to reproduct the results reported in our paper:

  • expt-synthetic, expt-polyphonic: Contains code and instructions for reproducing results from the paper.
  • baselines/: Contains to run some of the baseline algorithms on the synthetic data
  • ipynb/: Ipython notebooks for visualizing saved checkpoints and building plots

The main files of interest are:

  • Arguments that the model expects to be present. Looking through it is useful to understand the different knobs available to tune the model.
  • stinfmodel/ Code to construct the inference and generative model. The code is commented to enable easy modification for different scenarios.
  • stinfmodel/ Code to evaluate the Deep Kalman Filter's performance during learning.
  • stinfmodel/ Code for performing stochastic gradient ascent in the Evidence Lower Bound.


We use numpy tensors to store the datasets with binary numpy masks to allow batch sizes comprising sequences of variable length. We train the models using mini-batch gradient descent on negative ELBO.


The code to run on polyphonic and synthetic datasets has already been created in the theanomodels repository. See theanomodels/datasets/ for how the dataset is created and loaded.

The datasets are stored in three dimensional numpy tensors. To deal with datapoints of different lengths, we use numpy matrices comprised of binary masks. There may be different choices to manipulate data that you may adopt depending on your needs and this is merely a guideline.

assert type(dataset) is dict,'Expecting dictionary'
dataset['train'] # N_train x T_train_max x dim_observation : training data
dataset['test']  # N_test  x T_test_max  x dim_observation : validation data
dataset['valid'] # N_valid x T_valid_max x dim_observation : test data
dataset['mask_train'] # N_train x T_train_max : training masks
dataset['mask_test']  # N_test  x T_test_max  : validation masks
dataset['mask_valid'] # N_valid x T_valid_max : test masks
dataset['data_type'] # real/binary
dataset['has_masks'] # true/false

During learning, we select a minibatch of these tensors to update the weights of the model.

Running on different datasets

See the folder expt-template for an example of how to setup your data and run the code on your data


  title={Structured Inference Networks for Nonlinear State Space Models},
  author={Krishnan, Rahul G and Shalit, Uri and Sontag, David},

This paper subsumes the work in : [Deep Kalman Filters] (


DMMs for human pose forecasting. Fork of clinicalml/structuredinference (disassociated by Github because it was private for a while)







No releases published


No packages published