Python code for "Machine learning: a probabilistic perspective" (2nd edition)

Overview

pyprobml

Python 3 code for my new book series Probabilistic Machine Learning. This is work in progress, so expect rough edges. Getting less rough...

Jupyter notebooks

For each chapter there are one or more accompanying Jupyter notebooks that cover some of the material in more detail. When you open a notebook, there will be a button at the top that says 'Open in colab'. If you click on this, it will start a virtual machine (VM) instance on Google Cloud Platform (GCP), running Colab. This has most of the libraries you will need (e.g., scikit-learn, JAX) pre-installed, and gives you access to a free GPU. See this tutorial for details on how to use Colab.

Book 1 (PML: An Introduction)

See this link for a list of notebooks.

Book 2 (PML: Advanced topics)

See this link for a list of notebooks.

Running scripts to make individual figures

Many of the figures in the book are generated by various scripts. To run these, first clone this gihub repo. (For some tutorials on how to use github, see github guides.) Then, to manually execute an individual script from the command line, follow this example:

export PYPROBML=/Users/kpmurphy/github/pyprobml // set this to the directory where you downloaded this repo
cd $PYPROBML
python3 scripts/softmax_plot.py // writes to /Users/kpmurphy/github/pyprobml/figures/softmax_temp.pdf

The notebook for each chapter uses these scripts to recreate all the figures for that chapter.

Viewing the scripts

To browse the code using VScode instead of the gihub file viewer, you can just replace https://github.com/probml/pyprobml/tree/master/scripts with https://github1s.com/probml/pyprobml/tree/master/scripts (see this tweet). The output should look like this:

How to contribute

See this guide for how to contribute code.

Acknowledgements

I would like to thank the following people for contributing to the code (list autogenerated from this page):

murphyk mjsML ashishpapanai Duane321 animesh-007 Nirzu97 Drishttii always-newbie161 nappaillav jdf22 shivaditya-meduri karalleyna gerdm andrewnc Abdelrahman350 Garvit9000c kzymgch Neoanarika alen1010 adamnemecek galv krasserm nealmcb petercerno Prahitha khanshehjad hieuza jlh2018 mvervuurt TripleTop
murphyk mjsML ashishpapanai Duane321 animesh-007 Nirzu97 Drishttii always-newbie161 nappaillav jdf22 shivaditya-meduri karalleyna gerdm andrewnc Abdelrahman350 Garvit9000c kzymgch Neoanarika alen1010 adamnemecek galv krasserm nealmcb petercerno Prahitha khanshehjad hieuza jlh2018 mvervuurt TripleTop
Comments
  • convert legacy matlab code to python

    convert legacy matlab code to python

    If you want to contribute a Python version of a figure, follow these steps:

    • Check the list of open issues for ones with a name like "Convert foo to Python". Such issues have the tag 'Figures'. Each issue has a link to the Matlab file that was used to generate the figure, and a figure number. Figure numbers refer to this version of the book: https://github.com/probml/pml-book/releases/tag/2021-03-08. Consult the pdf file to see what the figure should look like.

    • Follow these guidelines for how to contribute code.

    • Test your code works in Google colab, and make a pull request. Please include the generated image(s) in your PR, and add a tag which mentions the issue you are solving.

    • Here is an example of good PR.

    • If you are a student and want to be considered for the Google Summer of Code, please apply here after March 29th. You should have at least 2 PRs succesfully added to this repo before applying. Please follow the style guidelines mentioned above.

    opened by murphyk 25
  • convert pytorch d2l.ai demos to JAX

    convert pytorch d2l.ai demos to JAX

    In vol 1 of my book, I use several notebooks taken from the book Dive Into Deep Learning. These are written in pytorch and stored at https://github.com/probml/probml-notebooks/tree/main/notebooks-d2l. The task is to convert these notebooks into JAX/FLAX code. It's okay to keep using torch dataloaders, but you should replace torch.tensor with jax.np.array, and torch.nn with flax.linen.nn, etc. Be sure to replace idioms like np.random.seed(seed=1); torch.manual_seed(1) with proper JAX PRNGs.

    You should make a JAX version of each notebook, and open a PR for each one at https://github.com/probml/probml-notebooks/tree/main/notebooks-d2l. If the original notebook is called foo_torch.ipynb, please call yours foo_jax.ipynb.

    See this example for how to format your code and PR.

    Before you start translating a notebook, please check that it has not already been done! (I only want one translation per notebook :)

    GSOC 
    opened by murphyk 17
  • Accelerate workflow by including SMOKE_RUN

    Accelerate workflow by including SMOKE_RUN

    After adding D2L notebooks, workflow execution time has increased from 1 hour to 2 hours 14 minutes. Ideally, the workflow should be as fast as possible so that we can know the failing components quickly. One of the solutions for this is to enable an environment variable called SMOKE_RUN for notebooks containing epoch-wise training with a logic that if SMOKE_RUN is in the environment we run only 1-2 epochs else we run the maximum epochs as mentioned in the notebook.

    internal 
    opened by patel-zeel 15
  • mlpPriorsDemo2

    mlpPriorsDemo2

    Hello, this is a Python implementation for mlpPriorsDemo2. The figures are slightly different from the book because NumPy generates different random vectors than Matlab.

    opened by Abdelrahman350 14
  • figure out why ELBO does not improve with pymc3 ADVI demi

    figure out why ELBO does not improve with pymc3 ADVI demi

    The advi.hist (ELBO) should increase over time, but it does not seem to, even though the posterior looks sensible. Find out why. https://github.com/probml/probml-notebooks/blob/main/notebooks/beta_binom_approx_post_pymc.ipynb

    GSOC 
    opened by murphyk 13
  • Porting the complete book code to Python?

    Porting the complete book code to Python?

    Hello Kevin,

    I was wondering if there is a plan to port all of the code examples from the ML book to Python?

    If that's the case I'd love to help out :)

    opened by thvasilo 12
  • Implemented SNGP JAX Demo

    Implemented SNGP JAX Demo

    opened by nsanghi 11
  • implement blocked gibbs sampling for Bayesian inference in linear Gaussian SSM  using JSL

    implement blocked gibbs sampling for Bayesian inference in linear Gaussian SSM using JSL

    Implement blocked gibbs sampling for Bayesian inference in linear Gaussian SSM . In the "E step", use the Jax SSM library for forwards-filtering backwards-sampling. In the "M step", sample from the parameter posteriors assuming conjugate priors.

    Some details can be found in this paper A. Wills, T. B. Schön, F. Lindsten, and B. Ninness, “Estimation of Linear Systems using a Gibbs Sampler,” IFAC proc. vol., vol. 45, no. 16, pp. 203–208, Jul. 2012, doi: 10.3182/20120711-3-be-2027.00297. [Online]. Available: https://linkinghub.elsevier.com/retrieve/pii/S1474667015379520

    JSL 
    opened by murphyk 10
  • Missing superimport module for compare_results.ipynb

    Missing superimport module for compare_results.ipynb

    I encounter the following error when running compare_results.ipynb in the vae folder.

    ---------------------------------------------------------------------------
    ModuleNotFoundError                       Traceback (most recent call last)
    <ipython-input-2-d04a2cc14755> in <module>()
          5 import matplotlib.pyplot as plt
          6 import torchvision.transforms as transforms
    ----> 7 from download_celeba import celeba_dataloader
          8 from assembler import get_config, assembler
          9 from utils.plot import plot_reconstruction, plot_samples
    
    /content/download_celeba.py in <module>()
    ----> 1 import superimport
          2 
          3 from absl import app
          4 from absl import flags
          5 import torchvision.transforms as transforms
    

    I think this can be resolved by adding one line in the notebook to download superimport into the colab.

    opened by Neoanarika 10
  • Converted mixBerMnistEM to python

    Converted mixBerMnistEM to python

    mixBernoulliMnist

    Closes #174

    The code might take some time to load and this is because it is downloading the MNIST dataset from online and the delay in execution is solely due to this and not due to the inefficiency of the code.

    The values and the images will differ because the data is randomly chosen from the total set of images.

    I initially added +1 to all images in the training set and changed the Bernoulli function to adapt to this, but did not see any change in the execution, It was more convenient for me to use the binary image as is and use the implementation of Bernoulli distribution which is used for this mixture model.

    In this implementation, I did not find the optimal k because the optimal k=20 has already been found through trial and error in the MATLAB code and no graph implementation is found in the book.

    Implemented the changes suggested:

    1. Vectorized code and replaced iterating over the data points to vectorized versions
    2. replaced Bernoulli function with https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.bernoulli.html
    3. factored out the code that does parameter initialization and image plotting into subfunctions, to simplify main()
    4. changed the data source from open_ml to tensorflow.datasets
    opened by shivaditya-meduri 10
  • estimate mutual information for all pairs of WHO variables

    estimate mutual information for all pairs of WHO variables

    opened by murphyk 10
  • Figure 6.1 missing sub-figure c) showing a sequence logo.

    Figure 6.1 missing sub-figure c) showing a sequence logo.

    Figure 6.1 b) shows a graphic depiction of a position frequency matrix, but it is not a sequence logo because all column heights are equal. My guess is the original intent was to have a sub-figure 6.1 c) showing a sequence logo and compare that to the graphic in sub-figure 6.1 b) so the reader can see how much easier it is to spot conserved positions when the column heights are scaled to equal the information content. The text corresponding to figure 6.1 does mention heights scaled to information content (although "bar" height is used instead of "column" height.

    opened by paulhorton 0
  • tweak book 1 fog 7.6  gaussEvec.ipynb

    tweak book 1 fog 7.6 gaussEvec.ipynb

    To solve https://github.com/probml/pml-book/issues/440 Tweak https://colab.research.google.com/github/probml/pyprobml/blob/master/notebooks/book1/07/gaussEvec.ipynb The exponents should be lambda^{-1/2}. I tried changing the text but the figure no longer renders properly (u_1, u_2 axis broken)

    Screen Shot 2022-07-28 at 11 55 07 PM
    opened by murphyk 0
  • Make bnn_mnist_sgld_blackjax.ipynb to be able to run in colab

    Make bnn_mnist_sgld_blackjax.ipynb to be able to run in colab

    • currently, this notebook won't run in colab, due to requirement of high memory.
    • Mostly prediction loops taking much memory, we can make it batch prediction to consume less memory at a time
    opened by karm-patel 0
Releases(v0.1.0)
  • v0.1.0(May 5, 2022)

Owner
Probabilistic machine learning
Material to accompany the book "Machine Learning: A Probabilistic Perspective" (Software, Data, Exercises, Figures, etc)
Probabilistic machine learning
Django application and library for importing and exporting data with admin integration.

django-import-export django-import-export is a Django application and library for importing and exporting data with included admin integration. Featur

2.6k Jan 07, 2023
fastapi-admin is a fast admin dashboard based on FastAPI and TortoiseORM with tabler ui, inspired by Django admin.

fastapi-admin is a fast admin dashboard based on FastAPI and TortoiseORM with tabler ui, inspired by Django admin.

fastapi-admin 1.6k Dec 30, 2022
Freqtrade is a free and open source crypto trading bot written in Python

Freqtrade is a free and open source crypto trading bot written in Python. It is designed to support all major exchanges and be controlled via Telegram. It contains backtesting, plotting and money man

20.2k Jan 02, 2023
PyTorch Implementation of Unsupervised Depth Completion with Calibrated Backprojection Layers (ORAL, ICCV 2021)

PyTorch Implementation of Unsupervised Depth Completion with Calibrated Backprojection Layers (ORAL, ICCV 2021)

80 Dec 13, 2022
Django Smuggler is a pluggable application for Django Web Framework that helps you to import/export fixtures via the automatically-generated administration interface.

Django Smuggler Django Smuggler is a pluggable application for Django Web Framework to easily dump/load fixtures via the automatically-generated admin

semente 373 Dec 26, 2022
Tornadmin is an admin site generation framework for Tornado web server.

Tornadmin is an admin site generation framework for Tornado web server.

Bharat Chauhan 0 Jan 10, 2022
Legacy django jet rebooted , supports only Django 3

Django JET Reboot Rebooting the original project : django-jet. Django Jet is modern template for Django admin interface with improved functionality. W

215 Dec 31, 2022
Ajenti Core and stock plugins

Ajenti is a Linux & BSD modular server admin panel. Ajenti 2 provides a new interface and a better architecture, developed with Python3 and AngularJS.

Ajenti Project 7k Jan 07, 2023
Extendable, adaptable rewrite of django.contrib.admin

django-admin2 One of the most useful parts of django.contrib.admin is the ability to configure various views that touch and alter data. django-admin2

Jazzband 1.2k Dec 29, 2022
Modern theme for Django admin interface

Django Suit Modern theme for Django admin interface. Django Suit is alternative theme/skin/extension for Django administration interface. Project home

Kaspars Sprogis 2.2k Dec 29, 2022
StyleCLIP: Text-Driven Manipulation of StyleGAN Imagery

StyleCLIP: Text-Driven Manipulation of StyleGAN Imagery

3.3k Jan 01, 2023
Material Design for Django

Django Material Material design for Django. Django-Material 1.7.x compatible with Django 1.11/2.0/2.1/2.2/3.0/3.1 Django-Material 1.6.x compatible wit

Viewflow 2.5k Jan 01, 2023
Sandwich Batch Normalization

Sandwich Batch Normalization Code for Sandwich Batch Normalization. Introduction We present Sandwich Batch Normalization (SaBN), an extremely easy imp

VITA 48 Dec 15, 2022
Firebase Admin Console is a centralized platform for easy viewing and maintenance of Firestore database, the back-end API is a Python Flask app.

Firebase Admin Console is a centralized platform for easy viewing and maintenance of Firestore database, the back-end API is a Python Flask app. A starting template for developers to customize, build

Daqi Chen 1 Sep 10, 2022
Python books free to read online or download

Python books free to read online or download

Paolo Amoroso 3.7k Jan 08, 2023
A configurable set of panels that display various debug information about the current request/response.

Django Debug Toolbar The Django Debug Toolbar is a configurable set of panels that display various debug information about the current request/respons

Jazzband 7.3k Dec 31, 2022
Allow foreign key attributes in list_display with '__'

django-related-admin Allow foreign key attributes in Django admin change list list_display with '__' This is based on DjangoSnippet 2996 which was mad

Petr Dlouhý 62 Nov 18, 2022
GFPGAN is a blind face restoration algorithm towards real-world face images.

GFPGAN is a blind face restoration algorithm towards real-world face images.

Applied Research Center (ARC), Tencent PCG 25.6k Jan 04, 2023
A cool, modern and responsive django admin application based on bootstrap 5

django-baton A cool, modern and responsive django admin application based on bootstrap 5 Documentation: readthedocs Live Demo Now you can try django-b

Otto srl 678 Jan 01, 2023
Awesome Video Datasets

Awesome Video Datasets

Yunhua Zhang 462 Jan 02, 2023