Skip to main content

PyDTMC is a full-featured, lightweight library for discrete-time Markov chains analysis. It provides classes and functions for creating, manipulating and simulating markovian stochastic processes.

Requirements

PyDTMC supports only Python 3 and the minimum required version is 3.6. In addition, the environment must include the following libraries:

For a better user experience, it's recommended to install Graphviz and PyDot before using the plot_graph function. In order to build the project documentation, it's necessary to install Sphinx. In order to perform unit tests, it's necessary to install PyTest.

Installation & Upgrade

Via PyPI:

$ pip install PyDTMC
$ pip install --upgrade PyDTMC

Via GitHub:

$ pip install git+https://github.com/TommasoBelluzzo/PyDTMC.git@master#egg=PyDTMC
$ pip install --upgrade git+https://github.com/TommasoBelluzzo/PyDTMC.git@master#egg=PyDTMC

Usage

The core element of the library is the MarkovChain class, which can be instantiated as follows:

>>> p = [[0.2, 0.7, 0.0, 0.1], [0.0, 0.6, 0.3, 0.1], [0.0, 0.0, 1.0, 0.0], [0.5, 0.0, 0.5, 0.0]]
>>> mc = MarkovChain(p, ['A', 'B', 'C', 'D'])
>>> print(mc)

DISCRETE-TIME MARKOV CHAIN
 SIZE:           4
 RANK:           4
 CLASSES:        2
  > RECURRENT:   1
  > TRANSIENT:   1
 ERGODIC:        NO
  > APERIODIC:   YES
  > IRREDUCIBLE: NO
 ABSORBING:      YES
 REGULAR:        NO
 REVERSIBLE:     NO

Below a few examples of MarkovChain instance properties and static computations:

>>> print(mc.is_ergodic)
False

>>> print(mc.recurrent_states)
['C']

>>> print(mc.transient_states)
['A', 'B', 'D']

>>> print(mc.steady_states)
[array([0.0, 0.0, 1.0, 0.0])]

>>> print(mc.is_absorbing)
True

>>> print(mc.fundamental_matrix)
[[1.50943396 2.64150943 0.41509434]
 [0.18867925 2.83018868 0.30188679]
 [0.75471698 1.32075472 1.20754717]]
 
>>> print(mc.kemeny_constant)
5.547169811320755

>>> print(mc.mean_absorption_times())
[4.56603774 3.32075472 3.28301887]

>>> print(mc.absorption_probabilities())
[1.0 1.0 1.0]

>>> print(mc.entropy_rate)
None

Dynamic computations on MarkovChain instances can be performed through their parametrized methods:

>>> print(mc.expected_rewards(10, [2, -3, 8, -7]))
[-2.76071635, -12.01665113, 23.23460025, -8.45723276]

>>> print(mc.expected_transitions(2))
[[0.085, 0.2975, 0.0,    0.0425]
 [0.0,   0.345,  0.1725, 0.0575]
 [0.0,   0.0,    0.7,    0.0   ]
 [0.15,  0.0,    0.15,   0.0   ]]

>>> print(mc.first_passage_probabilities(5, 3))
[[0.5, 0.0,    0.5,    0.0   ]
 [0.0, 0.35,   0.0,    0.05  ]
 [0.0, 0.07,   0.13,   0.045 ]
 [0.0, 0.0315, 0.1065, 0.03  ]
 [0.0, 0.0098, 0.0761, 0.0186]]
 
>>> print(mc.hitting_probabilities([0, 1]))
[1.0, 1.0, 0.0, 0.5]
 
>>> print(mc.walk(10))
['B', 'B', 'B', 'D', 'A', 'B', 'B', 'C', 'C', 'C']

Plotting functions can provide a visual representation of MarkovChain instances; in order to display function outputs immediately, the interactive mode of Matplotlib must be turned on:

>>> plot_eigenvalues(mc)

Eigenplot

>>> plot_graph(mc)

Graphplot

>>> plot_walk(mc, 10, 'sequence')

Walkplot

Download files

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

Source Distribution

PyDTMC-5.5.0.tar.gz (58.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

PyDTMC-5.5.0-py3-none-any.whl (44.0 kB view details)

Uploaded Python 3

File details

Details for the file PyDTMC-5.5.0.tar.gz.

File metadata

  • Download URL: PyDTMC-5.5.0.tar.gz
  • Upload date:
  • Size: 58.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.6.6

File hashes

Hashes for PyDTMC-5.5.0.tar.gz
Algorithm Hash digest
SHA256 6bfa5b64492d92d60c54109ee702f1724a61ded6930d54399ec326dbb19b2467
MD5 6493b82526929d8754ee2fd2738e571f
BLAKE2b-256 e49e3b2abba0dafb423d543270162b118469387efd9f78d776bf057b22987aca

See more details on using hashes here.

File details

Details for the file PyDTMC-5.5.0-py3-none-any.whl.

File metadata

  • Download URL: PyDTMC-5.5.0-py3-none-any.whl
  • Upload date:
  • Size: 44.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.6.6

File hashes

Hashes for PyDTMC-5.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0d860f9a108a3be8667ca4d62a8fdcb14994ccc9fd0da0aa8a197befaa0693d8
MD5 87b7d580dc6366a9d15db8f463281ada
BLAKE2b-256 231a31dc40c86874e332f6ad9e52b62464344e5eb3a07c828ce30a1da2c76d18

See more details on using hashes here.

Release history Release notifications | RSS feed

9.0.0

2 files

8.7.0

2 files

8.0.0

2 files

7.0.0

2 files

6.11.0

2 files

6.10.0

2 files

6.9.0

2 files

6.8.0

2 files

6.6.0

2 files

6.5.0

2 files

6.4.0

2 files

6.3.0

2 files

6.2.0

2 files

6.1.0

2 files

6.0.0

2 files

5.9.0

2 files

5.8.0

2 files

5.7.0

2 files

5.6.0

2 files

This release

5.5.0 This release

2 files

5.4.0

2 files

5.3.0

1 file

5.2.0

1 file

5.1.0

1 file

5.0.0

1 file

4.9.0

1 file

4.8.0

1 file

4.7.0

1 file

4.6.0

1 file

4.5.0

1 file

4.4.0

1 file

4.3.0

1 file

4.2.0

1 file

4.1.0

1 file

4.0.0

1 file

3.9.0

1 file

3.8.0

1 file

3.7.0

1 file

3.6.0

1 file

3.5.0

1 file

3.4.0

1 file

3.3.0

1 file

3.2.0

1 file

3.1.0

1 file

3.0.0

1 file

2.9.0

1 file

2.8.0

1 file

2.7.0

1 file

2.6.0

1 file

2.5.0

1 file

2.4.0

1 file

2.3.0

1 file

2.2.0

1 file

2.1.0

1 file

2.0.0

1 file

1.9.0

1 file

1.8.0

1 file

1.7.0

1 file

1.6.0

1 file

1.5.0

1 file

1.4.0

1 file

1.3.0

1 file

1.2.0

1 file

1.1.0

1 file

1.0.0

1 file

0.1.2

1 file

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page