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
Metadata
Release files for conservation-regime 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| conservation_regime-0.1.0.tar.gz | 8.5 kB | Without provenance | Details for conservation_regime-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| conservation_regime-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for conservation_regime-0.1.0-py3-none-any.whl |
Total release size: 16.3 kB
Release files / conservation_regime-0.1.0.tar.gz
| Download URL | conservation_regime-0.1.0.tar.gz |
|---|---|
| Size | 8.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d3acfb37a056fd4da45c79b711ab9f83499614af3fd065ca4a3926bb6ffc200a
|
|
BLAKE2b-256 checksum How to use checksums |
a91ff0feac6f022be1ec30c4a7052d609f67d45f3419ddac291b1d04416141cb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.12
|
Release files / conservation_regime-0.1.0-py3-none-any.whl
| Download URL | conservation_regime-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6bee0f0de9ebd4d0d1c8abcc1a27c3a7a5dd047588b960971d617575f70d3665
|
|
BLAKE2b-256 checksum How to use checksums |
84cbdb17fa92eedecc8c37bfa81d4085bd43d25d8470cd83b1861c2d5900f93d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.12
|
Security for conservation-regime 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.