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
    • Univariate Linear Regression
    • Multivariate Linear Regression
    • Interaction Terms in Regression
    • Regression with a Categorical Independent Variable
    • Binomial Model
    • Beta-Binomial Model
    • Poisson Model
    • 🚧 Poisson Model with an Offset
    • Gamma-Poisson Model
    • Categorical Model
    • Multinomial Model
    • 🚧 Dirichlet Model
    • Zero-Inflated Models
    • Survival Analysis 🚧
    • Varying Intercepts Models
    • Varying Slopes Models
    • Gaussian Processes
    • Measurement Error Models
    • Handling Missing Data (WIP)
    • Latent Variable Models 🚧
    • Principal Component Analysis
    • Gaussian Mixture Models
    • Dirichlet Process Mixture Models
    • Network Models
    • Stochastic Block Models
    • Network Metrics
    • Network-Based Diffusion Analysis
    • Bayesian Neural Networks 🚧
Categories
All (28)
Biases (1)
Classification (4)
Clustering (2)
Community Detection (1)
Count Data (4)
Deep Learning (1)
Dimensionality Reduction (1)
Factor Analysis (1)
GLM (9)
Graph Theory (4)
Hierarchical Models (2)
Imputation (1)
Network Analysis (4)
Neural Networks (1)
Non-parametric (2)
Regression (17)
Social transmission (1)
Structural Equation Modeling (1)
Survival Analysis (1)
Time-to-Event (1)
Unsupervised Learning (3)

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 : tuple

# 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()
jax.local_device_count 16

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
4 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
4 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
2 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 🚧
5 min
Survival Analysis
Time-to-Event

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
11 min
Hierarchical Models
Regression

Extending mixed-effects models by allowing the relationship (slope) to vary across different groups.

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 (WIP)
1 min
Imputation

An overview of strategies for dealing with missing values in a dataset, such as imputation.

Latent Variable Models 🚧
4 min
Structural Equation Modeling
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
6 min
Network Analysis
Graph Theory
Community Detection

A generative model for random graphs used to find communities of nodes with similar connection patterns.

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
2 min
Network Analysis
Graph Theory
Social transmission

Modeling how information, behaviors, or diseases spread through a network over time.

Bayesian Neural Networks 🚧
7 min
Neural Networks
Deep Learning

Neural networks that incorporate Bayesian inference to quantify uncertainty in their predictions.

No matching items