A library that allows for inference on probabilistic models

Overview

Bean Machine

Lint Tests PyPI

Overview

Bean Machine is a probabilistic programming language for inference over statistical models written in the Python language using a declarative syntax. Bean Machine is built on top of PyTorch and Bean Machine Graph, a custom C++ backend. Check out our tutorials and Quick Start to get started!

Installation

Bean Machine supports Python 3.7, 3.8 and PyTorch 1.10.

Install the Latest Release with Pip

pip install beanmachine

Install from Source

To download the latest Bean Machine source code from GitHub:

git clone https://github.com/facebookresearch/beanmachine.git
cd beanmachine

Then, you can choose from any of the following installation options.

Anaconda

We recommend using conda to manage the virtual environment and install the necessary build dependencies.

conda create -n {env name} python=3.7; conda activate {env name}
conda install boost eigen
pip install .

Docker

docker build -t beanmachine .
docker run -it beanmachine:latest bash

Validate Installation

If you would like to run the builtin unit tests:

# install pytest 7.0 from GitHub
pip install git+https://github.com/pytest-dev/[email protected]
pytest .

License

Bean Machine is MIT licensed, as found in the LICENSE file.

Comments
  • Better arviz support in base inference

    Better arviz support in base inference

    Motivation

    When I was doing bug fixing I noticed my arviz changes were lost in the shuffle. These commits add the functionality while keeping the APIs unchanged as much as possible.

    Changes proposed

    Changes the

    Test Plan

    Please provide clear instructions on how the changes were verified. Attach screenshots if applicable.

    Types of changes

    • [ ] Docs change / refactoring / dependency upgrade
    • [ ] Bug fix (non-breaking change which fixes an issue)
    • [x] New feature (non-breaking change which adds functionality)
    • [ ] Breaking change (fix or feature that would cause existing functionality to change)

    Checklist

    • [x] My code follows the code style of this project.
    • [ ] My change requires a change to the documentation.
    • [ ] I have updated the documentation accordingly.
    • [x] I have read the CONTRIBUTING document.
    • [x] I have added tests to cover my changes.
    • [x] All new and existing tests passed.
    • [x] The title of my pull request is a short description of the requested changes.
    CLA Signed 
    opened by zaxtax 55
  • Adds Hierarchical Modeling tutorial notebook

    Adds Hierarchical Modeling tutorial notebook

    Motivation

    This PR presents the first beanmachine tutorial notebook from the OpenTeams/Quansight team.

    Changes proposed

    This embeds a new notebook within the tutorials directory under the subdirectory openteams (can be moved/renamed if necessary).

    CLA Signed Merged 
    opened by dhavide 28
  • Multiple random seed runs introduced to single_site_random_walk_conjugate_test_nightly.py

    Multiple random seed runs introduced to single_site_random_walk_conjugate_test_nightly.py

    Summary: To help defend against potential flakiness and differences in the behavior of the random number generators across platform, this diff is adding multiple random seed runs to the test file mentioned above.

    Differential Revision: D28516365

    CLA Signed fb-exported 
    opened by wtaha 27
  • Having error messages report random_seed

    Having error messages report random_seed

    Summary: We have been having some trouble with deterministic tests producing different results on phabricator than on our machines. This diff extends the messages of the relevant assert statements so that we also have information about the random_seed at the time of the test failure.

    Differential Revision: D28517313

    CLA Signed fb-exported 
    opened by wtaha 26
  • handling plot category

    handling plot category

    Summary: Add support for trace plot and autocorrelation plots for sampled variables . User can override these functions or add new plot functionalities by registering these new methods via plot_fn(...)

    Differential Revision: D17911632

    CLA Signed Merged 
    opened by torabin 26
  • Extending tests to be better localize problem in single_site_ancestral_mh_conjugate_test_nightly.py

    Extending tests to be better localize problem in single_site_ancestral_mh_conjugate_test_nightly.py

    Summary: This diff introduces a set of ten seeds to run the various tests on. The distant_normal case fails on all ten values. This further supports the idea that the issue is with distant_normal_normal case and not necessarily the algorithm itself. In all cases it fails with the error indicated in the comment on the test (low ESS, and exactly the same value on both seeds). This suggests that the algorithm is consistently getting stuck on this case.

    Differential Revision: D28519753

    CLA Signed fb-exported 
    opened by wtaha 25
  • Factoring out Normal log density and Poisson log probability

    Factoring out Normal log density and Poisson log probability

    Summary: In preparation for reuse of Normal log density and Poisson log probability, they are factored out to util.h.

    Differential Revision: D39178764

    CLA Signed fb-exported 
    opened by rodrigodesalvobraz 24
  • GP tutorial NumPy error

    GP tutorial NumPy error

    The Gaussian_Process_Gpytorch tutorial has been updated for conversion to MDX. See #1392 for more info about the updates. Only minor edits were made including:

    • link updates
    • markdown display of dataframes
    • using ArviZ for summary statistics
    • spelling and grammar checks

    In cells 12 and 13, we attempt to show the summary statistics from ArviZ for the model. The following error occurs when converting the Bean Machine MonteCarloSamples object to either an xarray or ArviZ InferenceData object.

    RuntimeError: Can't call numpy() on Tensor that requires grad. Use
    tensor.detach().numpy() instead.
    

    This error is coming from the to_inference_data method, and can be seen in the stack trace in the notebook.

    Types of changes

    • [ ] Docs change / refactoring / dependency upgrade
    • [ ] Bug fix (non-breaking change which fixes an issue)
    • [ ] New feature (non-breaking change which adds functionality)
    • [ ] Breaking change (fix or feature that would cause existing functionality to change)

    Checklist

    • [x] My code follows the code style of this project.
    • [ ] My change requires a change to the documentation.
    • [ ] I have updated the documentation accordingly.
    • [x] I have read the CONTRIBUTING document.
    • [ ] I have added tests to cover my changes.
    • [ ] All new and existing tests passed.
    • [x] The title of my pull request is a short description of the requested changes.
    bug CLA Signed 
    opened by ndmlny-qs 24
  • Marginal diagnostic tool

    Marginal diagnostic tool

    This commit includes the marginal 1D diagnostic tool with JavaScript callbacks.

    Motivation

    This PR completes one tool that uses Bokeh and JavaScript callbacks in order to create an interactive tool that can be viewed in Jupyter. This refactors the code in PR #1631 heavily, since pure Python callbacks were found to not function properly with internal tools.

    Changes proposed

    A new tool folder in the diagnostics folder contains the proposed changes. In this folder there is a js folder that contains all the JavaScript callbacks needed for the Bokeh tool. The tool creates plots of marginal distributions for each random variable of the model. The output is a self-contained HTML object that can be rendered in Jupyter without any external CDN calls for JS resources.

    Test Plan

    Unit tests for the Python and JavaScript will be done at a later commit. Right now the testing was to run the tool in the Coin Flipping tutorial, and to inspect the output and ensure only static resources were used.

    Types of changes

    • [ ] Docs change / refactoring / dependency upgrade
    • [ ] Bug fix (non-breaking change which fixes an issue)
    • [x] New feature (non-breaking change which adds functionality)
    • [ ] Breaking change (fix or feature that would cause existing functionality to change)

    Checklist

    • [x] My code follows the code style of this project.
    • [ ] My change requires a change to the documentation.
    • [ ] I have updated the documentation accordingly.
    • [x] I have read the CONTRIBUTING document.
    • [ ] I have added tests to cover my changes.
    • [ ] All new and existing tests passed.
    • [x] The title of my pull request is a short description of the requested changes.

    TODO

    • [ ] Python unit tests
    • [ ] JavaScript unit tests
    • [ ] Figure out if the build should run npm run build for the tools, or if we should just have the minified code for the JS callbacks in the code base.
    enhancement CLA Signed 
    opened by ndmlny-qs 23
  • ipynb to mdx

    ipynb to mdx

    This commit contains the following changes.

    • Updates to the tutorials plotting module. Changes here were propagated to the tutorials using them. They include baseball.py and nba.py.
    • Tutorials were modified so they can accommodate conversion to mdx.
    • The following tutorials have been updated to include interactive figures:
      • Bayesian_Logistic_Regression
      • Robust_Linear_Regression
      • Sparse_Logistic_Regression
    • The website/tutorials.json file was updated to reflect the tutorials that can be successfully transformed into mdx files.

    Resolves #1346

    Types of changes

    • [x] Docs change / refactoring / dependency upgrade
    • [ ] Bug fix (non-breaking change which fixes an issue)
    • [x] New feature (non-breaking change which adds functionality)
    • [ ] Breaking change (fix or feature that would cause existing functionality to change)

    Checklist

    • [x] My code follows the code style of this project.
    • [x] My change requires a change to the documentation.
    • [x] I have updated the documentation accordingly.
    • [x] I have read the CONTRIBUTING document.
    • [ ] I have added tests to cover my changes.
    • [ ] All new and existing tests passed.
    • [x] The title of my pull request is a short description of the requested changes.

    Bugs

    • General
      • Remove tqdm progress bars in the mdx output
    • Tutorials
      • Coin flipping
        • :heavy_check_mark: runs in Colab
        • plots visible before execution in Colab
          • :heavy_check_mark: matplotlib
          • :x: plotly
        • Create a ticket to update with interactive figures.
      • Linear regression
        • Contains errors, create a ticket.
      • Robust linear regression tutorial
        • :x: runs in Colab (needs updated plots.py module)
        • plots visible before execution in Colab
          • :heavy_check_mark: Bokeh
      • Logistic regression tutorial
        • :x: runs in Colab (needs updated plots.py module)
        • plots visible before execution in Colab
          • :heavy_check_mark: Bokeh
      • Sparse logistic regression tutorial
        • :x: runs in Colab (needs updated plots.py module)
        • plots visible before execution in Colab
          • :heavy_check_mark: Bokeh
      • Hierarchical regression
        • :heavy_check_mark: runs in Colab
        • plots visible before execution in Colab
          • :heavy_check_mark: Bokeh
        • Create a ticket to ensure all figures are interactive.
      • Hierarchical modeling
        • :heavy_check_mark: runs in Colab
        • plots visible before execution in Colab
          • :heavy_check_mark: Bokeh
        • Create a ticket to ensure all figures are interactive.
      • IRT tutorial
        • :heavy_check_mark: runs in Colab
        • plots visible before execution in Colab
          • :heavy_check_mark: Bokeh
        • Create ticket to update displays of Markdown dataframes.
      • Zero inflated count data
        • :heavy_check_mark: runs in Colab
        • plots visible before execution in Colab
          • :heavy_check_mark: Bokeh
        • Create a ticket to ensure all figures are interactive.
      • Hidden Markov model
        • :heavy_check_mark: runs in Colab
        • plots visible before execution in Colab
          • :heavy_check_mark: matplotlib
        • Create a ticket to update with interactive figures.
      • Gaussian mixture model
        • :heavy_check_mark: runs in Colab
        • plots visible before execution in Colab
          • :x: Plotly
        • Create a ticket to update with interactive figures.
      • Neal's funnel
        • :heavy_check_mark: runs in Colab
        • plots visible before execution in Colab
          • :heavy_check_mark: matplotlib
          • :x: plotly
        • Create a ticket to update with interactive figures.
      • Gaussian process using gpytorch
        • Contains errors, create a ticket.
    documentation CLA Signed 
    opened by ndmlny-qs 23
  • Adding Item Response Theory tutorial

    Adding Item Response Theory tutorial

    Motivation

    Please describe your motivation for the changes. Provide link to any related issues.

    Changes proposed

    Outline the proposed changes and alternatives considered.

    Test Plan

    Please provide clear instructions on how the changes were verified. Attach screenshots if applicable.

    Types of changes

    • [ ] Docs change / refactoring / dependency upgrade
    • [ ] Bug fix (non-breaking change which fixes an issue)
    • [x] New feature (non-breaking change which adds functionality)
    • [ ] Breaking change (fix or feature that would cause existing functionality to change)

    Checklist

    • [x] My code follows the code style of this project.
    • [ ] My change requires a change to the documentation.
    • [ ] I have updated the documentation accordingly.
    • [x] I have read the CONTRIBUTING document.
    • [ ] I have added tests to cover my changes.
    • [ ] All new and existing tests passed.
    • [x] The title of my pull request is a short description of the requested changes.
    CLA Signed Merged 
    opened by zaxtax 23
  • Fix GP unit test

    Fix GP unit test

    Summary: Turning off fast computations in BoTorch broke this test. The MVN covar had 1 more batch dimension than loc, which the approximate log_prob was happy with but the exact log_prob did not like.

    Reviewed By: Balandat

    Differential Revision: D42194245

    CLA Signed fb-exported 
    opened by saitcakmak 1
  • Remove arviz as a dependency

    Remove arviz as a dependency

    Motivation

    This removes arviz as an explicit dependency of Bean Machine. This will also prevent a circular dependency with arviz.

    Changes proposed

    Updates setup.py and moves import into to_inference_data

    Types of changes

    • [ ] Docs change / refactoring / dependency upgrade
    • [x] Bug fix (non-breaking change which fixes an issue)
    • [ ] New feature (non-breaking change which adds functionality)
    • [ ] Breaking change (fix or feature that would cause existing functionality to change)

    Checklist

    • [x] My code follows the code style of this project.
    • [ ] My change requires a change to the documentation.
    • [ ] I have updated the documentation accordingly.
    • [x] I have read the CONTRIBUTING document.
    • [ ] I have added tests to cover my changes.
    • [x] All new and existing tests passed.
    • [x] The title of my pull request is a short description of the requested changes.
    CLA Signed 
    opened by zaxtax 1
  • Connect marginalization to Graph API

    Connect marginalization to Graph API

    Summary: We introduce two new values to InferenceType enum for automatic discrete marginalization (AMD) so AMD can be ran from the normal Graph inference API.

    Differential Revision: D41060415

    CLA Signed fb-exported 
    opened by rodrigodesalvobraz 1
  • Point stat choice

    Point stat choice

    Resolves #1817

    Motivation

    Allow a user to select which point statistic they want displayed in the Marginal 1D tool: mean or median.

    Changes proposed

    • Added method to calculate the median of an array in JavaScript.
    • Updated the Marginal 1D tool to use the new method.
    • Updated the Marginal 1D interfaces to include a new widget component.
    • Updated the Python side of the tool to render the new widget.
    • Updated Python TypedDict objects to include docstrings for inclusion in the documentation in the future.
    • Updated the coin flipping tutorial to use the new point statistic button.

    Test Plan

    • Updated the coin flipping tutorial, and visually inspected the tool worked.
    • Built the documentation locally for testing the new docstrings in Sphinx.
    • Built the Docusaurus documentation locally to ensure the new widgets worked.

    new-widget-check.webm

    Types of changes

    • [ ] Docs change / refactoring / dependency upgrade
    • [ ] Bug fix (non-breaking change which fixes an issue)
    • [x] New feature (non-breaking change which adds functionality)
    • [ ] Breaking change (fix or feature that would cause existing functionality to change)

    Checklist

    • [x] My code follows the code style of this project.
    • [ ] My change requires a change to the documentation.
    • [ ] I have updated the documentation accordingly.
    • [x] I have read the CONTRIBUTING document.
    • [ ] I have added tests to cover my changes.
    • [ ] All new and existing tests passed.
    • [x] The title of my pull request is a short description of the requested changes.
    enhancement CLA Signed 
    opened by ndmlny-qs 2
