Probjax is a powerful library for probabilistic computation in JAX, designed to simplify the development of probabilistic models and inference algorithms. It provides a comprehensive set of tools for building, training, and deploying probabilistic models with high performance and flexibility.
- Tracing: Advanced function tracing and manipulation capabilities
- Automatic Inversion: Robust automatic function inversion with support for complex transformations
- Automatic Log-Probability: Efficient computation of log-probabilities and transformed distribution handling
- Comprehensive set of probability distributions
- Support for sampling, log-probability computation, and distribution transformations
- Integration with JAX's functional programming paradigm
Built on top of Haiku, featuring:
- Standard architectures (Transformers, ResNets, U-Nets)
- Specialized layers for normalizing flows
- Coupling and autoregressive layers
- Custom layer implementations
- Various inference algorithms
- Support for variational inference
- MCMC sampling capabilities
- Numerical computation tools (ODE/SDE integration)
- Optimization utilities
- Performance monitoring and benchmarking
pip install probjaxYou can use uv for faster and more reliable Python package management:
uv pip install probjaxFor CUDA 12 support with GPU acceleration:
pip install "probjax[cuda12]"For Apple Silicon (Metal) GPU acceleration:
pip install "probjax[metal]"Then select the Metal backend at runtime (recommended via env var):
# Bash/Zsh
export JAX_PLATFORMS=metal,cpuOr in Python before importing JAX modules:
import os
os.environ["JAX_PLATFORMS"] = "metal,cpu"
import jax
print(jax.devices()) # should list Metal devicesRequirements: macOS 12+ on Apple Silicon, recent Xcode Command Line Tools, and Python 3.11 or later.
For development and testing:
git clone https://github.com/mackelab/probjax.git
cd probjax
pip install -e ".[dev]"import jax
import jax.numpy as jnp
from probjax import distributions as dist
from probjax.nn import layers
# Create a simple normal distribution
normal = dist.Normal(loc=0.0, scale=1.0)
# Sample from the distribution
key = jax.random.PRNGKey(0)
samples = normal.sample(key, sample_shape=(1000,))
# Compute log probability
log_prob = normal.log_prob(samples)Check out the examples/ directory for detailed tutorials and use cases:
basics/: Basic usage examplescore/: Core functionality demonstrationsdistributions/: Distribution examplesnn/: Neural network implementationsutils/: Utility function examples
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE.txt file for details.
If you use Probjax in your research, please cite:
@software{probjax2024,
author = {Manuel Gloeckler},
title = {Probjax: Probabilistic computation in JAX},
year = {2024},
publisher = {GitHub},
url = {https://github.com/mackelab/probjax}
}