Unified regime change detection via graph conservation ratio
Project description
conservation-regime
Unified regime change detection via graph conservation ratio.
One algorithm for any domain. The conservation ratio drops at regime transitions because the correlation/transition structure that was stable suddenly breaks.
Works on:
- Finance — market crises (conservation drops from ~0.44 to ~0.18)
- Climate — warming onset, heatwaves
- Social — bot injection, viral cascades
- Protein — folding transitions, mutations
- Sensors — failure detection in IoT networks
Install
pip install conservation-regime
Quick Start
import numpy as np
from regime_detection import ConservationRegimeDetector
detector = ConservationRegimeDetector(window=50, threshold_sigma=2.0)
# Any multivariate time series: (timesteps, variables)
data = np.random.randn(500, 10)
result = detector.detect(data)
# Regime changes
for rc in result.regime_changes:
print(f"Change at t={rc.time}, confidence={rc.confidence:.1f}σ, {rc.direction}")
# Full conservation series
print(f"Conservation: {result.conservation_series}")
How It Works
- Build graph: Sliding-window correlation matrix → adjacency graph
- Compute Laplacian: Normalized graph Laplacian captures connectivity
- Conservation ratio:
1 - (f^T L f) / 2— how smooth the signal is on the graph - Detect: Flag deviations beyond
threshold_sigmafrom baseline
During stable regimes, signals are smooth on the correlation graph → high conservation. At transitions, correlations break → conservation drops.
API
ConservationRegimeDetector
detector = ConservationRegimeDetector(
window=50, # baseline window
threshold_sigma=2.0, # detection sensitivity
min_separation=10, # min timesteps between detections
graph_type='correlation', # or 'transition'
method='conservation', # or 'spectral_gap'
)
detector.detect(data) → DetectionResult
regime_changes: List ofRegimeChange(time, confidence, direction, ...)conservation_series: Full conservation ratio time seriesanomaly_scores: Sigma deviations from baselinebaseline_mean,baseline_std: Baseline statistics
detector.detect_segments(data) → [(start, end, label), ...]
Returns labeled segments: 'stable' or 'transition'.
Examples
python examples/finance_example.py
python examples/climate_example.py
Testing
pip install -e ".[test]"
pytest tests/
Tests cover all 4 domains: finance, climate, social, protein.
License
MIT
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 Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file conservation_regime-0.1.0.tar.gz.
File metadata
- Download URL: conservation_regime-0.1.0.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3acfb37a056fd4da45c79b711ab9f83499614af3fd065ca4a3926bb6ffc200a
|
|
| MD5 |
54bd6bb910c5093e7facc48cd0c0d4be
|
|
| BLAKE2b-256 |
a91ff0feac6f022be1ec30c4a7052d609f67d45f3419ddac291b1d04416141cb
|
File details
Details for the file conservation_regime-0.1.0-py3-none-any.whl.
File metadata
- Download URL: conservation_regime-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6bee0f0de9ebd4d0d1c8abcc1a27c3a7a5dd047588b960971d617575f70d3665
|
|
| MD5 |
bfb27fd2cafa8c64d030d64524cb7c04
|
|
| BLAKE2b-256 |
84cbdb17fa92eedecc8c37bfa81d4085bd43d25d8470cd83b1861c2d5900f93d
|