Bayesian Inference (BI)
  • Get started
  • Models
  • API Reference
  • Help
    • Report a Bug
    • Ask a Question

On this page

  • Welcome to Bayesian Inference (BI)
    • An open-source library for Python, R and Julia
  • One Mental Model. Three Languages.
    • Compare the Syntax
  • A Unified, Scalable, and Accessible Framework
  • Gallery
Categories
All (36)
Biases (2)
Classification (7)
Clustering (2)
Community Detection (1)
Count Data (4)
Deep Learning (3)
Dimensionality Reduction (1)
Factor Analysis (1)
GLM (9)
Graph Theory (5)
Hierarchical Models (5)
Imputation (1)
Network Analysis (6)
Neural Networks (4)
Non-parametric (2)
Regression (19)
Social Learning (2)
Survival Analysis (1)
Unsupervised Learning (4)

Welcome to Bayesian Inference (BI)

An open-source library for Python, R and Julia

    Scalable - Built on top of Numpyro, TensorFlow Probability and Jax, for cpu, gpu and tpu vectorization and parallelization.

    Flexibility trade-offs - low-level abstraction coding available but also pre-build function for high-level of abstraction.

    Unified - One framework for both Python and R.

    Accessibility - 30 documented models.

    Intuitive - model-building syntax.

Get Started

One Mental Model. Three Languages.

BI provides a unified experience across Julia, Python, and R. Whether you work in R’s formula syntax, Python’s object-oriented approach, or Julia’s mathematical elegance, the model logic remains consistent.

Compare the Syntax

  • Python Syntax
  • R Syntax
  • Julia Syntax
def model(height, weight):
    # Priors
    sigma = bi.dist.uniform(0, 50, name='sigma', shape=(1,))
    alpha = bi.dist.normal(178, 20, name='alpha', shape=(1,))
    beta  = bi.dist.normal(0, 1, name='beta', shape=(1,))

    # Likelihood
    mu = alpha + beta * weight
    bi.dist.normal(mu, sigma, obs=height)
model <- function(height, weight){
  # Priors
  sigma = bi.dist.uniform(0, 50, name='sigma', shape=c(1))
  alpha = bi.dist.normal(178, 20, name='alpha', shape=c(1))
  beta  = bi.dist.normal(0, 1, name='beta', shape=c(1))

  # Likelihood
  mu = alpha + beta * weight
  bi.dist.normal(mu, sigma, obs=height)
}
@BI function model(weight, height)
    # Priors
    sigma = bi.dist.uniform(0, 50, name='sigma', shape=(1,))
    alpha = bi.dist.normal(178, 20, name='alpha', shape=(1,))
    beta  = bi.dist.normal(0, 1, name='beta', shape=(1,))

    # Likelihood
    mu = alpha + beta * weight
    bi.dist.normal(mu, sigma, obs=height)
end

A Unified, Scalable, and Accessible Framework

  • Pipeline
  • Full Model definition
  • Prebuilt function
  • Model to Latex
  • Distributions visualization
from BI import bi

# Setup device------------------------------------------------
m = bi(platform='cpu') # cpu, gpu or tpu

# Import Data ------------------------------------------------
m.data(data_path) 

# Define model ------------------------------------------------
def model(arg1,argb2):
   pass

# Run mcmc ------------------------------------------------
m.fit(model) 

# Summary ------------------------------------------------
m.summary()

# Diagnostics ------------------------------------------------
m.diag()

def model(kcal_per_g, index_clade):
    alpha = m.bi.dist.normal(0, 0.5, shape=(4,), name = 'a') # shape based on the number of clades
    beta = m.bi.dist.normal(0, 0.5, shape=(4,), name = 'b')
    sigma = m.bi.dist.exponential( 1, name = 's')    
    mu = a[index_clade]+b[index_clade]*mass
    m.normal(mu, s, obs=kcal_per_g)
def model(kcal_per_g, index_clade):
    a = m.dist.normal(5, 2,  name = 'a')
    b = m.dist.normal(-1, 0.5, name = 'b')
    sigma = m.dist.exponential( 1,  name = 'sigma')

    varying_intercept, varying_slope = m.effects.varying_effects(
      N_group = N_cafes,
      group = cafe,
      global_intercept= a,
      global_slope= b,
      group_name = 'cafe'
    )
#| label: model-to-latex
#| results: hold
#| echo: true
from BI import bi
m = bi(platform='cpu')

# define model ------------------------------------------------
def model(weight, height):    
    alpha = m.dist.normal( 178, 20, name = 'a')
    beta = m.dist.log_normal( 0, 1, name = 'b')   
    sigma = m.dist.uniform( 0, 50, name = 's')
    m.dist.normal(alpha + beta * weight , sigma, obs=height)

# Run sampler ------------------------------------------------
m.model = model
m.latex()

\begin{aligned} height &\sim \text{Normal}(\alpha + \beta * weight, \sigma) \\ \sigma &\sim \text{Uniform}(0, 50) \\ \beta &\sim \text{LogNormal}(0, 1) \\ \alpha &\sim \text{Normal}(178, 20) \end{aligned}

Code
from BI import bi
m = bi()
m.dist.normal( 0, 1, name = 'a', shape=(100,2, 4), sample = True, to_jax = False).hist()
BI v 0.0.26 package loaded
E0525 12:21:49.545932  549871 cuda_dnn.cc:523] Loaded runtime CuDNN library: 9.1.0 but source was compiled with: 9.8.0.  CuDNN library needs to have matching major version and equal or higher minor version. If using a binary install, upgrade your CuDNN library.  If building from sources, make sure the library loaded at runtime is compatible with the version specified during compile configuration.
E0525 12:21:49.548036  549871 cuda_dnn.cc:523] Loaded runtime CuDNN library: 9.1.0 but source was compiled with: 9.8.0.  CuDNN library needs to have matching major version and equal or higher minor version. If using a binary install, upgrade your CuDNN library.  If building from sources, make sure the library loaded at runtime is compatible with the version specified during compile configuration.
jax.local_device_count 32

