Add BlockCovariance: memory-efficient block-diagonal online covariance (O(p·b) state) - #49
Merged
Merged
Conversation
…e (O(p*b) state) Tracks only the within-block (contiguous n_blocks) EWA covariances, so the running state and per-step cost scale with block size b, not p: ~O(p*b) vs O(p^2). Cross-block entries are zero -- the memory-light gamma=0 (block-diagonal / composite) member of the Schur family, for high p where the dense p x p covariance is costly to hold while streaming. Block-diagonal of PD blocks is PD, so no global O(p^3) eigen-projection. Explicit JSON get_state/set_state (flat per-block lists). Registered; parametrized conformance suite + dedicated tests (block-diagonal structure, PD, sub-quadratic state, JSON roundtrip, blocks match within-block EWA). Verified locally: ruff, mypy, pytest all pass. Refs #47.
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.
Summary
Adds
BlockCovariance— a memory-efficient block-diagonal online covariance addressing the streaming-memory angle of #47.SchurCovariance(gamma=0)produces a block-diagonal estimate but keeps the fullp×pEWA covariance in state and zeroes cross-block entries only at read time.BlockCovarianceinstead tracks only the within-block (contiguousn_blocks) recency-weighted covariances:O(p·b)(block sizeb), notO(p²)— it never allocates the dense matrix while streaming; it densifies only on acovariance_request.O(p³)eigen-projection; the precision is block-wise too.gamma=0(block-diagonal / composite) member of the Schur family — useful at highpwhere the dense covariance is expensive or impossible to hold (the regime Block-streaming Schur pseudo-likelihood: avoid materializing the full p×p covariance #47 targets), and a natural generalization ofDiagonalCovariance(theb=1case).Tests
all_estimators()conformance suite (contract,fit == stream, state roundtrip, real-JSON state).tests/test_block_covariance.py: block-diagonal structure (off-block entries exactly zero), positive-definiteness, sub-quadratic state (sum of block elements< p²), JSON-serializable state that roundtrips, and blocks matching a within-blockEwaCovariance.ruff,mypy, and fullpytestpass locally.Notes
This is the block-diagonal case of #47. A general bounded-conditioning (Vecchia-style) streaming variant that keeps limited cross-block coupling without the dense matrix is a natural follow-up. Complementary to #48 (
SchurLedoitWolfCovariance, the analytic cross-block damping).