ANN: PyDTMC 10.0.0 — Discrete-time Markov chains and hidden Markov models in Python

Hi everyone,

I’d like to introduce PyDTMC, an open-source Python library that I’ve been developing and maintaining since 2019, focused on discrete-time Markov chains and hidden Markov models.

With the recent release of PyDTMC 10.0.0, I thought this would be a good opportunity to share the project with the Scientific Python community.

Main Capabilities

PyDTMC provides a comprehensive collection of tools for constructing, manipulating, analyzing, simulating, and visualizing finite-state Markovian stochastic processes. Its goal is to make both fundamental and more advanced Markov-chain techniques accessible through a consistent Python API.

The library covers several areas of stochastic modeling and analysis:

  • Markov-chain construction and manipulation: Creating chains from transition matrices or predefined models, generating random chains, and applying transformations such as censoring, lumping, and time reversal.

  • Structural and probabilistic analysis: Communicating classes, irreducibility, periodicity, recurrence, stationary distributions, absorption, hitting probabilities, first-passage times, and expected rewards.

  • Spectral and mixing analysis: Eigenvalue-based diagnostics, spectral gaps, Dobrushin and Doeblin contraction coefficients, conductance, and mixing-time measures.

  • Advanced Markov-chain diagnostics: Entropy production, stationary probability fluxes and currents, committor probabilities, reactive fluxes, perturbation and sensitivity analysis, and metastability-related measures.

  • Hidden Markov models: Construction, estimation, simulation, decoding, and prediction using transition and emission probabilities.

  • Visualization: Directed graphs, transition matrices, eigenvalues, state sequences, probability redistribution, and hidden-state trellises.

Example

A discrete-time Markov chain can be defined directly from its transition matrix:

from pydtmc import MarkovChain

p = [
    [0.8, 0.2],
    [0.3, 0.7]
]

mc = MarkovChain(p, ['A', 'B'])

print(mc.pi)
print(mc.is_ergodic)
print(mc.simulate(10, seed=42))

The same object provides access to a wider range of structural, probabilistic, and numerical properties without requiring separate implementations of the underlying algorithms.

Installation

PyDTMC 10.0.0 requires Python 3.12 or newer and is available through PyPI:

pip install pydtmc

The project is also distributed through conda-forge:

conda install -c conda-forge pydtmc

Project Links

PyDTMC is released under the MIT license. The repository includes the source code, automated tests, documentation, and examples.

Feedback & Contributions

I’d be particularly interested in feedback from researchers, educators, and developers working in related scientific fields or exploring potential applications of the library.

Suggestions concerning mathematical functionality, API design, numerical behavior, interoperability with other scientific Python packages, and potential use cases are very welcome.

Thanks for taking a look!