markovm


Namemarkovm JSON
Version 0.1.0 PyPI version JSON
download
home_page
SummaryPython library for Markov Models.
upload_time2023-06-10 22:39:31
maintainer
docs_urlNone
author
requires_python>=3.7
licenseMIT
keywords markov model markov chain
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <p align="center">
  <a href="https://github.com/HH-MWB/timerun">
    <img src="https://user-images.githubusercontent.com/50187675/244896432-f28357ec-2ced-4095-aef1-fca6a73dd983.png" alt="MarkovM">
  </a>
</p>

<p align="center"><strong>MarkovM</strong> - <em>Python library for Markov Models.</em></p>

<p align="center">
    <a href="https://github.com/HH-MWB/markovm/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/pypi/l/markovm.svg"></a>
    <a href="https://pypi.org/project/markovm/"><img alt="PyPI Latest Release" src="https://img.shields.io/pypi/v/markovm.svg"></a>
    <a href="https://pypi.org/project/markovm/"><img alt="Package Status" src="https://img.shields.io/pypi/status/markovm.svg"></a>
    <a href="https://github.com/psf/black/"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
    <a href="https://pycqa.github.io/isort/"><img alt="Imports: isort" src="https://img.shields.io/badge/%20imports-isort-%231674b1"></a>
</p>

## Installation

Install from [Python Package Index](https://pypi.org/project/markovm/):

```sh
pip install markovm
```

Install from [Source Code](https://github.com/HH-MWB/markovm):

```sh
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,

```python
>>> 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,

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

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "markovm",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "markov model,markov chain",
    "author": "",
    "author_email": "HH-MWB <h.hong@mail.com>",
    "download_url": "https://files.pythonhosted.org/packages/ea/56/b001cc15f98ce15e015cf579ff368411d4e7fe9f247639f7d151e9e328e6/markovm-0.1.0.tar.gz",
    "platform": null,
    "description": "<p align=\"center\">\n  <a href=\"https://github.com/HH-MWB/timerun\">\n    <img src=\"https://user-images.githubusercontent.com/50187675/244896432-f28357ec-2ced-4095-aef1-fca6a73dd983.png\" alt=\"MarkovM\">\n  </a>\n</p>\n\n<p align=\"center\"><strong>MarkovM</strong> - <em>Python library for Markov Models.</em></p>\n\n<p align=\"center\">\n    <a href=\"https://github.com/HH-MWB/markovm/blob/main/LICENSE\"><img alt=\"License\" src=\"https://img.shields.io/pypi/l/markovm.svg\"></a>\n    <a href=\"https://pypi.org/project/markovm/\"><img alt=\"PyPI Latest Release\" src=\"https://img.shields.io/pypi/v/markovm.svg\"></a>\n    <a href=\"https://pypi.org/project/markovm/\"><img alt=\"Package Status\" src=\"https://img.shields.io/pypi/status/markovm.svg\"></a>\n    <a href=\"https://github.com/psf/black/\"><img alt=\"Code style: black\" src=\"https://img.shields.io/badge/code%20style-black-000000.svg\"></a>\n    <a href=\"https://pycqa.github.io/isort/\"><img alt=\"Imports: isort\" src=\"https://img.shields.io/badge/%20imports-isort-%231674b1\"></a>\n</p>\n\n## Installation\n\nInstall from [Python Package Index](https://pypi.org/project/markovm/):\n\n```sh\npip install markovm\n```\n\nInstall from [Source Code](https://github.com/HH-MWB/markovm):\n\n```sh\npip install .\n```\n\n## Quickstart\n\n### Create Model\n\nYou 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,\n\n```python\n>>> import markovm\n>>> import numpy\n>>> m = markovm.create_markov_model(\n...     states=(\"A\", \"B\", \"C\"),\n...     transitions=numpy.array([\n...         [0.0, 1.0, 0.0],  # A must goto B\n...         [0.2, 0.0, 0.8],  # B can goto A (20%) or C (80%)\n...         [0.0, 0.5, 0.5],  # C can goto B or stay\n...     ]),\n... )\n```\n\n### Random Walk\n\nYou 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,\n\n```python\n>>> import itertools\n>>> for state in itertools.islice(\n...     markovm.random_walk(m, seed=0), 5\n... ):\n...     print(state)\n... \nA\nB\nC\nB\nA\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Python library for Markov Models.",
    "version": "0.1.0",
    "project_urls": {
        "Bug Reports": "https://github.com/HH-MWB/markovm/issues",
        "Homepage": "https://pypi.org/project/markovm",
        "Source": "https://github.com/HH-MWB/markovm"
    },
    "split_keywords": [
        "markov model",
        "markov chain"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "567a19213b454b70b872bcaf653432a30bdb2b459a7b4751c6878bbf9207bc77",
                "md5": "0bd7294d2576c7f57d16ad530f8536a0",
                "sha256": "38fd88e21834138ae2b4cabaa106b067d382aa5e1917e7bdc90ebc1692790e62"
            },
            "downloads": -1,
            "filename": "markovm-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0bd7294d2576c7f57d16ad530f8536a0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 4313,
            "upload_time": "2023-06-10T22:39:26",
            "upload_time_iso_8601": "2023-06-10T22:39:26.291707Z",
            "url": "https://files.pythonhosted.org/packages/56/7a/19213b454b70b872bcaf653432a30bdb2b459a7b4751c6878bbf9207bc77/markovm-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ea56b001cc15f98ce15e015cf579ff368411d4e7fe9f247639f7d151e9e328e6",
                "md5": "c19932b96f70192d50cdbec80b2b9a50",
                "sha256": "31a1190a11175943a6422454c91ed25f9e86fb470e7de04facf993d66263f4e3"
            },
            "downloads": -1,
            "filename": "markovm-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "c19932b96f70192d50cdbec80b2b9a50",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 4172,
            "upload_time": "2023-06-10T22:39:31",
            "upload_time_iso_8601": "2023-06-10T22:39:31.589992Z",
            "url": "https://files.pythonhosted.org/packages/ea/56/b001cc15f98ce15e015cf579ff368411d4e7fe9f247639f7d151e9e328e6/markovm-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-10 22:39:31",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "HH-MWB",
    "github_project": "markovm",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "markovm"
}
        
Elapsed time: 0.07397s