StochX
StochX is a lightweight Python library for turning stochastic-process mathematics into executable, validated, and testable objects.
It is designed around a simple idea: each mathematical object should have a clear Python representation, a predictable API, numerical validation, and runnable examples.
What makes StochX different
StochX is not limited to discrete-time Markov chains. Its public stochastic API is organized around several connected mathematical objects:
| Area | Main objects |
|---|---|
| Discrete-time Markov chains | MarkovChain |
| Poisson processes | PoissonProcess, NonHomogeneousPoissonProcess |
| Continuous-time Markov chains | ContinuousTimeMarkovChain, CTMCPath |
| Birth-death processes | BirthDeathProcess |
| Finite probability spaces | FiniteProbabilitySpace, RandomVariable, Partition |
| Conditional expectation | FiniteProbabilitySpace, RandomVariable |
| Filtrations and martingales | Filtration, Martingale, StoppingTime, StoppedProcess |
Two features are particularly central to the library:
- CTMC numerical flexibility: transition probabilities can be evaluated using the matrix-exponential route or a uniformization implementation.
- Mathematical continuity: finite conditional expectation, filtrations, martingales, and stopping times are first-class public objects rather than separate utilities.
Installation
python -m pip install stochx
For development:
python -m pip install -e ".[dev]"
For documentation development:
python -m pip install -e ".[docs]"
mkdocs serve
Quick start
Discrete-time Markov chain
import numpy as np
from stochx.stochastic import MarkovChain, empirical_state_frequencies
P = [
[0.7, 0.3],
[0.4, 0.6],
]
chain = MarkovChain(P, states=["A", "B"])
print(chain.n_step_transition(5))
print(chain.stationary_distribution())
path = chain.simulate(
10_000,
initial_state="A",
rng=np.random.default_rng(0),
)
print(empirical_state_frequencies(path, chain.states))
Continuous-time Markov chain
from stochx.stochastic import ContinuousTimeMarkovChain
Q = [
[-2.0, 2.0],
[1.0, -1.0],
]
chain = ContinuousTimeMarkovChain(Q, states=["A", "B"])
print(chain.transition_matrix(2.0))
print(chain.transition_matrix_at(2.0, method="uniformization"))
Public API
The public stochastic namespace is available from stochx.stochastic:
from stochx.stochastic import (
BirthDeathProcess,
CTMCPath,
ContinuousTimeMarkovChain,
FiniteProbabilitySpace,
Filtration,
MarkovChain,
Martingale,
NonHomogeneousPoissonProcess,
Partition,
PoissonProcess,
RandomVariable,
StoppedProcess,
StoppingTime,
empirical_state_frequencies,
)
The complete reference is maintained in the API documentation.
Examples
Every major mathematical area has a runnable example, and examples/07_api_operations.py provides a broader public-API gallery.
examples/
├── 01_discrete_markov_chain.py
├── 02_poisson_process.py
├── 03_continuous_markov_chain.py
├── 04_birth_death_process.py
├── 05_conditional_expectation.py
├── 06_martingale.py
└── 07_api_operations.py
The CI suite executes every examples/*.py file.
Documentation
The documentation site separates three concerns:
- Course material for the mathematical development.
- API Reference for Python classes, properties, methods, validation rules, and examples.
- Worked Examples for end-to-end executable usage.
Start at the documentation site.
Development and quality gates
The repository uses GitHub Actions to run the stochastic test suite on Python 3.10, 3.11, and 3.12. The CI pipeline also checks:
- public API docstring coverage;
- API-reference page coverage;
- documentation structure;
- runnable example coverage;
- strict MkDocs builds.
Run the main stochastic suite locally with:
pytest -q tests/test_stochastic_*.py --disable-warnings
Run the release-surface checks with:
pytest -q \
tests/test_docstring_coverage.py \
tests/test_stochastic_example_coverage.py \
tests/test_api_documentation_coverage.py \
tests/test_documentation_coverage.py
Build the package locally before a release:
python -m build
python -m twine check dist/*
Versioning
StochX follows semantic versioning for public API changes:
MAJORfor incompatible public API changes;MINORfor backwards-compatible features;PATCHfor backwards-compatible fixes.
The package version is defined once in stochx/__init__.py and is used by the build configuration, avoiding separate version values that can drift.
Release status
StochX is currently in the early development stage. PyPI publishing is prepared through a tag-based release workflow, but releases are not automatically published until the repository's PyPI trusted publisher is configured.
License
MIT
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file stochx-0.2.0.tar.gz.
File metadata
- Download URL: stochx-0.2.0.tar.gz
- Upload date:
- Size: 72.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
605dc64214d80f05d45eb0351a18a271c2fad51ca6d820306640498b66a822c8
|
|
| MD5 |
8142459970296d9af2c36a18c1a457c4
|
|
| BLAKE2b-256 |
fd0a369f902758b03703c6d619dbd65df71e0f0e2ead2bba9fe745a75941c57b
|
Provenance
The following attestation bundles were made for stochx-0.2.0.tar.gz:
Publisher:
release.yml on Faycal214/stochx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
stochx-0.2.0.tar.gz -
Subject digest:
605dc64214d80f05d45eb0351a18a271c2fad51ca6d820306640498b66a822c8 - Sigstore transparency entry: 2482010118
- Sigstore integration time:
-
Permalink:
Faycal214/stochx@4f903fb7e4da5972ca6f42bbd77acbc2d0c12154 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Faycal214
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4f903fb7e4da5972ca6f42bbd77acbc2d0c12154 -
Trigger Event:
push
-
Statement type:
File details
Details for the file stochx-0.2.0-py3-none-any.whl.
File metadata
- Download URL: stochx-0.2.0-py3-none-any.whl
- Upload date:
- Size: 37.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6fc204c584c918bb7c840dcbfc57f2e548baea4f51214ddc7de49aa5431cd1af
|
|
| MD5 |
3d2ddec74b36e3ef41336da6ecbe9c67
|
|
| BLAKE2b-256 |
14acf3ee36fd33bc4a1698f365b3d47c1c80141bf63417bbc5fd253a991198bd
|
Provenance
The following attestation bundles were made for stochx-0.2.0-py3-none-any.whl:
Publisher:
release.yml on Faycal214/stochx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
stochx-0.2.0-py3-none-any.whl -
Subject digest:
6fc204c584c918bb7c840dcbfc57f2e548baea4f51214ddc7de49aa5431cd1af - Sigstore transparency entry: 2482010191
- Sigstore integration time:
-
Permalink:
Faycal214/stochx@4f903fb7e4da5972ca6f42bbd77acbc2d0c12154 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Faycal214
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4f903fb7e4da5972ca6f42bbd77acbc2d0c12154 -
Trigger Event:
push
-
Statement type: