Python library for Markov Models.
Project description
MarkovM - Python library for Markov Models.
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
31a1190a11175943a6422454c91ed25f9e86fb470e7de04facf993d66263f4e3
|
|
| MD5 |
c19932b96f70192d50cdbec80b2b9a50
|
|
| BLAKE2b-256 |
ea56b001cc15f98ce15e015cf579ff368411d4e7fe9f247639f7d151e9e328e6
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
38fd88e21834138ae2b4cabaa106b067d382aa5e1917e7bdc90ebc1692790e62
|
|
| MD5 |
0bd7294d2576c7f57d16ad530f8536a0
|
|
| BLAKE2b-256 |
567a19213b454b70b872bcaf653432a30bdb2b459a7b4751c6878bbf9207bc77
|