Repository navigation
measure: distance to criticality (d2) for univariate time series - #443
Merged
Merged
Conversation
harness.measure.criticality measures the KL rate from a series' best-fit AR model to the nearest critical AR model of the same order (Sooter et al. 2026, PNAS, CC BY 4.0). d_beta uses an exact closed form, checked against numerical minimisation of the paper's integral; a formula without the differencing fails that check. Standard library only. Clean room: the authors' MATLAB toolkit is CC BY-NC 4.0 and was read for conventions only, never copied or run. sliding() detrends with the past only by default: a two-sided smoother let a leap fake an early warning in a learning-curve study. Docs: docs/features/criticality.md with the reproduced benchmarks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
My first commit rewrote every line ending in docs/features/README.md. This restores them and keeps only the one new entry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What it does
harness.measure.criticalitymeasures how close one time series runs to criticality: d2, the KL divergence rate in bits per step from the series' best-fit AR model to the nearest critical AR model of the same order. Method: Sooter, Fontenele, Barreiro, Ly, Hengen and Shew 2026, PNAS 123(44) e2526984123 (CC BY 4.0).d2(x, order, beta, fit, dt, err): Yule-Walker or least-squares fit, the paper's delta-method error bar, segmented series, ascopeon every result.d_beta: an exact closed form derived here (half the log of the order-(n - beta/2) prediction error variance of the differenced fitted process). It replaces the paper's numerical search.sliding,detrend,kendall_tau: time-resolved d2 and the early-warning trend.slidingdetrends with the past only by default, because a two-sided smoother let a leap fake an early warning in a learning-curve study.sims: AR, Hawkes and Langevin models with exact truths, for planted checks.Standard library only, under
harness/measure/besideharness/studyrun(#436, merged).Clean room
The authors' MATLAB toolkit is CC BY-NC 4.0. It was read to check conventions and was neither copied nor run. The code follows the paper's equations; the closed form is this package's own derivation.
Checks
tests/test_measure_criticality.py, 18 tests. The closed form is compared with a direct numerical minimisation of the paper's integral over the paper's own parameterisation (scipy, test-only; skipped where absent), and a formula without the differencing must fail that comparison. The causal-detrend test changes only future values and requires the past to stay identical.docs/features/criticality.md.🤖 Generated with Claude Code