Gallery

Univariate Linear Regression
5 min
Regression
An introduction to linear regression models.

Multivariate Linear Regression
4 min
Regression
Extending linear regression to model a continuous outcome using multiple predictor variables.

Interaction Terms in Regression
5 min
Regression
Modeling how the effect of one independent variable on the outcome changes based on the value of another independent variable.

Regression with a Categorical Independent Variable
5 min
Regression
GLM
Incorporating categorical predictors (i.e., factor variables) into a regression model using dummy variables.

Binomial Model
4 min
Classification
Regression
GLM
Modeling binary outcomes (e.g., successes/failures) across multiple independent trials.

Beta-Binomial Model
6 min
Regression
GLM
Modeling binary outcomes (e.g., successes/failures) across multiple independent trials when the success probability itself is uncertain.

Poisson Model
4 min
Regression
Count Data
GLM
Modeling count data, such as the number of events occurring in a fixed interval of time or space.

Poisson Model with an Offset
5 min
Regression
Count Data
Modeling count data that has been collected over different levels of exposure using an offset.

Gamma-Poisson Model
3 min
Regression
Count Data
GLM
An extension of the Poisson model for count data that exhibits overdispersion.

Categorical Model
5 min
Classification
Regression
GLM
Modeling a categorical dependent variable with more than two nominal outcomes.

Multinomial Model
4 min
Regression
GLM
Classification
Modeling the counts of outcomes across multiple categorical trials.

Dirichlet Model
5 min
Regression
GLM
Classification
Modeling uncertainty about the probabilities of categories themselves.

Zero-Inflated Models
4 min
Count Data
Regression
GLM
Handling count data with an excess of zero counts by combining a count model with a logistic model.

Survival Analysis
4 min
Survival Analysis
Analyzing time-to-event data, focusing on the duration until an event of interest occurs.

Varying Intercepts Models
4 min
Hierarchical Models
Regression
Modeling grouped or hierarchical data by allowing the intercept to vary for each group.

Varying Slopes Models
10 min
Hierarchical Models
Regression
Extending mixed-effects models by allowing the relationship (slope) to vary across different groups.

🚧Nested Varying Effects
8 min
Hierarchical Models
Regression
Modeling hierarchical data with multiple levels of nesting (e.g., individuals within groups within regions).

Phylogenetic Generalized Multilevel Models (PGMMs)
24 min
Hierarchical Models
Regression
Estimating evolutionary relationships and morphological evolution using Generalized Phylogenetic Multilevel Models (GPMMs).

Gaussian Processes
7 min
Regression
Non-parametric
A Bayesian approach to regression and classification that defines a distribution over functions.

Measurement Error Models
5 min
Regression
Biases
Statistical models that explicitly account for errors in the measurement of predictor variables.

Handling Missing Data
14 min
Imputation
An overview of strategies for dealing with missing values in a dataset, such as imputation, using Bayesian Inference (BI).

🚧Latent Variable Models
4 min
Factor Analysis
Models that relate a set of observable variables to a set of unobserved (latent) variables.

Principal Component Analysis
13 min
Dimensionality Reduction
Unsupervised Learning
A dimensionality reduction technique to transform a large set of variables into a smaller one.

Gaussian Mixture Models
7 min
Clustering
Unsupervised Learning
A probabilistic model for representing normally distributed subpopulations, often used for clustering.

Dirichlet Process Mixture Models
8 min
Clustering
Unsupervised Learning
Non-parametric
A non-parametric Bayesian clustering method that automatically determines the number of clusters.

Network Models
7 min
Network Analysis
Graph Theory
Modeling relationships and interactions between entities as a graph of nodes and edges.

Stochastic Block Models
7 min
Network Analysis
Graph Theory
Community Detection
A generative model for random graphs used to find communities of nodes with similar connection patterns.

Controlling for Network Biases
4 min
Network Analysis
Graph Theory
Biases
Techniques to account for biases in data collection that can affect the structure and analysis of networks.

Network Edges Inference
23 min
Network Analysis
Graph Theory
Documentation for Bayesian frameworks inferring social networks from observational data.

Network Metrics
11 min
Network Analysis
Graph Theory
An overview of key metrics used to describe and analyze the structure and properties of networks.

🚧Network-Based Diffusion Analysis
27 min
Social Learning
Network Analysis
Documentation for Bayesian models of social transmission using the STbayes framework.

🚧Experience-Weighted Attraction
15 min
Social Learning
Hierarchical Models
Experience-Weighted Attraction (EWA) model applied to social learning in wild capuchin monkeys.

BNN for Regression
9 min
Neural Networks
Deep Learning
Neural networks that incorporate Bayesian inference to quantify uncertainty in their predictions.

BNN for Classification
7 min
Neural Networks
Classification
Deep Learning
Neural networks that incorporate Bayesian inference to predict probabilities of binary outcomes.

BNN for Multiclass Classification
6 min
Neural Networks
Classification
Deep Learning
Neural networks that incorporate Bayesian inference to predict probabilities across three or more mutually exclusive classes.

🚧Unsupervised BNNC
5 min
Neural Networks
Classification
Unsupervised Learning
Bayesian Neural Network Clustering for discovering hidden multivariate groupings.
No matching items