Skip to main content

Simple CTMC solver for Python

Project description

Markon

Continous Time Markov Chain solver for Python

Markon is a small Python utility for performing analytic solution of CTMCs. Both quantitative and symbolic analysis is possible.

Example:

from markon import solve_ctmc

# Define a CTMC as a dict of state-tuples (from_state, to_state) to a transition rate
t = {('up', 'down'): 1,  # Transition rate from 'up' to 'down' is 1
     ('down', 'up'): 5}  # Transition rate from 'down' to 'up' is 5

# Obtain steady state probabilities
p = solve_ctmc(t)
print(p)

will output

{'down': 1/6, 'up': 5/6}

Individual state probabilities can be obtained, both in exact form or as a single rounded float:

print(p['up'])
print(float(p['up']))

will output

5/6
0.8333333333333334

General symbolic analysis can also be done via Sympy:

from markon import solve_ctmc
import sympy

# Define Sympy symbols
l, m = sympy.symbols('l, m')

t = {('up', 'down'): l,
     ('down', 'up'): m}

# Obtain steady state probabilities with defined order
p = solve_ctmc(t, ['up', 'down'])
print(p)

will output

{'up': m/(l + m), 'down': l/(l + m)}

We can then use Sympy functionality to substitute values

values = [(l, 1), (m,5)]
print(p['up'].subs(values))

will output

5/6

Refer to the Sympy documentation for more on how to enable nice formatting of expressions, output to Latex, etc.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

markon-1.0.0-py3-none-any.whl (3.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page