Add transfer entropy (KSG + binned) — first bivariate information-flow measure - #1
Merged
Conversation
Demonstrates entropy of a rolling correlation series as a correlation-regime stability gauge (idea from an r/dataisbeautiful thread). Ships alongside a rolling-std baseline so the example shows that an entropy signal must be checked against a trivial baseline before being trusted — on this synthetic data, std separates the regimes and entropy of the smooth correlation swing does not. - _synthetic.correlated_assets(): two return streams, stable shared-factor regime then a correlation breakdown - examples/correlation_stability.py: rolling corr -> permutation entropy vs rolling-std baseline, prints regime separation for both - tests: smoke test for the new example + a behavioral test asserting the generator's stable half is more correlated than its broken half Uses only the existing public API; no library changes. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Implements embed() in entroscope/_transfer_estimators.py — the single source of (y_future, y_past, x_past) aligned columns consumed by both the binned and KSG estimators. Verified in isolation against hand-computed values (Gate C). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Remove unused imports and split semicolon statements flagged by ruff in the transfer tests; drop a pre-existing unused pandas import in the correlation-stability example. Full suite: 132 passed. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…g perf Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
CI runs 'ruff format --check'; the new files weren't formatter-clean. Cosmetic only (import wrapping, comment spacing, line reflow), no logic change. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Merged
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.
Adds
entroscope.transfer, the library's first bivariate / information-flowmeasure: directional transfer entropy TE(X→Y) (Schreiber 2000) with two
estimators — Kraskov KSG k-NN (default, no binning) and a binned histogram
cross-check. Mirrors the house
compute / rolling / delta / plotcontract,takes two series, preserves the pandas index.
Born from an r/dataisbeautiful thread asking for transfer entropy + KSG.
Correctness — three independent authorities
The KSG estimator is validated against ground truth that shares no code with it:
The binned-vs-KSG cross-check is treated as a consistency check only (a shared
embedding bug would fool both), so correctness rests on A/B/C.
Notes
blowup flagged in the thread).
Tests
132 passed, ruff clean. New
tests/test_transfer.py(22 tests): the threegates + independence + directionality + cross-check + API/contract + guard.
Also includes the correlation-stability example (this branch is stacked on it).