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)
Exploring Visual Engagement Signals for Representation Learning

Exploring Visual Engagement Signals for Representation Learning Menglin Jia, Zuxuan Wu, Austin Reiter, Claire Cardie, Serge Belongie and Ser-Nam Lim C

Menglin Jia 9 Jul 23, 2022
DCA - Official Python implementation of Delaunay Component Analysis algorithm

Delaunay Component Analysis (DCA) Official Python implementation of the Delaunay

Petra Poklukar 9 Sep 06, 2022
PyTorch implementation of Advantage Actor Critic (A2C), Proximal Policy Optimization (PPO), Scalable trust-region method for deep reinforcement learning using Kronecker-factored approximation (ACKTR) and Generative Adversarial Imitation Learning (GAIL).

PyTorch implementation of Advantage Actor Critic (A2C), Proximal Policy Optimization (PPO), Scalable trust-region method for deep reinforcement learning using Kronecker-factored approximation (ACKTR)

Ilya Kostrikov 3k Dec 31, 2022
SwinIR: Image Restoration Using Swin Transformer

SwinIR: Image Restoration Using Swin Transformer This repository is the official PyTorch implementation of SwinIR: Image Restoration Using Shifted Win

Jingyun Liang 2.4k Jan 08, 2023
Code for our method RePRI for Few-Shot Segmentation. Paper at http://arxiv.org/abs/2012.06166

Region Proportion Regularized Inference (RePRI) for Few-Shot Segmentation In this repo, we provide the code for our paper : "Few-Shot Segmentation Wit

Malik Boudiaf 138 Dec 12, 2022
Sound Source Localization for AI Grand Challenge 2021

Sound-Source-Localization Sound Source Localization study for AI Grand Challenge 2021 (sponsored by NC Soft Vision Lab) Preparation 1. Place the data-

sanghoon 19 Mar 29, 2022
REGTR: End-to-end Point Cloud Correspondences with Transformers

REGTR: End-to-end Point Cloud Correspondences with Transformers This repository contains the source code for REGTR. REGTR utilizes multiple transforme

Zi Jian Yew 108 Dec 17, 2022
Nested Graph Neural Network (NGNN) is a general framework to improve a base GNN's expressive power and performance

Nested Graph Neural Networks About Nested Graph Neural Network (NGNN) is a general framework to improve a base GNN's expressive power and performance.

Muhan Zhang 38 Jan 05, 2023
ICML 21 - Voice2Series: Reprogramming Acoustic Models for Time Series Classification

Voice2Series-Reprogramming Voice2Series: Reprogramming Acoustic Models for Time Series Classification International Conference on Machine Learning (IC

49 Jan 03, 2023
A variational Bayesian method for similarity learning in non-rigid image registration (CVPR 2022)

A variational Bayesian method for similarity learning in non-rigid image registration We provide the source code and the trained models used in the re

daniel grzech 14 Nov 21, 2022
FLVIS: Feedback Loop Based Visual Initial SLAM

FLVIS Feedback Loop Based Visual Inertial SLAM 1-Video EuRoC DataSet MH_05 Handheld Test in Lab FlVIS on UAV Platform 2-Relevent Publication: Under Re

UAV Lab - HKPolyU 182 Dec 04, 2022
A (PyTorch) imbalanced dataset sampler for oversampling low frequent classes and undersampling high frequent ones.

Imbalanced Dataset Sampler Introduction In many machine learning applications, we often come across datasets where some types of data may be seen more

Ming 2k Jan 08, 2023
DEEPAGÉ: Answering Questions in Portuguese about the Brazilian Environment

DEEPAGÉ: Answering Questions in Portuguese about the Brazilian Environment This repository is related to the paper DEEPAGÉ: Answering Questions in Por

0 Dec 10, 2021
PyTorch implementation for Graph Contrastive Learning with Augmentations

Graph Contrastive Learning with Augmentations PyTorch implementation for Graph Contrastive Learning with Augmentations [poster] [appendix] Yuning You*

Shen Lab at Texas A&M University 382 Dec 15, 2022
Code for "Sparse Steerable Convolutions: An Efficient Learning of SE(3)-Equivariant Features for Estimation and Tracking of Object Poses in 3D Space"

Sparse Steerable Convolution (SS-Conv) Code for "Sparse Steerable Convolutions: An Efficient Learning of SE(3)-Equivariant Features for Estimation and

25 Dec 21, 2022
Implementation supporting the ICCV 2017 paper "GANs for Biological Image Synthesis"

GANs for Biological Image Synthesis This codes implements the ICCV-2017 paper "GANs for Biological Image Synthesis". The paper and its supplementary m

Anton Osokin 95 Nov 25, 2022
Seach Losses of our paper 'Loss Function Discovery for Object Detection via Convergence-Simulation Driven Search', accepted by ICLR 2021.

CSE-Autoloss Designing proper loss functions for vision tasks has been a long-standing research direction to advance the capability of existing models

Peidong Liu(刘沛东) 54 Dec 17, 2022
Framework for joint representation learning, evaluation through multimodal registration and comparison with image translation based approaches

CoMIR: Contrastive Multimodal Image Representation for Registration Framework 🖼 Registration of images in different modalities with Deep Learning 🤖

Methods for Image Data Analysis - MIDA 55 Dec 09, 2022
TensorFlow CNN for fast style transfer

Fast Style Transfer in TensorFlow Add styles from famous paintings to any photo in a fraction of a second! It takes 100ms on a 2015 Titan X to style t

1 Dec 14, 2021
Autolfads-tf2 - A TensorFlow 2.0 implementation of Latent Factor Analysis via Dynamical Systems (LFADS) and AutoLFADS

autolfads-tf2 A TensorFlow 2.0 implementation of LFADS and AutoLFADS. Installati

Systems Neural Engineering Lab 11 Oct 29, 2022