Releases(v0.2.0)
  • v0.2.0(Sep 6, 2022)

    Full Changelog: https://github.com/facebookresearch/beanmachine/compare/v0.1.2...v0.2.0

    New Features

    • Graduated VI from experimental (#1609)
      • Added ADVI and MAP inference as support for variational inference methods
    • Graduated NNC from experimental (#1618)
      • Allows the use of Functorch’s AOT compiler by default for HMC and NUTS
      • If working with a non-static model or unexpected errors are encountered, you may need to manually disable the nnc_compile flag.

    Changes

    • VerboseLevel in infer is deprecated. Users should use the new boolean argument show_progress_bar to control whether the tqdm progress bar is displayed or not ( #1603).

    Fixes

    • HMC/ NUTS throws an exception when the step size becomes zero (#1606)
    • Random variables warn users against using torch tensors as arguments (#1639)

    Documentations

    • Added VI static documentation (#1613)
    • Added NNC static documentation (#1619)
    • Added VI PPCA tutorial (#1617)
    • Added VI tutorial demonstrating ADVI against Gaussian (perfect) and Gamma (approximation gap) targets (#1621)
    • Added VI tutorial replicating the Tensorflow probability GLMM tutorial (#1622)
    • Addded VI tutorial demonstrating MAP on Bayesian linear regression and how it coincides with Tikhonov regularization (with Gaussian prior) and LASSO (with Laplace prior) (#1623)
    Source code(tar.gz)
    Source code(zip)
  • v0.1.2(Jul 6, 2022)

    Full Changelog: https://github.com/facebookresearch/beanmachine/compare/v0.1.1...v0.1.2

    New Features

    • Supports accelerated inference on HMC and NUTS with functorch’s Neural Network Compiler (NNC), which can be controlled setting nnc_compile flag when initializing an inference method (#1385) (Docs)
    • Supports parallel sampling when number of chains > 1, which can be controlled by setting run_in_parallel flag when calling infer (#1369)
    • Added progress bar to BMGInference (#1321)
    • MonteCarloSamples object returned from an inference will contain log likelihood and observations now (#1269)
    • Reworked bm.simulate, which accepts a dictionary of posterior as inputs as well (#1474)
    • Binary wheels for M1 Apple Silicon and Python 3.10 are included in the release (#1419, #1507)

    Changes

    • The default number of adaptive samples will be algorithm-specific now. For most of the algorithms, the default number of adaptive samples is still 0. For HMC and NUTS, the default is changed to half of number of samples (i.e. num_samples // 2 ) (#1353)
    • In CompositionalInference, the default algorithm for continuous latent variables is changed to NUTS (GlobalNoUTurnSampler) (#1407).

    Fixes

    • Resolved deprecation warnings to support PyTorch 1.11 (#1378) (Note: PyTorch 1.12 is also supported now)

    Documentations

    • Added a Bayesian structural time series tutorial (#1376) (link to tutorial)
    • Used the experimental NNC compile feature in supported tutorials (#1408)
    • Added MiniBM, a minimal and standalone implementation of Bean Machine in around a hundred lines of code (excluding comments) (#1415) (minibm.py)
    Source code(tar.gz)
    Source code(zip)
  • v0.1.1(Jan 28, 2022)

    Full Changelog: https://github.com/facebookresearch/beanmachine/compare/v0.1.0...v0.1.1

    Highlights

    • Bean Machine now supports Python 3.9 (#1302)
    • Adds the missing cpp header files to the source distribution in PyPI (#1309)
    • In case of invalid initialization, BM will attempt to re-initialize an inference and throw a ValueError if the model is misspecified (#1313)
    Source code(tar.gz)
    Source code(zip)
  • v0.1.0.post1(Dec 13, 2021)

    Full Changelog: https://github.com/facebookresearch/beanmachine/compare/v0.1.0...v0.1.0.post1

    Highlights

    • Fixed the order of samples returning from MonteCarloSamples.get_variables (#1253)
    Source code(tar.gz)
    Source code(zip)
Minimal diffusion models - Minimal code and simple experiments to play with Denoising Diffusion Probabilistic Models (DDPMs)

Minimal code and simple experiments to play with Denoising Diffusion Probabilist

Rithesh Kumar 16 Oct 6, 2022
Torchserve server using a YoloV5 model running on docker with GPU and static batch inference to perform production ready inference.

Yolov5 running on TorchServe (GPU compatible) ! This is a dockerfile to run TorchServe for Yolo v5 object detection model. (TorchServe (PyTorch librar

null 82 Nov 29, 2022
Monocular 3D pose estimation. OpenVINO. CPU inference or iGPU (OpenCL) inference.

human-pose-estimation-3d-python-cpp RealSenseD435 (RGB) 480x640 + CPU Corei9 45 FPS (Depth is not used) 1. Run 1-1. RealSenseD435 (RGB) 480x640 + CPU

Katsuya Hyodo 8 Oct 3, 2022
Data-depth-inference - Data depth inference with python

Welcome! This readme will guide you through the use of the code in this reposito

Marco 3 Feb 8, 2022
BMW TechOffice MUNICH 148 Dec 21, 2022
NVIDIA Merlin is an open source library providing end-to-end GPU-accelerated recommender systems, from feature engineering and preprocessing to training deep learning models and running inference in production.

NVIDIA Merlin NVIDIA Merlin is an open source library designed to accelerate recommender systems on NVIDIA’s GPUs. It enables data scientists, machine

null 419 Jan 3, 2023
Adversarial Attacks on Probabilistic Autoregressive Forecasting Models.

Attack-Probabilistic-Models This is the source code for Adversarial Attacks on Probabilistic Autoregressive Forecasting Models. This repository contai

SRI Lab, ETH Zurich 25 Sep 14, 2022
Official PyTorch implementation for FastDPM, a fast sampling algorithm for diffusion probabilistic models

Official PyTorch implementation for "On Fast Sampling of Diffusion Probabilistic Models". FastDPM generation on CIFAR-10, CelebA, and LSUN datasets. S

Zhifeng Kong 68 Dec 26, 2022
Denoising Diffusion Probabilistic Models

Denoising Diffusion Probabilistic Models This repo contains code for DDPM training. Based on Denoising Diffusion Probabilistic Models, Improved Denois

Alexander Markov 7 Dec 15, 2022
ILVR: Conditioning Method for Denoising Diffusion Probabilistic Models (ICCV 2021 Oral)

ILVR + ADM This is the implementation of ILVR: Conditioning Method for Denoising Diffusion Probabilistic Models (ICCV 2021 Oral). This repository is h

Jooyoung Choi 225 Dec 28, 2022
Pytorch-diffusion - A basic PyTorch implementation of 'Denoising Diffusion Probabilistic Models'

PyTorch implementation of 'Denoising Diffusion Probabilistic Models' This reposi

Arthur Juliani 76 Jan 7, 2023
Implementation of Retrieval-Augmented Denoising Diffusion Probabilistic Models in Pytorch

Retrieval-Augmented Denoising Diffusion Probabilistic Models (wip) Implementation of Retrieval-Augmented Denoising Diffusion Probabilistic Models in P

Phil Wang 55 Jan 1, 2023
A Python library for Deep Probabilistic Modeling

Abstract DeeProb-kit is a Python library that implements deep probabilistic models such as various kinds of Sum-Product Networks, Normalizing Flows an

DeeProb-org 46 Dec 26, 2022
CPU inference engine that delivers unprecedented performance for sparse models

The DeepSparse Engine is a CPU runtime that delivers unprecedented performance by taking advantage of natural sparsity within neural networks to reduce compute required as well as accelerate memory bound workloads. It is focused on model deployment and scaling machine learning pipelines, fitting seamlessly into your existing deployments as an inference backend.

Neural Magic 1.2k Jan 9, 2023
Deep Learning Models for Causal Inference

Extensive tutorials for learning how to build deep learning models for causal inference using selection on observables in Tensorflow 2.

Bernard  J Koch 151 Dec 31, 2022
Music Source Separation; Train & Eval & Inference piplines and pretrained models we used for 2021 ISMIR MDX Challenge.

Music Source Separation with Channel-wise Subband Phase Aware ResUnet (CWS-PResUNet) Introduction This repo contains the pretrained Music Source Separ

Lau 100 Dec 25, 2022
This package proposes simplified exporting pytorch models to ONNX and TensorRT, and also gives some base interface for model inference.

PyTorch Infer Utils This package proposes simplified exporting pytorch models to ONNX and TensorRT, and also gives some base interface for model infer

Alex Gorodnitskiy 11 Mar 20, 2022