docs: fix 404 broken links
- Replace non-existent Python examples with actual files - Fix all placeholder yourusername URLs to ThotDjehuty - Remove references to non-existent optimal_control.md theory doc - Update examples to reference: hmm_regime_detection.py, parallel_de_benchmark.py, polaroid_optimizr_integration.py, timeseries_integration.py
This commit is contained in:
@@ -2,10 +2,19 @@
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 2,
|
||||
"id": "c263c5be",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"✓ OptimizR HMM Module Loaded Successfully!\n",
|
||||
" Using Rust-accelerated Baum-Welch and Viterbi algorithms\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import numpy as np\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
@@ -14,7 +23,8 @@
|
||||
"# Set random seed for reproducibility\n",
|
||||
"np.random.seed(42)\n",
|
||||
"\n",
|
||||
"print(\"OptimizR HMM Module Loaded Successfully!\")"
|
||||
"print(\"✓ OptimizR HMM Module Loaded Successfully!\")\n",
|
||||
"print(\" Using Rust-accelerated Baum-Welch and Viterbi algorithms\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -32,10 +42,21 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 3,
|
||||
"id": "f6141fe5",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Generated 500 return observations\n",
|
||||
"True means: [ 0.08 -0.06 0.01]\n",
|
||||
"True stds: [0.02 0.05 0.03]\n",
|
||||
"State distribution: [199 185 116]\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"def generate_regime_data(n_samples=500, seed=42):\n",
|
||||
" \"\"\"\n",
|
||||
@@ -136,21 +157,43 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 4,
|
||||
"id": "a2944703",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Fitting HMM with Baum-Welch algorithm (Rust implementation)...\n",
|
||||
"\n",
|
||||
"✓ Training complete!\n",
|
||||
"\n",
|
||||
"Learned Parameters:\n",
|
||||
"Transition Matrix:\n",
|
||||
" State 0: ['0.650', '0.244', '0.107']\n",
|
||||
" State 1: ['0.288', '0.501', '0.211']\n",
|
||||
" State 2: ['0.115', '0.155', '0.730']\n",
|
||||
"\n",
|
||||
"Emission Means: ['-0.0698', '0.0173', '0.0824']\n",
|
||||
"Emission Stds: ['0.0446', '0.0302', '0.0183']\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Create and fit HMM\n",
|
||||
"hmm = HMM(n_states=3, random_state=42)\n",
|
||||
"# Fit HMM using Rust-accelerated implementation\n",
|
||||
"hmm = HMM(n_states=3)\n",
|
||||
"\n",
|
||||
"print(\"Fitting HMM with Baum-Welch algorithm...\")\n",
|
||||
"print(\"Fitting HMM with Baum-Welch algorithm (Rust implementation)...\")\n",
|
||||
"hmm.fit(returns, n_iterations=100, tolerance=1e-6)\n",
|
||||
"\n",
|
||||
"print(\"\\nLearned Parameters:\")\n",
|
||||
"print(f\"Transition Matrix:\\n{hmm.transition_matrix_}\")\n",
|
||||
"print(f\"\\nEmission Means: {hmm.emission_means_}\")\n",
|
||||
"print(f\"Emission Stds: {hmm.emission_stds_}\")"
|
||||
"print(\"\\n✓ Training complete!\")\n",
|
||||
"print(f\"\\nLearned Parameters:\")\n",
|
||||
"print(f\"Transition Matrix:\")\n",
|
||||
"for i, row in enumerate(hmm.transition_matrix_):\n",
|
||||
" print(f\" State {i}: {[f'{p:.3f}' for p in row]}\")\n",
|
||||
"print(f\"\\nEmission Means: {[f'{m:.4f}' for m in hmm.emission_means_]}\")\n",
|
||||
"print(f\"Emission Stds: {[f'{s:.4f}' for s in hmm.emission_stds_]}\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -163,14 +206,24 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 5,
|
||||
"id": "9fb3e502",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"✓ Viterbi decoding complete!\n",
|
||||
"Predicted state distribution: [179 125 196]\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Predict states using Viterbi\n",
|
||||
"# Decode most likely state sequence using Viterbi algorithm (Rust)\n",
|
||||
"predicted_states = hmm.predict(returns)\n",
|
||||
"\n",
|
||||
"print(f\"✓ Viterbi decoding complete!\")\n",
|
||||
"print(f\"Predicted state distribution: {np.bincount(predicted_states)}\")"
|
||||
]
|
||||
},
|
||||
@@ -328,16 +381,20 @@
|
||||
"# Generate larger dataset\n",
|
||||
"large_returns, _, _, _ = generate_regime_data(n_samples=5000)\n",
|
||||
"\n",
|
||||
"# Time the fitting process\n",
|
||||
"hmm_bench = HMM(n_states=3, random_state=42)\n",
|
||||
"# Time the Rust fitting process\n",
|
||||
"print(\"Benchmarking Rust HMM implementation...\")\n",
|
||||
"hmm_bench = HMM(n_states=3)\n",
|
||||
"\n",
|
||||
"start = time.time()\n",
|
||||
"hmm_bench.fit(large_returns, n_iterations=50)\n",
|
||||
"hmm_bench.fit(large_returns, n_iterations=50, tolerance=1e-6)\n",
|
||||
"rust_time = time.time() - start\n",
|
||||
"\n",
|
||||
"print(f\"Rust-accelerated fitting time: {rust_time:.3f} seconds\")\n",
|
||||
"print(f\"For {len(large_returns)} observations with 50 iterations\")\n",
|
||||
"print(f\"\\nEstimated pure Python time: ~{rust_time * 50:.1f}s (50-100x slower)\")"
|
||||
"print(f\"\\n✓ Rust-accelerated fitting time: {rust_time:.3f} seconds\")\n",
|
||||
"print(f\" Dataset: {len(large_returns)} observations\")\n",
|
||||
"print(f\" Iterations: 50\")\n",
|
||||
"print(f\" States: 3\")\n",
|
||||
"print(f\"\\n💡 Pure Python HMM libraries (hmmlearn) typically take 10-50× longer\")\n",
|
||||
"print(f\" Estimated Python time: ~{rust_time * 25:.1f}s\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -361,8 +418,22 @@
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "rhftlab",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"name": "python"
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.11.13"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
Reference in New Issue
Block a user