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)
Implemented fully documented Particle Swarm Optimization algorithm (basic model with few advanced features) using Python programming language

Implemented fully documented Particle Swarm Optimization (PSO) algorithm in Python which includes a basic model along with few advanced features such as updating inertia weight, cognitive, social lea

9 Nov 29, 2022
Model Agnostic Interpretability for Multiple Instance Learning

MIL Model Agnostic Interpretability This repo contains the code for "Model Agnostic Interpretability for Multiple Instance Learning". Overview Executa

Joe Early 10 Dec 17, 2022
A symbolic-model-guided fuzzer for TLS

tlspuffin TLS Protocol Under FuzzINg A symbolic-model-guided fuzzer for TLS Master Thesis | Thesis Presentation | Documentation Disclaimer: The term "

69 Dec 20, 2022
Manipulation OpenAI Gym environments to simulate robots at the STARS lab

Manipulator Learning This repository contains a set of manipulation environments that are compatible with OpenAI Gym and simulated in pybullet. In par

STARS Laboratory 5 Dec 08, 2022
EgGateWayGetShell py脚本

EgGateWayGetShell_py 免责声明 由于传播、利用此文所提供的信息而造成的任何直接或者间接的后果及损失,均由使用者本人负责,作者不为此承担任何责任。 使用 python3 eg.py urls.txt 目标 title:锐捷网络-EWEB网管系统 port:4430 漏洞成因 ?p

榆木 61 Nov 09, 2022
Code Repository for The Kaggle Book, Published by Packt Publishing

The Kaggle Book Data analysis and machine learning for competitive data science Code Repository for The Kaggle Book, Published by Packt Publishing "Lu

Packt 1.6k Jan 07, 2023
Measuring if attention is explanation with ROAR

NLP ROAR Interpretability Official code for: Evaluating the Faithfulness of Importance Measures in NLP by Recursively Masking Allegedly Important Toke

Andreas Madsen 19 Nov 13, 2022
Vision-Language Transformer and Query Generation for Referring Segmentation (ICCV 2021)

Vision-Language Transformer and Query Generation for Referring Segmentation Please consider citing our paper in your publications if the project helps

Henghui Ding 143 Dec 23, 2022
Pytorch implementation of ProjectedGAN

ProjectedGAN-pytorch Pytorch implementation of ProjectedGAN (https://arxiv.org/abs/2111.01007) Note: this repository is still under developement. @InP

Dominic Rampas 17 Dec 14, 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 b

Neural Magic 1.2k Jan 09, 2023
The description of FMFCC-A (audio track of FMFCC) dataset and Challenge resluts.

FMFCC-A This project is the description of FMFCC-A (audio track of FMFCC) dataset and Challenge resluts. The FMFCC-A dataset is shared through BaiduCl

18 Dec 24, 2022
A module for solving and visualizing Schrödinger equation.

qmsolve This is an attempt at making a solid, easy to use solver, capable of solving and visualize the Schrödinger equation for multiple particles, an

506 Dec 28, 2022
Generalized Decision Transformer for Offline Hindsight Information Matching

Generalized Decision Transformer for Offline Hindsight Information Matching [arxiv] If you use this codebase for your research, please cite the paper:

Hiroki Furuta 35 Dec 12, 2022
CenterPoint 3D Object Detection and Tracking using center points in the bird-eye view.

CenterPoint 3D Object Detection and Tracking using center points in the bird-eye view. Center-based 3D Object Detection and Tracking, Tianwei Yin, Xin

Tianwei Yin 134 Dec 23, 2022
Repository for the paper "Exploring the Sensory Spaces of English Perceptual Verbs in Natural Language Data"

Sensory Spaces of English Perceptual Verbs This repository contains the code and collocational data described in the paper "Exploring the Sensory Spac

David Peng 0 Sep 07, 2021
Official code of "Mitigating the Mutual Error Amplification for Semi-Supervised Object Detection"

CrossTeaching-SSOD 0. Introduction Official code of "Mitigating the Mutual Error Amplification for Semi-Supervised Object Detection" This repo include

Bruno Ma 9 Nov 29, 2022
Решения, подсказки, тесты и утилиты для тренировки по алгоритмам от Яндекса.

Решения и подсказки к тренировке по алгоритмам от Яндекса Что есть внутри Решения с подсказками и комментариями; рекомендую сначала смотреть md файл п

Yankovsky Andrey 50 Dec 26, 2022
Code for "The Intrinsic Dimension of Images and Its Impact on Learning" - ICLR 2021 Spotlight

dimensions Estimating the instrinsic dimensionality of image datasets Code for: The Intrinsic Dimensionaity of Images and Its Impact On Learning - Phi

Phil Pope 41 Dec 10, 2022
The implementation of 'Image synthesis via semantic composition'.

Image synthesis via semantic synthesis [Project Page] by Yi Wang, Lu Qi, Ying-Cong Chen, Xiangyu Zhang, Jiaya Jia. Introduction This repository gives

DV Lab 71 Jan 06, 2023
A scanpy extension to analyse single-cell TCR and BCR data.

Scirpy: A Scanpy extension for analyzing single-cell immune-cell receptor sequencing data Scirpy is a scalable python-toolkit to analyse T cell recept

ICBI 145 Jan 03, 2023