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)
Moer Grounded Image Captioning by Distilling Image-Text Matching Model

Moer Grounded Image Captioning by Distilling Image-Text Matching Model Requirements Python 3.7 Pytorch 1.2 Prepare data Please use git clone --recurse

YE Zhou 60 Dec 16, 2022
Code of our paper "Contrastive Object-level Pre-training with Spatial Noise Curriculum Learning"

CCOP Code of our paper Contrastive Object-level Pre-training with Spatial Noise Curriculum Learning Requirement Install OpenSelfSup Install Detectron2

Chenhongyi Yang 21 Dec 13, 2022
How to Become More Salient? Surfacing Representation Biases of the Saliency Prediction Model

How to Become More Salient? Surfacing Representation Biases of the Saliency Prediction Model

Bogdan Kulynych 49 Nov 05, 2022
ScaleNet: A Shallow Architecture for Scale Estimation

ScaleNet: A Shallow Architecture for Scale Estimation Repository for the code of ScaleNet paper: "ScaleNet: A Shallow Architecture for Scale Estimatio

Axel Barroso 34 Nov 09, 2022
NP DRAW paper released code

NP-DRAW: A Non-Parametric Structured Latent Variable Model for Image Generation This repo contains the official implementation for the NP-DRAW paper.

ZENG Xiaohui 22 Mar 13, 2022
Code for the paper Learning the Predictability of the Future

Learning the Predictability of the Future Code from the paper Learning the Predictability of the Future. Website of the project in hyperfuture.cs.colu

Computer Vision Lab at Columbia University 139 Nov 18, 2022
[BMVC'21] Official PyTorch Implementation of Grounded Situation Recognition with Transformers

Grounded Situation Recognition with Transformers Paper | Model Checkpoint This is the official PyTorch implementation of Grounded Situation Recognitio

Junhyeong Cho 18 Jul 19, 2022
A computational block to solve entity alignment over textual attributes in a knowledge graph creation pipeline.

How to apply? Create your config.ini file following the example provided in config.ini Choose one of the options below to run: Run with Python3 pip in

Scientific Data Management Group 3 Jun 23, 2022
Spectral Temporal Graph Neural Network (StemGNN in short) for Multivariate Time-series Forecasting

Spectral Temporal Graph Neural Network for Multivariate Time-series Forecasting This repository is the official implementation of Spectral Temporal Gr

Microsoft 306 Dec 29, 2022
Code for the paper "Graph Attention Tracking". (CVPR2021)

SiamGAT 1. Environment setup This code has been tested on Ubuntu 16.04, Python 3.5, Pytorch 1.2.0, CUDA 9.0. Please install related libraries before r

122 Dec 24, 2022
This repo contains the official code and pre-trained models for the Dynamic Vision Transformer (DVT).

Dynamic-Vision-Transformer (Pytorch) This repo contains the official code and pre-trained models for the Dynamic Vision Transformer (DVT). Not All Ima

210 Dec 18, 2022
PyTorch implementation of DreamerV2 model-based RL algorithm

PyDreamer Reimplementation of DreamerV2 model-based RL algorithm in PyTorch. The official DreamerV2 implementation can be found here. Features ... Run

118 Dec 15, 2022
Airbus Ship Detection Challenge

Airbus Ship Detection Challenge This is an open solution to the Airbus Ship Detection Challenge. Our goals We are building entirely open solution to t

minerva.ml 55 Nov 29, 2022
Source code for the Paper: CombOptNet: Fit the Right NP-Hard Problem by Learning Integer Programming Constraints}

CombOptNet: Fit the Right NP-Hard Problem by Learning Integer Programming Constraints Installation Run pipenv install (at your own risk with --skip-lo

Autonomous Learning Group 65 Dec 27, 2022
This repository contains the scripts for downloading and validating scripts for the documents

HC4: HLTCOE CLIR Common-Crawl Collection This repository contains the scripts for downloading and validating scripts for the documents. Document ids,

JHU Human Language Technology Center of Excellence 6 Jun 07, 2022
On the Adversarial Robustness of Visual Transformer

On the Adversarial Robustness of Visual Transformer Code for our paper "On the Adversarial Robustness of Visual Transformers"

Rulin Shao 35 Dec 14, 2022
Jittor Medical Segmentation Lib -- The assignment of Pattern Recognition course (2021 Spring) in Tsinghua University

THU模式识别2021春 -- Jittor 医学图像分割 模型列表 本仓库收录了课程作业中同学们采用jittor框架实现的如下模型: UNet SegNet DeepLab V2 DANet EANet HarDNet及其改动HarDNet_alter PSPNet OCNet OCRNet DL

48 Dec 26, 2022
Mscp jamf - Build compliance in jamf

mscp_jamf Build compliance in Jamf. This will build the following xml pieces to

Bob Gendler 3 Jul 25, 2022
Open-Domain Question-Answering for COVID-19 and Other Emergent Domains

Open-Domain Question-Answering for COVID-19 and Other Emergent Domains This repository contains the source code for an end-to-end open-domain question

7 Sep 27, 2022
Paddle implementation for "Highly Efficient Knowledge Graph Embedding Learning with Closed-Form Orthogonal Procrustes Analysis" (NAACL 2021)

ProcrustEs-KGE Paddle implementation for Highly Efficient Knowledge Graph Embedding Learning with Orthogonal Procrustes Analysis 🙈 A more detailed re

Lincedo Lab 4 Jun 09, 2021