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
An improved django-admin-tools dashboard for Django projects

django-fluent-dashboard The fluent_dashboard module offers a custom admin dashboard, built on top of django-admin-tools (docs). The django-admin-tools

django-fluent 326 Nov 09, 2022
Awesome Video Datasets

Awesome Video Datasets

Yunhua Zhang 462 Jan 02, 2023
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
A modern Python package manager with PEP 582 support.

A modern Python package manager with PEP 582 support.

Python Development Master(PDM) 3.6k Jan 05, 2023
Disable dark mode in Django admin user interface in Django 3.2.x.

Django Non Dark Admin Disable or enable dark mode user interface in Django admin panel (Django==3.2). Installation For install this app run in termina

Artem Galichkin 6 Nov 23, 2022
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
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
spider-admin-pro

Spider Admin Pro Github: https://github.com/mouday/spider-admin-pro Gitee: https://gitee.com/mouday/spider-admin-pro Pypi: https://pypi.org/

mouday 289 Jan 06, 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
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
Tactical RMM is a remote monitoring & management tool for Windows computers, built with Django and Vue.

Tactical RMM is a remote monitoring & management tool for Windows computers, built with Django and Vue. It uses an agent written in golan

Dan 1.4k Dec 30, 2022
Python Crypto Bot

Python Crypto Bot

Michael Whittle 1.6k Jan 06, 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
Collection of admin fields and decorators to help to create computed or custom fields more friendly and easy way

django-admin-easy Collection of admin fields, decorators and mixin to help to create computed or custom fields more friendly and easy way Installation

Ezequiel Bertti 364 Jan 08, 2023
Passhunt is a simple tool for searching of default credentials for network devices, web applications and more. Search through 523 vendors and their 2084 default passwords.

Passhunt is a simple tool for searching of default credentials for network devices, web applications and more. Search through 523 vendors and their 2084 default passwords.

Viral Maniar 1.1k Dec 31, 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
PyMMO is a Python-based MMO game framework using sockets and PyGame.

PyMMO is a Python framework/template of a MMO game built using PyGame on top of Python's built-in socket module.

Luis Souto Maior 61 Dec 18, 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
Code to reproduce experiments in the paper "Task-Oriented Dialogue as Dataflow Synthesis" (TACL 2020).

Code to reproduce experiments in the paper "Task-Oriented Dialogue as Dataflow Synthesis" (TACL 2020).

Microsoft 274 Dec 28, 2022
A Django admin theme using Twitter Bootstrap. It doesn't need any kind of modification on your side, just add it to the installed apps.

django-admin-bootstrapped A Django admin theme using Bootstrap. It doesn't need any kind of modification on your side, just add it to the installed ap

1.6k Dec 28, 2022