Skip to content

leicao25/Generative_Bayesian_Filtering

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Generative Bayesian Filtering

We propose Generative Bayesian Filtering (GBF), a filtering framework that utilizes pretrained conditional generative model as observations model.

The repository contains:

  • 1_gaussian_mixture/ — CVAE vs. discriminative baseline on a synthetic Gaussian-mixture case study.
  • 2_temporal_mnist/ — Temporal MNIST (4 states, pixel-flip noise);
  • 3_temporal_fashion_mnist/ — Temporal Fashion-MNIST (5 states, Gaussian noise);
  • 4_ecg/ — MIT-BIH heartbeat classification into AAMI categories from sequential ECG beats.

Each temporal experiment under 2_4_ includes method/ baselines we compare against: NN, CVAE, Kalman, HMMNN, SCALE, and DeepBayes. See each subdirectory for data preparation, training, and evaluation instructions.

Repository layout

Generative_Bayesian_Filtering/
├── README.md
├── 1_gaussian_mixture/                     # Section 3.1: 1-D Gaussian mixture toy study
│   ├── data_generation.py                  # synthetic two-Gaussian data
│   ├── cvae_train.py                       # train 1-D CVAE observation model
│   ├── cvae_classifier.py                  # generative inference (SGLD-style MAP update)
│   ├── cnn_classifier.py                   # discriminative classifier 
│   └── plot_posterior.py                   # CVAE vs. CNN vs. analytic posterior
├── 2_temporal_mnist/                       # Section 4: Temporal MNIST (4 states, pixel-flip noise)
│   ├── dataset_generation.py               # Markov sequences (length 500) from MNIST digits 
│   ├── method/
│   │   ├── gbf_classifier.py               # our method: CVAE measurement update + transition filter
│   │   ├── cvae_train.py                   # train 2-D CVAE on clean frames
│   │   ├── cvae_classifier.py              # frame-wise CVAE classifier (no temporal prior)
│   │   ├── nn_train.py / nn_classifier.py  # CNN discriminative baseline
│   │   ├── kalman.py                       # Kalman filter 
│   │   ├── hmmnn_classifier.py             # CNN + HMM
│   │   ├── scale_train.py / scale_classifier.py
│   │   ├── deepbayes_train.py / deepbayes_classifier.py
│   │   └── utils.py                        # transition-matrix estimation, noise, metrics
│   ├── benchmark_run.py                    # sweep flip ratios × all methods
│   ├── benchmark_summary.py                # aggregate mean ± std tables
│   └── plot_benchmark.py                   # accuracy / coverage curves
├── 3_temporal_fashion_mnist/               # Section 4: Temporal Fashion-MNIST (5 states, Gaussian noise)
│   ├── dataset_generation.py               # Markov sequences from Fashion-MNIST classes
│   ├── method/                             # same layout as 2_temporal_mnist/
│   ├── benchmark_run.py
│   ├── benchmark_summary.py
│   └── plot_benchmark.py
└── 4_ecg/                                  # Section 5.2: MIT-BIH heartbeat classification (AAMI, 5 classes)
    ├── data_load.py                        # download MIT-BIH via kagglehub
    ├── data_check.py                       # sanity-check raw records
    ├── dataset_generation.py               # beat segmentation → train/test .pt + transition matrix estimation
    ├── plot_beat_samples.py                # original vs. CVAE-generated beats per class
    ├── method/                             # GBF + baselines (1-D Conv backbone)
    ├── benchmark_run.py
    └── benchmark_summary.py

How to run the experiments

Requirements: Python 3.10+, PyTorch, torchvision, numpy, scipy, matplotlib. Experiment 4_ecg additionally needs kagglehub for data download.

One-click reproduction

Each experiment folder provides run_experiment_boc.py, which runs the full pipeline (data → training → benchmark → summary/plots) with a single command:

cd 2_temporal_mnist
python run_experiment_boc.py

Note: the full pipeline trains all models and runs the complete benchmark sweep. A GPU is required for the training and benchmark steps to finish in reasonable time. 4_ecg also needs a configured Kaggle account for data download.

Manual steps

All commands below are run from the corresponding experiment directory (e.g. cd 2_temporal_mnist).

Experiment 1 (1_gaussian_mixture/):

python data_generation.py
python cvae_train.py && python cnn_classifier.py   # train both models
python cvae_classifier.py && python cnn_classifier.py
python plot_posterior.py

Experiments 2–4 (temporal benchmarks; same workflow):

# 1. Prepare data
python dataset_generation.py          # 4_ecg: run data_load.py first

# 2. Train models (CVAE required for GBF)
python method/cvae_train.py
python method/nn_train.py             # optional: other baselines as needed

# 3. Evaluate a single method
python method/gbf_classifier.py

# 4. Full benchmark (train + all methods + noise sweep)
python benchmark_run.py --train
python benchmark_summary.py
python plot_benchmark.py              # 2_, 3_ only

Quick smoke test: python benchmark_run.py --methods gbf --n-runs 1 --noise 0.2

About

repository of generative bayesian filtering

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages