Skip to main content

A Python Library for Markov Chain based Stochastic Analysis!

Project description

logo1

ChainoPy 1.0

A Python 🐍 Package for Markov Chains, Markov Chain Neural Networks and Markov Switching Models.

Why ChainoPy?

  • Covers most of the fundamental agorithms for Markov Chain Analysis
  • Memory efficient Model saving
  • Faster than other libraries (eg: 5x Faster than PyDTMC)
  • First Package to contain functions to build equivalent Markov Chain Neural Networks from Markov Chains.
  • Contains Markov Switching Models for Univariate Time Series Analysis
  • Supports Numpy 2.0.0

How to Install ChainoPy?

Using pip

pip install chainopy

Build from Source

Before you begin, ensure you have the following installed on your system:

  • Python (> 3.9 )

1. Clone the Repository

Fork and Clone the Chainopy repository to your local machine using Git:

git clone https://github.com/aadya940/chainopy.git

Navigate to the directory which contains the pyproject.toml file.

2. Install the package

python -m build

How to run ChainoPy Tests?

  1. Clone the project locally
  2. Install packages mentioned in requirements.txt and requirements_test.txt
  3. Navigate to the directory containing tests folder
  4. Run the following command:
python -m pytest tests/

You're all Set! 😃 👍

The Basics

Create Markov Chains and Markov Chain Neural Networks as follows:

>>> import chainopy
>>> mc = chainopy.MarkovChain([[0, 1], [1, 0]], states = ["Rain", "No-Rain"])    # Creates a two-states Markov Chain stored in `mc`.
>>> neural_network = chainopy.MarkovChainNeuralNetwork(mc, num_layers = 5)    # Creates a 5-layered Neural Network that simulates `mc`. 

image

Create a Markov Switching Model as follows:

>>> import numpy as np
>>> import random
>>> from chainopy import MarkovSwitchingModel
>>> X = np.random.normal(0, 1, 1000) + np.random.logistic(5, 10, 1000) # Generate Random Training Data
>>> regime_col = [random.choice(["High", "Low", "Stagnant"]) for _ in range(1000)] # Generate Regimes for Training Data
>>> mod = MarkovSwitchingModel()
>>> mod.fit(X, regime_col)
>>> y, regime_y = mod.predict("High", steps=20)

Generates Data as follows:

  • X: We generate 1000 data points by combining a normal distribution (mean = 0, standard deviation = 1) with a logistic distribution (mean = 5, scale = 10). This creates a complex dataset with variations.
  • regime_col: We assign one of three possible regimes ("High", "Low", "Stagnant") to each data point. This is done by randomly selecting one of these regimes for each of the 1000 data points.

Later, Creates a Markov Switching Model using chainopy.MarkovSwitchingModel with 3 regimes (High, Low and Stagnant) and predicts the next twenty steps if the start states is "High".

Example - Apple Weekly High Stock data prediction using chainopy.MarkovSwitchingModel

image

How to Contribute?

  1. Fork the Project.
  2. Clone the Project locally.
  3. Create a New Branch to Contribute.
  4. run pip install -r requirements.txt and pip install -r requirements_test.txt to download dependencies.
  5. Do the changes of interest (Make sure to write docstrings).
  6. Write Unit Tests and test your implementation.
  7. Format the code using the Black Formatter.
  8. Push the changes and submit a Pull Request.

Note: If your implementation is Cython, justify its usage in your PR to make the code more maintainable.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

chainopy-1.0.3-cp312-cp312-win_amd64.whl (257.7 kB view details)

Uploaded CPython 3.12Windows x86-64

chainopy-1.0.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

