BayesForge for Python
A unified probabilistic programming library, bringing JAX-powered BayesForge to the Python, R and Julia ecosystem.
Run bespoke models on CPU, GPU, or TPU with Julia's native syntax.
One Mental Model. Three Languages.
BayesForge (BF) 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.
- ✅ Zero Context Switching: Variable names, distribution signatures, and model logic remain consistent across all implementations.
- ✅ NumPyro Power: All interfaces compile down to XLA via JAX for blazing fast inference.
- ✅ Rich Diagnostics: Seamless integration with ArviZ for posterior analysis.
Compare the Syntax
| Python Syntax | Julia Syntax | R Syntax |
|---|---|---|
def model(height, weight):
# Priors
sigma = bf.dist.uniform(0, 50, name='sigma', shape=(1,))
alpha = bf.dist.normal(178, 20, name='alpha', shape=(1,))
beta = bf.dist.normal(0, 1, name='beta', shape=(1,))
# Likelihood
mu = alpha + beta * weight
bf.dist.normal(mu, sigma, obs=height)
|
@BI function model(weight, height)
# Priors
sigma = bf.dist.uniform(0, 50, name='sigma', shape=(1,))
alpha = bf.dist.normal(178, 20, name='alpha', shape=(1,))
beta = bf.dist.normal(0, 1, name='beta', shape=(1,))
# Likelihood
mu = alpha + beta * weight
bf.dist.normal(mu, sigma, obs=height)
end
|
model <- function(height, weight){
# Priors
sigma = bf.dist.uniform(0, 50, name='sigma', shape=c(1))
alpha = bf.dist.normal(178, 20, name='alpha', shape=c(1))
beta = bf.dist.normal(0, 1, name='beta', shape=c(1))
# Likelihood
mu = alpha + beta * weight
bf.dist.normal(mu, sigma, obs=height)
}
|
Built for Speed
Leveraging Just-In-Time (JIT) compilation via JAX, bf outperforms traditional engines on standard hardware and unlocks massive scalability on GPU clusters for large datasets.
Benchmark: Network Size 800 (Lower is Better)
| Engine | Execution Time | Relative Performance |
|---|---|---|
| STAN (CPU) | ███████████████████████████████████████ |
Baseline |
| BF (CPU) | ██████████ |
~3.7x Faster |
| BF (GPU) | ██ |
~13.5X Faster |
> Comparison of execution time for a Social Relations Model. Source: Sosa et al. (2026).
Installation & Setup
1. Install Python
Download and install Python 3.10 or later
2. Install Package
From pip
pip install BayesForge
Development Installation
pip install git+https://github.com/BGN-for-ASNA/BF.git
Or clone the repository and activate it locally:
git clone https://github.com/BGN-for-ASNA/BF.git
cd BF
Then in Python:
pip install -e .
3. Initialize Environment
from BF import BF
m = BF()
4. Select Backend
Choose "cpu", "gpu", or "tpu" when importing the library.
# Initialize on CPU (default)
m = BF(platform="cpu")
# Or on GPU (requires JAX GPU installation)
m = BF(platform="gpu")
Quick Start
from BayesForge import bf
# Initialize BF
m = bf('cpu')
# Generate some data
x = m.dist.normal(0, 1, shape=(100,), sample=True)
y = m.dist.normal(0.2 + 0.6 * x, 1.2, sample=True)
# Define a Bayesian linear regression model
def linear_model(x, y):
alpha = m.dist.normal(loc=0, scale=1, name="alpha")
beta = m.dist.normal(loc=0, scale=1, name="beta")
sigma = m.dist.exponential(1, name="sigma")
mu = alpha + beta * x
m.dist.normal(mu, sigma, obs=y)
# Fit the model
m.fit(linear_model, num_warmup=1000, num_samples=1000, num_chains=1)
# Display results
m.summary()
# Plot results with @pyplot
m.plot_trace()
Features
Data Manipulation
- One-hot encoding
- Index variable conversion
- Scaling and normalization
Modeling (via NumPyro)
- Linear & Generalized Linear Models: Regression, Binomial, Poisson, Negative Binomial, etc.
- Hierarchical/Multilevel Models: Varying intercepts and slopes.
- Time Series & Processes: Gaussian Processes, Gaussian Random Walks, State Space Models.
- Mixture Models: GMM, Dirichlet Process Mixtures.
- Network Models: Network-based diffusion, Block models.
- Bayesian Neural Networks (BNN).
Diagnostics (via ArviZ)
- Posterior summary statistics and plots.
- Trace plots, Density plots, Autocorrelation.
- WAIC and LOO (ELPD) model comparison.
- R-hat and Effective Sample Size (ESS).
Available Distributions
The package provides wrappers for a comprehensive set of distributions from NumPyro.
Continuous
m.dist.normal,m.dist.uniform,m.dist.student_tm.dist.cauchy,m.dist.halfcauchy,m.dist.halfnormalm.dist.gamma,m.dist.inverse_gamma,m.dist.exponentialm.dist.beta,m.dist.beta_proportionm.dist.laplace,m.dist.asymmetric_laplacem.dist.log_normal,m.dist.log_uniformm.dist.pareto,m.dist.weibull,m.dist.gumbelm.dist.chi2,m.dist.gompertz
Discrete
m.dist.bernoulli,m.dist.binomialm.dist.poisson,m.dist.negative_binomialm.dist.geometric,m.dist.discrete_uniformm.dist.beta_binomial,m.dist.zero_inflated_poisson
Multivariate
m.dist.multivariate_normal,m.dist.multivariate_student_tm.dist.dirichlet,m.dist.dirichlet_multinomialm.dist.multinomialm.dist.lkj,m.dist.lkj_choleskym.dist.wishart,m.dist.wishart_cholesky
Time Series & Stochastic Processes
m.dist.gaussian_random_walkm.dist.gaussian_state_spacem.dist.euler_maruyamam.dist.car(Conditional AutoRegressive)
Mixtures & Truncated
m.dist.mixture,m.dist.mixture_same_familym.dist.truncated_normal,m.dist.truncated_cauchym.dist.lower_truncated_power_law
(See package documentation for the full list)
Documentation
For full documentation and examples visit [Official website](https://s-sosa.com/BF/0.Introduction.html)
Platform Support
- ✅ Linux
- ✅ macOS
- ✅ Windows
GPU support available on compatible systems with JAX GPU installation.
Related Packages
::: {align="center"} BayesForge
Based on "The BayesForge library for Python, R, Julia" by Sosa, McElreath, & Ross (2026).
Official website | Issues | Quick Start
© 2026 BayesForge Team. Released under GPL-3.0. ::: :::: :::::
Metadata
Release files for BayesForge 0.0.60
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bayesforge-0.0.60.tar.gz | 895.1 kB | Without provenance | Details for bayesforge-0.0.60.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bayesforge-0.0.60-py3-none-any.whl | Python 3 | none | any | Details for bayesforge-0.0.60-py3-none-any.whl |
Total release size: 1.8 MB
Release files / bayesforge-0.0.60.tar.gz
| Download URL | bayesforge-0.0.60.tar.gz |
|---|---|
| Size | 895.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7790d3a8bf5d09665fc91e3dddc07b59a4c29365b5cb342664a47371dc52d0ec
|
|
BLAKE2b-256 checksum How to use checksums |
ebe0847e1bfd96b949593bc36b3875732f4df0a7f78b20b45f71c546a81c2f67
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.17
|
Release files / bayesforge-0.0.60-py3-none-any.whl
| Download URL | bayesforge-0.0.60-py3-none-any.whl |
|---|---|
| Size | 931.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
08a28dead991743fc5e37412c7108f2aa1356eb154a3b96cc993c4d28e3ec8d4
|
|
BLAKE2b-256 checksum How to use checksums |
48fef8d42249ca654e4e3877902161ee548282b93228202a2add304fd22b91b6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.17
|
Security for BayesForge 0.0.60
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.