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 details)

Uploaded Source

Built Distribution

markovm-0.1.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file markovm-0.1.0.tar.gz.

File metadata

  • Download URL: markovm-0.1.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for markovm-0.1.0.tar.gz
Algorithm Hash digest
SHA256 31a1190a11175943a6422454c91ed25f9e86fb470e7de04facf993d66263f4e3
MD5 c19932b96f70192d50cdbec80b2b9a50
BLAKE2b-256 ea56b001cc15f98ce15e015cf579ff368411d4e7fe9f247639f7d151e9e328e6

See more details on using hashes here.

File details

Details for the file markovm-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: markovm-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for markovm-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 38fd88e21834138ae2b4cabaa106b067d382aa5e1917e7bdc90ebc1692790e62
MD5 0bd7294d2576c7f57d16ad530f8536a0
BLAKE2b-256 567a19213b454b70b872bcaf653432a30bdb2b459a7b4751c6878bbf9207bc77

See more details on using hashes here.

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