Skip to content
Pytorch implementation for "Particle Flow Bayes' Rule"
Branch: master
Clone or download
Latest commit 2fb400f Jun 22, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
pfbayes upload code May 29, 2019
video upload code May 29, 2019
.gitignore upload code May 29, 2019
LICENSE Initial commit May 9, 2019 Update Jun 22, 2019
pylintrc upload code May 29, 2019 upload code May 29, 2019

Particle Flow Bayes' Rule

Implementation of Particle Flow Bayes’ Rule

Stepwise posterior estimation for 'two-gaussian'.

From left to right:

  1. smc (Sequential Monte Carlo),
  2. pfbayes (our method),
  3. True posterior



Install the package

This package requires the dependency of torch==1.0.0 and torchdiffeq[3]. Our implementation is based on ffjord [2].

pip install torch==1.0.0
git clone
cd torchdiffeq
pip install -e .

After that, clone and install the current package.

pip install -e .

data and results

The data and pretrained model dumps can be obtained via the shared dropbox folder

After downloading the shared folder, put it under the root of the project (or create a symbolic link) and rename it as 'dropbox', so that the default bash script can automatically find them.

Finally the project has the following folder structure:

|___pfbayes  # source code
|   |___common # common implementations
|   |___experiments # code for each experiment
|___dropbox  # data, trained model dumps and result statistics
        |____hmm_lds # for hmm lds

Reproducing the experiments

In general, the scripts come with the experiment have the default configurations. You can also tune the hyperparameters like number of particles, solver types, etc.

Multivariate Gaussian Model


The data used in the paper is included, and you can find them here:

cd pfbayes/experiments/mvn_unimodal/data

You can also generate new data using the script


First navigate to the experiment folder, and you can use the pretrained model directly:

cd pfbayes/experiments/mvn_unimodal

This will generate evaluation results under current scratch/ folder. To train from scratch, simply set phase=seg_train in above script.

Gaussian Mixture Model

The data is generated on the fly. This experiment is mainly used for qualitative evaluation.


cd pfbayes/experiments/two_gaussian

You will get videos under current scratch/ folder. You can also try different seeds to see how our pfbayes can estimate the posterior for new sequences. To train from scratch, simply set phase=train in above script.



We've included the LDS model and sampled traces under pfbayes/experiments/hmm_lds/data.

You can also create new data and samples using the scripts under that folder, e.g.

cd pfbayes/experiments/hmm_lds/data
python  # this will create a new LDS model
./  # this will load the model and generate samples


First navigate to the experiment folder, and you can use the pretrained model directly:

cd pfbayes/experiments/hmm_lds

This will generate results under current scratch/ folder

To train from scratch, simply set phase=train in above script.

Bayesian Logistic Regression


The dataset is preprocessed into numpy array, you can find more details in the paper.

pfbayes as variational inference

This experiment simply performs variational inference for posterior of entire training set. We perform 10 rounds of training/test, with different random splits per each.

cd pfbayes/experiments/logistic_regression

generalize learned bayes rules

Similar to meta-learning, here each 'task' corresponds to a fixed angle of data rotation. The pretrained model can be generalized to different random angles. Try different random seeds to evaluate against different angles:


You can also train from scratch with random angles:

cd pfbayes/experiments/logistic_regression


If you found this library useful in your research, please consider citing

  title={Particle Flow Bayes’ Rule},
  author={Chen, Xinshi and Dai, Hanjun and Song, Le},
  booktitle={International Conference on Machine Learning},


[1] Xinshi Chen, Hanjun Dai, Le Song. "Particle Flow Bayes' Rule." In International Conference on Machine Learning. 2019.

[2] Grathwohl W, Chen RT, Betterncourt J, Sutskever I, Duvenaud D. "FFJORD: Free-form continuous dynamics for scalable reversible generative models." arXiv preprint arXiv:1810.01367. 2018.

[3] Ricky T. Q. Chen, Yulia Rubanova, Jesse Bettencourt, David Duvenaud. "Neural Ordinary Differential Equations." Advances in Neural Processing Information Systems. 2018.

You can’t perform that action at this time.