chainopy-1.0.3-cp312-cp312-macosx_11_0_arm64.whl (256.3 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

chainopy-1.0.3-cp312-cp312-macosx_10_9_x86_64.whl (268.8 kB view details)

Uploaded CPython 3.12macOS 10.9+ x86-64

chainopy-1.0.3-cp311-cp311-win_amd64.whl (255.4 kB view details)

Uploaded CPython 3.11Windows x86-64

chainopy-1.0.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

chainopy-1.0.3-cp311-cp311-macosx_11_0_arm64.whl (255.8 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

chainopy-1.0.3-cp311-cp311-macosx_10_9_x86_64.whl (267.2 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

chainopy-1.0.3-cp310-cp310-win_amd64.whl (255.1 kB view details)

Uploaded CPython 3.10Windows x86-64

chainopy-1.0.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

chainopy-1.0.3-cp310-cp310-macosx_11_0_arm64.whl (256.4 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

chainopy-1.0.3-cp310-cp310-macosx_10_9_x86_64.whl (267.5 kB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

File details

Details for the file chainopy-1.0.3-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: chainopy-1.0.3-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 257.7 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for chainopy-1.0.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 869610e9e238b4c7ebe0cdbecbb9f134830d2553ad7e153672ccfe04134598ba
MD5 7dd85c9bc33796d12955f32b37560c8a
BLAKE2b-256 1edcdf6d96efa2f5bdaf4763d6ae94d3f0be916bef5514bb464e2f04a08e393f

See more details on using hashes here.

File details

Details for the file chainopy-1.0.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for chainopy-1.0.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 27656b93599d50f9aebc9495516a3a32e3a0db9f04679d0bcd0ea80e2c039941
MD5 222e6346c22411e486ac27781c54ab04
BLAKE2b-256 5134e9891a428fdacc171b6984c074131ec5d7d57b2a1a6678ddfefa49b9b4d8

See more details on using hashes here.

File details

Details for the file chainopy-1.0.3-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for chainopy-1.0.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 44f476d75a45e7fda8812bae370f6680f5b722fcf693592f5886445f3e491478
MD5 15116314bfc75e39e257730868b0e573
BLAKE2b-256 81068a51089b517cd991c2977460980949609c995e53406edc113b55f6ef24e1

See more details on using hashes here.

File details

Details for the file chainopy-1.0.3-cp312-cp312-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for chainopy-1.0.3-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 b9c41ee4c622129fede8cb0b480ddc9cd7040e0e8d367cb9e43534a9154903d8
MD5 9941f2590334d7fc3aaf23f8bb522856
BLAKE2b-256 1a988b05c97bb007dddf6926814c7e2e42ee8fe671268aa5cc516b6a590dcec1

See more details on using hashes here.

File details

Details for the file chainopy-1.0.3-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: chainopy-1.0.3-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 255.4 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for chainopy-1.0.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 3ddd196c4ea5db9fc971ccc66e58c84bb98039d1f40e8d3202a593938af32bdb
MD5 15723a1692ba4f23c0d1257ee15812ab
BLAKE2b-256 4ecfc9d281cde8097ca37ceebe8b8d49e599ece81a8e7d8ac5e453b5a34064ab

See more details on using hashes here.

File details

Details for the file chainopy-1.0.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for chainopy-1.0.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2954c4ef23cad7556c50fa0f7b58b85d368a0a49688039b5766022bba4fc941e
MD5 18d27e791e658cfbcf4226bdffa3ff61
BLAKE2b-256 2d0f566f825b097bc026c18918c0fc3e91f08034f07d4c4f3b07715340c4eb02

See more details on using hashes here.

File details

Details for the file chainopy-1.0.3-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for chainopy-1.0.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 45f1a92056d8121b0b6c0ee6d364f39394f86200e91f5d2ec07dc0c54c371a5e
MD5 18a0d76e641f1efe7ad6088192c80f62
BLAKE2b-256 1981b7155593a3c25a91c1fe2ba2f79aba2bf142fa2ae276c3dd30522296e57d

See more details on using hashes here.

File details

Details for the file chainopy-1.0.3-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for chainopy-1.0.3-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 1b9a0573047d2bca683e16abda60dc51dbda0182da12d4794ff8bff66f5193c2
MD5 ac9f7f268a6954eacb7c7d591c14106f
BLAKE2b-256 e14ccc016c966dc8c9d2d64e88bb3cb9da90b487f5d4d56c1fa8895f86b15cbd

See more details on using hashes here.

File details

Details for the file chainopy-1.0.3-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: chainopy-1.0.3-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 255.1 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for chainopy-1.0.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 7064d1b0952232404adb00f79bd64247264dd1feb9a6d294a605277824e9d734
MD5 9601133c90b1d3cc793a13384e59d3f2
BLAKE2b-256 181a2dc4c5cc8ade08aad610cf9c6625a16eb7d1f4077701b7641c81003ad4fd

See more details on using hashes here.

File details

Details for the file chainopy-1.0.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for chainopy-1.0.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cdec9930fcf0691e8d201d20f4bc19b73ae838987437390c722ba2e4fffefec0
MD5 c055b97dd38388bf82b8d19bc524a502
BLAKE2b-256 46a4a50a926c8c7d8e70c2d66df86cc445d41aee2a02d79f72a11ce124cba6e4

See more details on using hashes here.

File details

Details for the file chainopy-1.0.3-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for chainopy-1.0.3-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e987d4718d0765986df6c6fb1ac8d326af34b4d595e72627bcd94d4d33dd4696
MD5 4ab5c97d782ee395568edcffa6064eb7
BLAKE2b-256 d52966097f14a2ce2499e1400c11213bb6621f7ef39c414ae3d8e61c88d29b0a

See more details on using hashes here.

File details

Details for the file chainopy-1.0.3-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for chainopy-1.0.3-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 75d5f36a3fad0e812bfec79553d192ebcadc5382ed65a752e720456d52d7e339
MD5 c4caff3a6f5ca5dd7c7b039c27341ca7
BLAKE2b-256 63ac0d9bb8c37d57a3fe7db3120527c6cec1e8e54b30851f2d86a148a73b7b79

See more details on using hashes here.

Supported by

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