markovgpu-rane 0.1.0__tar.gz → 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,16 +1,17 @@
1
1
  name: Publish to PyPI
2
2
 
3
3
  on:
4
- release:
5
- types: [published] # Runs ONLY when you click "Create Release" on GitHub
4
+ push:
5
+ tags:
6
+ - "v*"
6
7
 
7
8
  jobs:
8
9
  pypi-publish:
9
10
  name: Publish to PyPI
10
11
  runs-on: ubuntu-latest
11
- environment: pypi # Matches what you typed in PyPI website
12
+ environment: pypi # Matches what you typed in PyPI website
12
13
  permissions:
13
- id-token: write # REQUIRED for Trusted Publishing
14
+ id-token: write # REQUIRED for Trusted Publishing
14
15
 
15
16
  steps:
16
17
  - name: Checkout Code
@@ -24,4 +25,4 @@ jobs:
24
25
 
25
26
  - name: Publish to PyPI
26
27
  # This action uses the "Trusted" connection automatically
27
- uses: pypa/gh-action-pypi-publish@release/v1
28
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,205 @@
1
+ Metadata-Version: 2.4
2
+ Name: markovgpu-rane
3
+ Version: 0.3.0
4
+ Summary: High-performance Markov Chains & HMMs using OpenCL
5
+ Author-email: Sahil Rane <sahilrane249@gmail.com>
6
+ Classifier: Development Status :: 4 - Beta
7
+ Classifier: Intended Audience :: Developers
8
+ Classifier: Intended Audience :: Financial and Insurance Industry
9
+ Classifier: Intended Audience :: Science/Research
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
14
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
15
+ Requires-Python: >=3.12
16
+ Requires-Dist: matplotlib>=3.8.0
17
+ Requires-Dist: numpy>=1.26.0
18
+ Requires-Dist: pyopencl>=2024.1
19
+ Requires-Dist: scikit-learn>=1.8.0
20
+ Requires-Dist: scipy>=1.11.0
21
+ Requires-Dist: yfinance>=1.1.0
22
+ Description-Content-Type: text/markdown
23
+
24
+ <div align="center">
25
+
26
+ # ⚡ **MarkovGPU**
27
+
28
+ ### *Massive Scale Markov Models on Consumer Hardware*
29
+ <img width="1024" height="338" alt="image" src="https://github.com/user-attachments/assets/b57dab80-ba03-4d1d-bb4d-6390e3f63f52" />
30
+
31
+ > **Run million-state HMMs on your laptop GPU.**
32
+ > **No CUDA required • Hybrid CPU/GPU Backend • Production Ready**
33
+
34
+ [![PyPI version](https://img.shields.io/pypi/v/markovgpu-rane?style=flat-square&color=blue)](https://pypi.org/project/markovgpu-rane/)
35
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg?style=flat-square)](https://www.python.org/downloads/)
36
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](https://opensource.org/licenses/MIT)
37
+ [![Build Status](https://img.shields.io/github/actions/workflow/status/wizardwithcodehazard/markov/test.yml?style=flat-square&label=CI)](https://github.com/wizardwithcodehazard/markov/actions)
38
+
39
+ </div>
40
+
41
+ ---
42
+
43
+ ## 🌟 **The Engine for Stochastic Intelligence**
44
+
45
+ **MarkovGPU** is a high-performance probabilistic modeling library built for speed. It breaks the "NVIDIA Monopoly" by using **OpenCL** to accelerate **Hidden Markov Models (HMM)** and **Markov Chains** on *any* GPU—including AMD Radeon, Intel Arc, and Apple Silicon.
46
+
47
+ It doesn't just run; it *thinks*. The **Smart Hybrid Backend** automatically routes small tasks to the CPU (NumPy) and massive workloads to the GPU, giving you optimal performance at every scale.
48
+
49
+ ---
50
+
51
+ ## 🚀 **Core Superpowers**
52
+
53
+ | Feature | Magic Behind It |
54
+ |-------|----------------|
55
+ | ⚡ **Hardware Agnostic** | Built on **OpenCL** — runs on AMD, Intel, NVIDIA, and Apple M1/M2/M3 chips. |
56
+ | 🧠 **Smart Hybrid Backend** | Auto-detects problem size ($N$). Uses **NumPy** for speed on small data, **GPU** for massive throughput. |
57
+ | 📉 **Log-Space Stability** | Implements **Log-Sum-Exp** kernels to prevent underflow on long time-series (1M+ steps). |
58
+ | 🕵️ **Viterbi Decoding** | Finds the "Hidden Truth" in noisy data (e.g., market regimes, DNA sequences) in milliseconds. |
59
+ | 🎓 **Unsupervised Learning** | **Baum-Welch (EM)** algorithm trains models directly on the GPU, learning rules from raw data. |
60
+ | 📦 **Zero-Config Install** | `pip install markovgpu-rane`. No driver hell. No CUDA toolkit nightmares. |
61
+
62
+ ---
63
+
64
+ ## 🏗️ **Architecture: The Hybrid Pipeline**
65
+
66
+ ```mermaid
67
+ graph LR
68
+ A[User Code] -->|Request Fit/Predict| B{Smart Dispatcher}
69
+ B -->|Small N < 64| C["CPU Engine
70
+ (NumPy AVX2)"]
71
+ B -->|Large N >= 64| D["GPU Engine
72
+ (OpenCL Kernels)"]
73
+ C --> E[Result]
74
+ D --> E
75
+ subgraph GPU_Acceleration[GPU Acceleration]
76
+ D --> F[Matrix Multiply]
77
+ D --> G[Log-Sum-Exp]
78
+ D --> H[Parallel Viterbi]
79
+ end
80
+ ```
81
+
82
+ The library handles the hardware. You handle the math.
83
+
84
+ ## ⚡ Performance: Benchmarks
85
+
86
+ **Task**: Viterbi Decoding (64 Hidden States, 5000 Days of Data).
87
+ **Hardware**: AMD Ryzen 680M (Integrated Graphics).
88
+
89
+ | Engine | Execution Time | Speedup |
90
+ |--------|---------------|---------|
91
+ | 🐢 CPU (NumPy Optimized) | 5.06s | 1x |
92
+ | 🚀 GPU (MarkovGPU) | 0.82s | **6.2x** |
93
+
94
+ ---
95
+
96
+ ## ⚙️ Quick Start in 30 Seconds
97
+
98
+ ### Installation
99
+
100
+ ```bash
101
+ # Production
102
+ pip install markovgpu-rane
103
+
104
+ # Or for local development
105
+ uv pip install markovgpu-rane
106
+ ```
107
+
108
+ ### 1. Market Regime Detection (Viterbi)
109
+ Identify hidden "Bull" vs. "Bear" markets from noisy stock returns.
110
+
111
+ ```python
112
+ import numpy as np
113
+ from markovgpu import MarkovEngine
114
+
115
+ # 1. Setup the Rules (Transition Matrix)
116
+ # "Bull markets tend to stay Bullish (95%)"
117
+ trans_mat = np.array([[0.95, 0.05],
118
+ [0.10, 0.90]], dtype=np.float32)
119
+
120
+ # 2. Feed the Data (Observation Likelihoods)
121
+ # Shape: (1000 Days, 2 States)
122
+ obs_probs = np.random.rand(1000, 2).astype(np.float32)
123
+
124
+ # 3. Ignite the Engine
125
+ engine = MarkovEngine()
126
+ predicted_states = engine.decode_regime(trans_mat, obs_probs)
127
+
128
+ print("Detected Regimes:", predicted_states)
129
+ # Output: [0, 0, 0, 1, 1, 1, 0 ...]
130
+ ```
131
+
132
+ ### 2. Unsupervised Learning (Baum-Welch)
133
+ Train the AI to discover the hidden rules from raw data.
134
+
135
+ ```python
136
+ # The engine learns the Transition Matrix automatically
137
+ learned_matrix = engine.fit(
138
+ obs_probs,
139
+ n_states=2,
140
+ n_iters=100,
141
+ tolerance=1e-4
142
+ )
143
+
144
+ print("Discovered Rules:")
145
+ print(learned_matrix)
146
+ ```
147
+
148
+ ---
149
+
150
+ ## 🔬 Technical Brilliance
151
+
152
+ ### 1. The Log-Sum-Exp Kernel
153
+ Standard HMMs crash on long sequences because probabilities like $0.9^{1000}$ vanish to zero.
154
+ We solved this by rewriting the entire GPU kernel in Log-Space:
155
+
156
+ ```c
157
+ // Actual OpenCL Kernel snippet
158
+ float log_add(float log_a, float log_b) {
159
+ float max_val = max(log_a, log_b);
160
+ return max_val + log1p(exp(min(log_a, log_b) - max_val));
161
+ }
162
+ ```
163
+ → **Result**: You can process sequences of infinite length without numerical collapse.
164
+
165
+ ### 2. Parallel Viterbi
166
+ Instead of a slow Python loop, we launch $N$ threads (one per state) for every time step on the GPU, calculating the optimal path in parallel.
167
+
168
+ ---
169
+
170
+ ## 🛠️ Project Structure
171
+
172
+ ```
173
+ markovgpu/
174
+ ├── src/markovgpu/
175
+ │ ├── backend.py # The Brain (Smart Dispatcher)
176
+ │ ├── kernels.cl # The Muscle (OpenCL C Code)
177
+ │ └── __init__.py
178
+ ├── tests/ # Unit Tests
179
+ ├── pyproject.toml # Modern Packaging Config
180
+ └── README.md
181
+ ```
182
+
183
+ ## 🌱 Contributing
184
+
185
+ We welcome forks, issues, and PRs!
186
+
187
+ ```bash
188
+ git clone https://github.com/wizardwithcodehazard/markov.git
189
+ cd markov
190
+ uv sync --dev
191
+ uv run pytest
192
+ ```
193
+
194
+ ## 📄 License
195
+
196
+ **MIT License** — Free to use, modify, and ship in commercial products.
197
+
198
+ <div align="center">
199
+
200
+ MarkovGPU doesn’t just crunch numbers.
201
+ ### It discovers the hidden structure of reality.
202
+
203
+ Made with 🧡 by Sahil Rane
204
+
205
+ </div>
@@ -0,0 +1,182 @@
1
+ <div align="center">
2
+
3
+ # ⚡ **MarkovGPU**
4
+
5
+ ### *Massive Scale Markov Models on Consumer Hardware*
6
+ <img width="1024" height="338" alt="image" src="https://github.com/user-attachments/assets/b57dab80-ba03-4d1d-bb4d-6390e3f63f52" />
7
+
8
+ > **Run million-state HMMs on your laptop GPU.**
9
+ > **No CUDA required • Hybrid CPU/GPU Backend • Production Ready**
10
+
11
+ [![PyPI version](https://img.shields.io/pypi/v/markovgpu-rane?style=flat-square&color=blue)](https://pypi.org/project/markovgpu-rane/)
12
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg?style=flat-square)](https://www.python.org/downloads/)
13
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](https://opensource.org/licenses/MIT)
14
+ [![Build Status](https://img.shields.io/github/actions/workflow/status/wizardwithcodehazard/markov/test.yml?style=flat-square&label=CI)](https://github.com/wizardwithcodehazard/markov/actions)
15
+
16
+ </div>
17
+
18
+ ---
19
+
20
+ ## 🌟 **The Engine for Stochastic Intelligence**
21
+
22
+ **MarkovGPU** is a high-performance probabilistic modeling library built for speed. It breaks the "NVIDIA Monopoly" by using **OpenCL** to accelerate **Hidden Markov Models (HMM)** and **Markov Chains** on *any* GPU—including AMD Radeon, Intel Arc, and Apple Silicon.
23
+
24
+ It doesn't just run; it *thinks*. The **Smart Hybrid Backend** automatically routes small tasks to the CPU (NumPy) and massive workloads to the GPU, giving you optimal performance at every scale.
25
+
26
+ ---
27
+
28
+ ## 🚀 **Core Superpowers**
29
+
30
+ | Feature | Magic Behind It |
31
+ |-------|----------------|
32
+ | ⚡ **Hardware Agnostic** | Built on **OpenCL** — runs on AMD, Intel, NVIDIA, and Apple M1/M2/M3 chips. |
33
+ | 🧠 **Smart Hybrid Backend** | Auto-detects problem size ($N$). Uses **NumPy** for speed on small data, **GPU** for massive throughput. |
34
+ | 📉 **Log-Space Stability** | Implements **Log-Sum-Exp** kernels to prevent underflow on long time-series (1M+ steps). |
35
+ | 🕵️ **Viterbi Decoding** | Finds the "Hidden Truth" in noisy data (e.g., market regimes, DNA sequences) in milliseconds. |
36
+ | 🎓 **Unsupervised Learning** | **Baum-Welch (EM)** algorithm trains models directly on the GPU, learning rules from raw data. |
37
+ | 📦 **Zero-Config Install** | `pip install markovgpu-rane`. No driver hell. No CUDA toolkit nightmares. |
38
+
39
+ ---
40
+
41
+ ## 🏗️ **Architecture: The Hybrid Pipeline**
42
+
43
+ ```mermaid
44
+ graph LR
45
+ A[User Code] -->|Request Fit/Predict| B{Smart Dispatcher}
46
+ B -->|Small N < 64| C["CPU Engine
47
+ (NumPy AVX2)"]
48
+ B -->|Large N >= 64| D["GPU Engine
49
+ (OpenCL Kernels)"]
50
+ C --> E[Result]
51
+ D --> E
52
+ subgraph GPU_Acceleration[GPU Acceleration]
53
+ D --> F[Matrix Multiply]
54
+ D --> G[Log-Sum-Exp]
55
+ D --> H[Parallel Viterbi]
56
+ end
57
+ ```
58
+
59
+ The library handles the hardware. You handle the math.
60
+
61
+ ## ⚡ Performance: Benchmarks
62
+
63
+ **Task**: Viterbi Decoding (64 Hidden States, 5000 Days of Data).
64
+ **Hardware**: AMD Ryzen 680M (Integrated Graphics).
65
+
66
+ | Engine | Execution Time | Speedup |
67
+ |--------|---------------|---------|
68
+ | 🐢 CPU (NumPy Optimized) | 5.06s | 1x |
69
+ | 🚀 GPU (MarkovGPU) | 0.82s | **6.2x** |
70
+
71
+ ---
72
+
73
+ ## ⚙️ Quick Start in 30 Seconds
74
+
75
+ ### Installation
76
+
77
+ ```bash
78
+ # Production
79
+ pip install markovgpu-rane
80
+
81
+ # Or for local development
82
+ uv pip install markovgpu-rane
83
+ ```
84
+
85
+ ### 1. Market Regime Detection (Viterbi)
86
+ Identify hidden "Bull" vs. "Bear" markets from noisy stock returns.
87
+
88
+ ```python
89
+ import numpy as np
90
+ from markovgpu import MarkovEngine
91
+
92
+ # 1. Setup the Rules (Transition Matrix)
93
+ # "Bull markets tend to stay Bullish (95%)"
94
+ trans_mat = np.array([[0.95, 0.05],
95
+ [0.10, 0.90]], dtype=np.float32)
96
+
97
+ # 2. Feed the Data (Observation Likelihoods)
98
+ # Shape: (1000 Days, 2 States)
99
+ obs_probs = np.random.rand(1000, 2).astype(np.float32)
100
+
101
+ # 3. Ignite the Engine
102
+ engine = MarkovEngine()
103
+ predicted_states = engine.decode_regime(trans_mat, obs_probs)
104
+
105
+ print("Detected Regimes:", predicted_states)
106
+ # Output: [0, 0, 0, 1, 1, 1, 0 ...]
107
+ ```
108
+
109
+ ### 2. Unsupervised Learning (Baum-Welch)
110
+ Train the AI to discover the hidden rules from raw data.
111
+
112
+ ```python
113
+ # The engine learns the Transition Matrix automatically
114
+ learned_matrix = engine.fit(
115
+ obs_probs,
116
+ n_states=2,
117
+ n_iters=100,
118
+ tolerance=1e-4
119
+ )
120
+
121
+ print("Discovered Rules:")
122
+ print(learned_matrix)
123
+ ```
124
+
125
+ ---
126
+
127
+ ## 🔬 Technical Brilliance
128
+
129
+ ### 1. The Log-Sum-Exp Kernel
130
+ Standard HMMs crash on long sequences because probabilities like $0.9^{1000}$ vanish to zero.
131
+ We solved this by rewriting the entire GPU kernel in Log-Space:
132
+
133
+ ```c
134
+ // Actual OpenCL Kernel snippet
135
+ float log_add(float log_a, float log_b) {
136
+ float max_val = max(log_a, log_b);
137
+ return max_val + log1p(exp(min(log_a, log_b) - max_val));
138
+ }
139
+ ```
140
+ → **Result**: You can process sequences of infinite length without numerical collapse.
141
+
142
+ ### 2. Parallel Viterbi
143
+ Instead of a slow Python loop, we launch $N$ threads (one per state) for every time step on the GPU, calculating the optimal path in parallel.
144
+
145
+ ---
146
+
147
+ ## 🛠️ Project Structure
148
+
149
+ ```
150
+ markovgpu/
151
+ ├── src/markovgpu/
152
+ │ ├── backend.py # The Brain (Smart Dispatcher)
153
+ │ ├── kernels.cl # The Muscle (OpenCL C Code)
154
+ │ └── __init__.py
155
+ ├── tests/ # Unit Tests
156
+ ├── pyproject.toml # Modern Packaging Config
157
+ └── README.md
158
+ ```
159
+
160
+ ## 🌱 Contributing
161
+
162
+ We welcome forks, issues, and PRs!
163
+
164
+ ```bash
165
+ git clone https://github.com/wizardwithcodehazard/markov.git
166
+ cd markov
167
+ uv sync --dev
168
+ uv run pytest
169
+ ```
170
+
171
+ ## 📄 License
172
+
173
+ **MIT License** — Free to use, modify, and ship in commercial products.
174
+
175
+ <div align="center">
176
+
177
+ MarkovGPU doesn’t just crunch numbers.
178
+ ### It discovers the hidden structure of reality.
179
+
180
+ Made with 🧡 by Sahil Rane
181
+
182
+ </div>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "markovgpu-rane"
3
- version = "0.1.0"
3
+ version = "0.3.0"
4
4
  description = "High-performance Markov Chains & HMMs using OpenCL"
5
5
  readme = "README.md"
6
6
  authors = [
@@ -14,6 +14,8 @@ dependencies = [
14
14
  "pyopencl>=2024.1",
15
15
  "matplotlib>=3.8.0",
16
16
  "scipy>=1.11.0",
17
+ "yfinance>=1.1.0",
18
+ "scikit-learn>=1.8.0",
17
19
  ]
18
20
 
19
21
  # Metadata tags to help people find your library on PyPI
@@ -0,0 +1,5 @@
1
+ from .backend import MarkovEngine
2
+ from .sklearn import GpuHMM
3
+
4
+ __all__ = ["MarkovEngine", "GpuHMM"]
5
+ __version__ = "0.2.0"