Skip to main content

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.

Metadata

Release files for chainopy 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for chainopy 1.0.3
File
chainopy-1.0.3-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
chainopy-1.0.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details
chainopy-1.0.3-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details
chainopy-1.0.3-cp312-cp312-macosx_10_9_x86_64.whl CPython 3.12 CPython 3.12 macOS 10.9+ x86-64 Details
chainopy-1.0.3-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
chainopy-1.0.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details
chainopy-1.0.3-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details
chainopy-1.0.3-cp311-cp311-macosx_10_9_x86_64.whl CPython 3.11 CPython 3.11 macOS 10.9+ x86-64 Details
chainopy-1.0.3-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
chainopy-1.0.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details
chainopy-1.0.3-cp310-cp310-macosx_11_0_arm64.whl CPython 3.10 CPython 3.10 macOS 11.0+ ARM64 Details
chainopy-1.0.3-cp310-cp310-macosx_10_9_x86_64.whl CPython 3.10 CPython 3.10 macOS 10.9+ x86-64 Details

Total release size: 6.5 MB

Release files / chainopy-1.0.3-cp312-cp312-win_amd64.whl

Download URL chainopy-1.0.3-cp312-cp312-win_amd64.whl
Size 257.7 kB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
869610e9e238b4c7ebe0cdbecbb9f134830d2553ad7e153672ccfe04134598ba
BLAKE2b-256 checksum
How to use checksums
1edcdf6d96efa2f5bdaf4763d6ae94d3f0be916bef5514bb464e2f04a08e393f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Release files / chainopy-1.0.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL chainopy-1.0.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.4 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
27656b93599d50f9aebc9495516a3a32e3a0db9f04679d0bcd0ea80e2c039941
BLAKE2b-256 checksum
How to use checksums
5134e9891a428fdacc171b6984c074131ec5d7d57b2a1a6678ddfefa49b9b4d8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Release files / chainopy-1.0.3-cp312-cp312-macosx_11_0_arm64.whl

Download URL chainopy-1.0.3-cp312-cp312-macosx_11_0_arm64.whl
Size 256.3 kB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
44f476d75a45e7fda8812bae370f6680f5b722fcf693592f5886445f3e491478
BLAKE2b-256 checksum
How to use checksums
81068a51089b517cd991c2977460980949609c995e53406edc113b55f6ef24e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Release files / chainopy-1.0.3-cp312-cp312-macosx_10_9_x86_64.whl

Download URL chainopy-1.0.3-cp312-cp312-macosx_10_9_x86_64.whl
Size 268.8 kB
Tags CPython 3.12 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
b9c41ee4c622129fede8cb0b480ddc9cd7040e0e8d367cb9e43534a9154903d8
BLAKE2b-256 checksum
How to use checksums
1a988b05c97bb007dddf6926814c7e2e42ee8fe671268aa5cc516b6a590dcec1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Release files / chainopy-1.0.3-cp311-cp311-win_amd64.whl

Download URL chainopy-1.0.3-cp311-cp311-win_amd64.whl
Size 255.4 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
3ddd196c4ea5db9fc971ccc66e58c84bb98039d1f40e8d3202a593938af32bdb
BLAKE2b-256 checksum
How to use checksums
4ecfc9d281cde8097ca37ceebe8b8d49e599ece81a8e7d8ac5e453b5a34064ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Release files / chainopy-1.0.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL chainopy-1.0.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.4 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
2954c4ef23cad7556c50fa0f7b58b85d368a0a49688039b5766022bba4fc941e
BLAKE2b-256 checksum
How to use checksums
2d0f566f825b097bc026c18918c0fc3e91f08034f07d4c4f3b07715340c4eb02
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Release files / chainopy-1.0.3-cp311-cp311-macosx_11_0_arm64.whl

Download URL chainopy-1.0.3-cp311-cp311-macosx_11_0_arm64.whl
Size 255.8 kB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
45f1a92056d8121b0b6c0ee6d364f39394f86200e91f5d2ec07dc0c54c371a5e
BLAKE2b-256 checksum
How to use checksums
1981b7155593a3c25a91c1fe2ba2f79aba2bf142fa2ae276c3dd30522296e57d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Release files / chainopy-1.0.3-cp311-cp311-macosx_10_9_x86_64.whl

Download URL chainopy-1.0.3-cp311-cp311-macosx_10_9_x86_64.whl
Size 267.2 kB
Tags CPython 3.11 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
1b9a0573047d2bca683e16abda60dc51dbda0182da12d4794ff8bff66f5193c2
BLAKE2b-256 checksum
How to use checksums
e14ccc016c966dc8c9d2d64e88bb3cb9da90b487f5d4d56c1fa8895f86b15cbd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Release files / chainopy-1.0.3-cp310-cp310-win_amd64.whl

Download URL chainopy-1.0.3-cp310-cp310-win_amd64.whl
Size 255.1 kB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
7064d1b0952232404adb00f79bd64247264dd1feb9a6d294a605277824e9d734
BLAKE2b-256 checksum
How to use checksums
181a2dc4c5cc8ade08aad610cf9c6625a16eb7d1f4077701b7641c81003ad4fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Release files / chainopy-1.0.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL chainopy-1.0.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.3 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
cdec9930fcf0691e8d201d20f4bc19b73ae838987437390c722ba2e4fffefec0
BLAKE2b-256 checksum
How to use checksums
46a4a50a926c8c7d8e70c2d66df86cc445d41aee2a02d79f72a11ce124cba6e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Release files / chainopy-1.0.3-cp310-cp310-macosx_11_0_arm64.whl

Download URL chainopy-1.0.3-cp310-cp310-macosx_11_0_arm64.whl
Size 256.4 kB
Tags CPython 3.10 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
e987d4718d0765986df6c6fb1ac8d326af34b4d595e72627bcd94d4d33dd4696
BLAKE2b-256 checksum
How to use checksums
d52966097f14a2ce2499e1400c11213bb6621f7ef39c414ae3d8e61c88d29b0a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Release files / chainopy-1.0.3-cp310-cp310-macosx_10_9_x86_64.whl

Download URL chainopy-1.0.3-cp310-cp310-macosx_10_9_x86_64.whl
Size 267.5 kB
Tags CPython 3.10 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
75d5f36a3fad0e812bfec79553d192ebcadc5382ed65a752e720456d52d7e339
BLAKE2b-256 checksum
How to use checksums
63ac0d9bb8c37d57a3fe7db3120527c6cec1e8e54b30851f2d86a148a73b7b79
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Release history Release notifications | RSS feed

This release

1.0.3 This release

12 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page