Skip to content

Louis-Jarvis/mcmc_simulator_app

Repository files navigation

Markov Chain Monte Carlo Simulator App

python Streamlit version pre-commit CI-CD Ruff

Background:

I was inspired by this excellent Medium article by Fortunato Nucera on the subject of using Metropolis Hastings for Bayesian Regression and set about trying to implement a variation of this myself. Additionally, I thought it would make for an interesting challenge to animate the results in streamlit!

In this project I wanted to:

  • implement the Metropolis Hastings algorithm for a Simple Linear Regression model.
  • create a streamlit app.
  • test and deploy this application.

TODOS:

  • ✨Style✨ the main page.
  • Make parameters such as the number of burn in samples configurable in the side bar.
  • Extend this to Bayesian Multiple Linear Regression.
  • Deploy this on a Kubernetes instance (e.g. Minikube).

Installation:

# Setup for development
pip install pipenv
pipenv shell 
pipenv install --dev

Usage:

pipenv shell 
streamlit run main.py

If you want to generate new data, run the following command:

python scripts/generate_data.py

Testing:

This package uses Tox to manage testing across multiple environments - see the tox.ini file. Testing of the MCMC logic uses pytest and hypothesis.

# Example tox commands
tox # run all
tox -e py310 # test in python 3.10
tox -e lint

# Run tests alone
pytest

About

Markov Chain Monte Carlo Simulator App inspired by the medium article: "Mastering Bayesian Linear Regression from Scratch: A Metropolis-Hastings Implementation in Python"

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages