phdist is a PyTorch library for Phase-Type (PH) distributions, designed for both classical statistical modeling and modern deep learning workflows.
The library provides:
- Differentiable PH distributions
- Maximum likelihood estimation (MLE)
- Clean integration with PyTorch optimizers
- Exact handling of PH parameters for evaluation and fitting
This project has a special focus on heavy-tailed modeling.
- General Phase-Type distribution
- Series Canonical From Phase-Type distribution
- Valid PH parameterization with automatic constraints
- Maximum likelihood fitting via negative log-likelihood
- Compatible with PyTorch autograd and optimizers
- Supports both:
- fixed PH distributions, where the user gives the paramters and use the library for different utilities
- trainable PH models, to find the paramters of a PH (typical use case in deep learning models).
- Sampling utilities(stochastic and differentiable reparametirization)
Planned:
- Deep learning modules
Install from source:
git clone https://github.com/yourusername/phdist.git
cd phdist
pip install -e .Dependencies:
- Python ≥ 3.9
- PyTorch
- NumPy
from phdist import GeneralPH
ph = GeneralPH(m=5)
print(ph.alpha) # initial distribution
print(ph.A) # sub-generator matriximport torch
x = torch.rand(100) + 0.1 # positive data
logp = ph.log_prob(x)from phdist import fit_ph_mle
fit_ph_mle(ph, x, lr=5e-3, steps=2000)
# learned parameters
print(ph.alpha)
print(ph.A)ph = GeneralPH(alpha=alpha0, A=A0)This uses the provided parameters exactly for likelihood evaluation. Optimization (if performed) updates them explicitly.
Current version: v0.1.0
This is an early research release.
APIs may evolve as new PH variants are added.
If you use this library in academic work, please cite:
@misc{phdist,
title = {phdist: Phase-Type Distributions in PyTorch},
author = {Hakim Ziani and Andras Horvath and Paolo Ballarini},
year = {2026},
note = {GitHub repository}
}MIT License (see LICENSE).
This library is developed in the context of research on heavy-tailed modeling and probabilistic deep learning.
Further details on Phase-Type distributions and their ability to approximate heavy-tailed data are provided in the following paper: https://arxiv.org/abs/2510.26524