Skip to main content

MARKOV SOLVER

markov-solver-banner

PyPI version Python versions License Build status Tests Coverage Code style: black Downloads

Solve Markov Chains in a glance.

Table of Contents

Features

  • Solve Markov Chains: Compute steady-state probabilities for discrete-time Markov chains.
  • Symbolic Transition Rates: Define transition rates using symbolic expressions with named parameters.
  • YAML Chain Definitions: Define Markov chains in simple, human-readable YAML files.
  • Graph Visualization: Automatically render Markov chain diagrams in SVG and PNG formats using Graphviz.
  • CLI and Library: Use as a command-line tool or integrate directly into your Python projects.
  • Export Results: Save solutions to TXT and CSV files for further analysis.
  • High Precision: Calculations with 12 decimal places of floating-point precision.

Installation

pip install markov-solver

Usage

You can use markov-solver as a CLI or as a library in your project.

To use it as a CLI, check the recorded demo:

Markov Chain Solver Demo

To use it as a library, you can check the examples.

In both cases you need to define the Markov Chain to solve. See the instructions below to know how to do it.

Chain with constant transition rates

Let us image that we want to solve the following Markov chain:

Markov Chain Simple

We should create a YAML file that defines the chain:

chain:
  - from: "Sunny"
    to: "Sunny"
    value: "0.9"

  - from: "Sunny"
    to: "Rainy"
    value: "0.1"

  - from: "Rainy"
    to: "Rainy"
    value: "0.5"

  - from: "Rainy"
    to: "Sunny"
    value: "0.5"

Then, running the following command:

markov-solver solve --definition [PATH_TO_DEFINITION_FILE]

We obtain the following result:

===============================================================
                     MARKOV CHAIN SOLUTION
===============================================================

                      states probability
Rainy.........................................0.166666666666667
Sunny.........................................0.833333333333333

Chain with symbolic transition rates

Let us image that we want to solve the following Markov chain:

Markov Chain Symbolic

We should create a YAML file that defines the chain:

symbols:
  lambda: 1.5
  mu: 2.0

chain:
  - from: "0"
    to: "1"
    value: "lambda"

  - from: "1"
    to: "2"
    value: "lambda"

  - from: "2"
    to: "3"
    value: "lambda"

  - from: "3"
    to: "2"
    value: "3*mu"

  - from: "2"
    to: "1"
    value: "2*mu"

  - from: "1"
    to: "0"
    value: "mu"

Then, running the following command:

markov-solver solve --definition [PATH_TO_DEFINITION_FILE]

We obtain the following result:

===============================================================
                     MARKOV CHAIN SOLUTION
===============================================================

                      states probability
0.............................................0.475836431226766
1.............................................0.356877323420074
2.............................................0.133828996282528
3............................................0.0334572490706320

References

Issues

Please report any issues or feature requests on the GitHub Issues page.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Metadata

Release files for markov-solver 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for markov-solver 2.0.0
File Size Uploaded Provenance
markov_solver-2.0.0.tar.gz 18.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for markov-solver 2.0.0
File Interpreter ABI Platform
markov_solver-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 40.4 kB

Release files / markov_solver-2.0.0.tar.gz

Download URL markov_solver-2.0.0.tar.gz
Size 18.2 kB
Tags Source
SHA-256 checksum
How to use checksums
78ca9c4b5206112e2bbc7d65d2d41955b821dd0e264a3c381c234bff46764fd2
BLAKE2b-256 checksum
How to use checksums
1b16f486a64129b2f71fb3ee60958a747441d6551a2c82dfffb458ccac82be83
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release files / markov_solver-2.0.0-py3-none-any.whl

Download URL markov_solver-2.0.0-py3-none-any.whl
Size 22.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9a07e97b1ce46875f73766d6b0f66b0249efcc2b38e161b9d93ef7b7755cf213
BLAKE2b-256 checksum
How to use checksums
be02a5d95b88d2b0d35230ec2f95b843a359b577eb7668b6a7848134778a64a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Security for markov-solver 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page