A Python Library for Markov Chain based Stochastic Analysis!
Project description
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
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?
- Clone the project locally
- Install packages mentioned in
requirements.txt
andrequirements_test.txt
- Navigate to the directory containing
tests
folder - 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`.
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
How to Contribute?
- Fork the Project.
- Clone the Project locally.
- Create a New Branch to Contribute.
- run
pip install -r requirements.txt
andpip install -r requirements_test.txt
to download dependencies. - Do the changes of interest (Make sure to write docstrings).
- Write Unit Tests and test your implementation.
- Format the code using the Black Formatter.
- 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
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 Distributions
Built Distributions
Hashes for chainopy-1.0.2-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4aaaa92170a14fea8f64ad803b9c3f9de1ce5e46ce2945075f9f2cb8cfbea4bc |
|
MD5 | 7336af1b185d8382b72b3d0648eb1a7b |
|
BLAKE2b-256 | c697d85a7a09417b48a41ef78cfa358b9bbf63462a416914e921ec8c13c1c50d |
Hashes for chainopy-1.0.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a98cced89465d840176087257c9caf6f2e8cc583619c5f2bb33844ec48fa490 |
|
MD5 | 48fab673758395c636706a1d3a8c5a4c |
|
BLAKE2b-256 | 27ecb8d585ae549aa7408ea5bb643ee1fa0ce9f9d5aed2f4ce551634b33d934e |
Hashes for chainopy-1.0.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5029a4f0ed1c3069fc71cd971096da2ecc59615eb9bed2f72265d606a0c17275 |
|
MD5 | bf99d1f0627cad986f1bee25776968d6 |
|
BLAKE2b-256 | cc6fa27264877c5e768968e0f5448c1a61f35e86ce6a01dc1c11a2964bbacd42 |
Hashes for chainopy-1.0.2-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc54883bfb4e8c31f151550c014fa40890b1c2f2f9fb420e5375372b6f843bd4 |
|
MD5 | d5ea304c61e099cecef8162913588ef9 |
|
BLAKE2b-256 | b38582d482435587e9ad807f615d775261aa9b2b53f5321bcdb9dc601356bdcd |
Hashes for chainopy-1.0.2-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a147b43e0e12adb9389a20d1f7faee761ed4fe305b2f0491dd73cea3941722d |
|
MD5 | e151f5392d4c8ec3dfb620122e2d2ccb |
|
BLAKE2b-256 | 2b61fa8be3456a311ddaa23e22a6caf5aa46fd7caf9ec4c5240e9ecb2d1b4d5a |
Hashes for chainopy-1.0.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13d35aee266b049b5c2c55ea73264bacc7eed33e9fc963a3a817228cdc059b3a |
|
MD5 | e7e50bda32d41d4ed4b02b19dc8dc5db |
|
BLAKE2b-256 | cd01a440a43d475c3eace56940e9a778919050175dc709c42a2141715802c5ae |
Hashes for chainopy-1.0.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6234de1fa02bede9f3466b23dff4ea2326fb9f246a91a249ba5274bcef8daccd |
|
MD5 | d0aee232e491e184e715d81fca6871d2 |
|
BLAKE2b-256 | ad007cb044103c889893b7bae7643b33ba1f9b27fbd613ae870d0e53734c1263 |
Hashes for chainopy-1.0.2-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aee25ee073459b229a8e95bec2a31098364751b51365e1da8a03a01cb1fd0a9b |
|
MD5 | 96096c457d1076582125ed6cea9b2aa5 |
|
BLAKE2b-256 | 4fe3ba02d7a8d11850508865cb897f8f596e0f8e03002f51ba093ee9484ea48f |
Hashes for chainopy-1.0.2-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a09a81e871e4a09b5135259fa2273e22766c647e96ae54bf8758219fe915e4e |
|
MD5 | e86c016592721381edfa3c42a1641ecf |
|
BLAKE2b-256 | cc32f1790348830e80bb5ef21b50ca46d613e8ae43e1ac32dc4350fa4c43b477 |
Hashes for chainopy-1.0.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1ad2d280643e1de6b60b536f055922bc46bc7bfb68a5a3cea4f5a31abea0b93 |
|
MD5 | c796194819fdf4d1c814d30085a75aa3 |
|
BLAKE2b-256 | c75da3c561a22d900b63cffa5fe7df0616951815f59097d1761619af8002f34a |
Hashes for chainopy-1.0.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 517fb76fcbbda6d3303e3169c05ff57019d84b9c5f1cd29b6bdd6801254ddaba |
|
MD5 | d1de78e4cab45fb05ea3e793cb75a365 |
|
BLAKE2b-256 | c745ce30b96fb9d1d2145ec9d1437c316efd7a12cea06176e8b3bb414d430b7d |
Hashes for chainopy-1.0.2-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c31d9504960b9ee25dea2b3eb9288f3f8bc3a1544b4080e26faf3f9e1530effb |
|
MD5 | 61858468c31561b3e7239d7f1de2827f |
|
BLAKE2b-256 | ee09b361aeadc3553775ead8354a1d3c6acbf737c686ef1d4bb0a58fbe657bc0 |