Skip to content

HakimZiani/phdist

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

phdist

Version License Python

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.


Features

  • 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

Installation

Install from source:

git clone https://github.com/yourusername/phdist.git
cd phdist
pip install -e .

Dependencies:

  • Python ≥ 3.9
  • PyTorch
  • NumPy

Quick Start

Create a PH distribution

from phdist import GeneralPH

ph = GeneralPH(m=5)

print(ph.alpha)  # initial distribution
print(ph.A)      # sub-generator matrix

Evaluate log-likelihood

import torch

x = torch.rand(100) + 0.1  # positive data
logp = ph.log_prob(x)

Fit a PH distribution (MLE)

from phdist import fit_ph_mle

fit_ph_mle(ph, x, lr=5e-3, steps=2000)

# learned parameters
print(ph.alpha)  
print(ph.A)

Initialize from known PH parameters

ph = GeneralPH(alpha=alpha0, A=A0)

This uses the provided parameters exactly for likelihood evaluation. Optimization (if performed) updates them explicitly.


Project Status

Current version: v0.1.0
This is an early research release.
APIs may evolve as new PH variants are added.


Citation

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}
}

License

MIT License (see LICENSE).


Acknowledgements

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

About

A python library to work with Phase-Type distribution in deep learning

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors