Skip to content

Hands on tutorial on simulation-based inference using the Lotka-Volterra model as example.

License

Notifications You must be signed in to change notification settings

janfb/euroscipy-2025-sbi-tutorial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

34 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

EuroSciPy 2025: Simulation-Based Inference Tutorial

Open In Colab

Beyond Likelihoods: Bayesian Parameter Inference for Black-Box Simulators with sbi

πŸ“ KrakΓ³w, Poland | 90 minutes | Intermediate Track

🎯 Learning Objectives

By the end of this tutorial, you will:

  • Understand when and why to use Simulation-Based Inference (SBI)
  • Run parameter inference for any Python simulator using the sbi package
  • Diagnose whether your inference results are trustworthy
  • Apply SBI to your own scientific problems

πŸ“š Pre-Tutorial Homework (Required)

1. Environment Setup

# Install uv if you haven't already
curl -LsSf https://astral.sh/uv/install.sh | sh

# Clone this repository
git clone https://github.com/janfb/euroscipy-2025-sbi-tutorial.git
cd euroscipy-2025-sbi-tutorial

# Create environment and install dependencies
uv venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
uv sync
```text

### 2. Test Your Setup

```python
# Run this to verify installation
python -c "import sbi; import torch; print('βœ… Setup complete!')"

Running the notebooks

  • You can run the notebooks in VSCode or a similar IDE, selecting the euroscipy-2025-sbi-tutorial python kernel
  • Alternatively, you can start jupyter notebook in the terminal and work on the notebooks in the browser.

Open notebooks in Colab

  • notebook 1: Open 01 in Colab
  • notebook 2: Open 02 in Colab
  • notebook 3: Open 03 in Colab

3. Optional but Recommended

  • Read a bit about SBI:

  • Bring Your Simulator: If you have a scientific simulator you'd like to apply SBI to, prepare a simplified version that:

    • Takes parameters as input (numpy array or torch tensor)
    • Returns observations as output (numpy array or torch tensor)
    • Runs in < 1 second per simulation
    • Example: def simulator(params): return observations

πŸ“‹ Tutorial Outline

Part 1: Why SBI? (15 min)

  • The Environmental Monitoring Challenge
  • Point estimates vs. uncertainty quantification
  • When traditional methods fail

Part 2: Core Intuition (10 min)

  • Rejection sampling in 5 lines of code
  • Neural Posterior Estimation concept
  • Learning parameter-data relationships

Part 3: Hands-On Exercises (55 min)

Exercise 1: Your First Inference (15 min)

  • Lotka-Volterra predator-prey model
  • Running NPE with sbi
  • Visualizing posterior distributions

Exercise 2: Trust but Verify (20 min)

  • Posterior predictive checks
  • Coverage diagnostics
  • Interpreting warning signs

Exercise 3: Your Own Problem (20 min)

  • Adapt template to your simulator
  • OR use provided examples (ball throw, SIR model)
  • Specify priors and run inference

Part 4: Next Steps (5 min)

  • Advanced SBI methods (NLE, NRE, sequential)
  • Resources and community

Q&A (5 min)

πŸ—‚οΈ Repository Structure

euroscipy-2025-sbi-tutorial/
β”œβ”€β”€ README.md                     # This file
β”œβ”€β”€ pyproject.toml                # Project dependencies
└── materials/
    β”œβ”€β”€ 2024-08-30-EuroSciPy2024-SBI.pdf  # Optional pre-reading
    └── references.md                     # Further resources
β”œβ”€β”€ slides/                       # Presentation slides
β”‚   └── sbi_tutorial.md
    β”œβ”€β”€ sbi_tutorial.pdf
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ 00_setup_test.py          # Verify installation
β”‚   β”œβ”€β”€ 01_first_inference.ipynb  # Exercise 1
β”‚   β”œβ”€β”€ 02_diagnostics.ipynb      # Exercise 2
β”‚   β”œβ”€β”€ 03_your_sbi_problem.ipynb     # Exercise 3
β”‚   └── simulators/               # Example simulators
β”‚       β”œβ”€β”€ lotka_volterra.py
β”‚       β”œβ”€β”€ ball_throw.py
β”‚       └── sir_model.py
    └── utils.py                  # Plotting utils

πŸ’» Technical Requirements

  • Python 3.10+
  • Basic familiarity with PyTorch tensors
  • Understanding of your own simulator (if bringing one)

πŸ‘₯ Instructors

  • Jan Teusen (Boelts), TransferLab, appliedAI Institute for Europe
  • Janos Gabler, TransferLab, appliedAI Institute for Europe
  • Kristof SchrΓΆder, TransferLab, appliedAI Institute for Europe

πŸ“§ Support

  • Before the tutorial: Open an issue on GitHub
  • During the tutorial: Raise your hand
  • After the tutorial: Join the sbi community on GitHub Discussions

πŸ”— Links

Acknowledgments

πŸ“ License

This tutorial is licensed under Apache 2.0.

About

Hands on tutorial on simulation-based inference using the Lotka-Volterra model as example.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •