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 app that enables staff to log in as other users using their own credentials.

Impostor Impostor is a Django application which allows staff members to login as a different user by using their own username and password. Login Logg

Andreu Vallbona Plazas 144 Dec 13, 2022
With Django Hijack, admins can log in and work on behalf of other users without having to know their credentials.

Django Hijack With Django Hijack, admins can log in and work on behalf of other users without having to know their credentials. Docs See http://django

1.2k Jan 05, 2023
With Django Hijack, admins can log in and work on behalf of other users without having to know their credentials.

Django Hijack With Django Hijack, admins can log in and work on behalf of other users without having to know their credentials. Docs 3.x docs are avai

1.2k Jan 02, 2023
A high-level app and dashboarding solution for Python

Panel provides tools for easily composing widgets, plots, tables, and other viewable objects and controls into custom analysis tools, apps, and dashboards.

HoloViz 2.5k Jan 03, 2023
📱 An extension for Django admin that makes interface mobile-friendly. Merged into Django 2.0

Django Flat Responsive django-flat-responsive is included as part of Django from version 2.0! 🎉 Use this app if your project is powered by an older D

elky 248 Sep 02, 2022
django's default admin interface made customizable. popup windows replaced by modals. :mage: :zap:

django-admin-interface django-admin-interface is a modern responsive flat admin interface customizable by the admin itself. Features Beautiful default

Fabio Caccamo 1.3k Dec 31, 2022
Drop-in replacement of Django admin comes with lots of goodies, fully extensible with plugin support, pretty UI based on Twitter Bootstrap.

Xadmin Drop-in replacement of Django admin comes with lots of goodies, fully extensible with plugin support, pretty UI based on Twitter Bootstrap. Liv

差沙 4.7k Dec 31, 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
django-admin fixture generator command

Mockango for short mockango is django fixture generator command which help you have data without pain for test development requirements pip install dj

Ilia Rastkhadiv 14 Oct 29, 2022
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
Visually distinguish environments in Django Admin

django-admin-env-notice Visually distinguish environments in Django Admin. Based on great advice from post: 5 ways to make Django Admin safer by hakib

Yuri Shikanov 258 Nov 30, 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
BitcartCC is a platform for merchants, users and developers which offers easy setup and use.

BitcartCC is a platform for merchants, users and developers which offers easy setup and use.

BitcartCC 270 Jan 07, 2023
Extends the Django Admin to include a extensible dashboard and navigation menu

django-admin-tools django-admin-tools is a collection of extensions/tools for the default django administration interface, it includes: a full feature

Django Admin Tools 731 Dec 28, 2022
WebVirtCloud is virtualization web interface for admins and users

WebVirtCloud is a virtualization web interface for admins and users. It can delegate Virtual Machine's to users. A noVNC viewer presents a full graphical console to the guest domain. KVM is currently

Anatoliy Guskov 1.3k Dec 29, 2022
Jet Bridge (Universal) for Jet Admin – API-based Admin Panel Framework for your application

Jet Bridge for Jet Admin – Admin panel framework for your application Description About Jet Admin: https://about.jetadmin.io Live Demo: https://app.je

Jet Admin 1.3k Dec 27, 2022
A jazzy skin for the Django Admin-Interface (official repository).

Django Grappelli A jazzy skin for the Django admin interface. Grappelli is a grid-based alternative/extension to the Django administration interface.

Patrick Kranzlmueller 3.4k Dec 31, 2022
FLEX (Federated Learning EXchange,FLEX) protocol is a set of standardized federal learning agreements designed by Tongdun AI Research Group。

Click to view Chinese version FLEX (Federated Learning Exchange) protocol is a set of standardized federal learning agreements designed by Tongdun AI

同盾科技 50 Nov 29, 2022
A curated list of the latest breakthroughs in AI by release date with a clear video explanation, link to a more in-depth article, and code.

A curated list of the latest breakthroughs in AI by release date with a clear video explanation, link to a more in-depth article, and code

Louis-François Bouchard 2.9k Jan 08, 2023
A minimalist GUI frontend for the youtube-dl. Takes up less than 4 KB.

📥 libre-DL A minimalist GUI wrapper for youtube-dl. Written in python. Total size less than 4 KB. Contributions welcome. You don't need youtube-dl pr

40 Sep 23, 2022