Skip to main content

Python library for Markov Models.

Project description

MarkovM

MarkovM - Python library for Markov Models.

License PyPI Latest Release Package Status Code style: black Imports: isort

Installation

Install from Python Package Index:

pip install markovm

Install from Source Code:

pip install .

Quickstart

Create Model

You can use markovm.create_markov_model to create a Markov model. Please provide all valid states and an n-by-n matrix describing the probabilities of transitions, where n is the number of states. If two states i and j do not have a connection in between, set matrix[i][j] to 0. For example,

>>> import markovm
>>> import numpy
>>> m = markovm.create_markov_model(
...     states=("A", "B", "C"),
...     transitions=numpy.array([
...         [0.0, 1.0, 0.0],  # A must goto B
...         [0.2, 0.0, 0.8],  # B can goto A (20%) or C (80%)
...         [0.0, 0.5, 0.5],  # C can goto B or stay
...     ]),
... )

Random Walk

You can use markovm.random_walk to randomly walk through a Markov model. By default, it will start with the first state. If you want it to start with another state, please provide the index of the expected starting state to index in the function call. You can also set a seed to the function call, and it uses None by default. For example,

>>> import itertools
>>> for state in itertools.islice(
...     markovm.random_walk(m, seed=0), 5
... ):
...     print(state)
... 
A
B
C
B
A

Project details


Download files

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

Source Distribution

markovm-0.1.0.tar.gz (4.2 kB view hashes)

Uploaded Source

Built Distribution

markovm-0.1.0-py3-none-any.whl (4.3 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