feat(core): standardize covariance through Rust owner contract - #1722
feat(core): standardize covariance through Rust owner contract#1722seonghobae wants to merge 21 commits into
Conversation
📝 WalkthroughWalkthroughAdds a versioned ChangesCovariance Standardization
Estimated code review effort: 4 (Complex) | ~45 minutes Merge Risk: 🟡 Moderate · up to The new covariance standardization API can currently accept signed-zero asymmetric covariance cells and can produce an incorrect zero result for some valid extreme-valued inputs. These localized correctness issues should be fixed before the PR is merged. Sequence Diagram(s)sequenceDiagram
participant Caller
participant standardize_covariance_matrix
participant pairwise_covariance_is_admissible
Caller->>standardize_covariance_matrix: covariance and dimension
standardize_covariance_matrix->>pairwise_covariance_is_admissible: covariance and diagonal variances
pairwise_covariance_is_admissible-->>standardize_covariance_matrix: admissibility result
standardize_covariance_matrix-->>Caller: correlation matrix or typed error
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Take current protected main as the authoritative tree and preserve only #1722's four-file Rust covariance-standardization owner-contract delta. Keep the newly merged binary-response measurement contract and both histories without force push or destructive rebase.
|
Fresh exact-head landing evidence for unchanged
The aggregate-queue / CodeQL pre-materialization split is handed to canonical central owner |
|
Current-main reconciliation and release-traceability repair published.
The local environment has no The writer ref advanced with |
|
Fresh exact-head evidence update for |
Closes #1720.
Scope
Move reusable static covariance-to-correlation standardization into the canonical Rust numerical owner instead of allowing TEPP temporal/event code to own duplicate arithmetic.
mlsirm_core::covariance_standardizationas a domain-neutral Rust module;fast_mlsirm.covariance_standardization@1.0.0;D^{-1/2} Sigma D^{-1/2}contract without ctsem names, clocks, EventTime admission, or TEPP temporal-state semantics;f64, scale invariance, variable-order invariance, and typed numerical failure evidence.TEPP remains the owner of temporal/event semantics and may consume this only after an immutable released/versioned fast-mlsirm contract exists.
TDD / concurrent-writer convergence
Two same-issue implementations appeared from the same protected-main base. #1721 was closed unmerged only after its unique public-contract tests were preserved here; its undocumented
64*EPSILON/128*EPSILONadmission tolerances were intentionally not carried forward.69ae2c40c4a459f9e946f9dc0850019dde06b25aproved that heuristic approximate symmetry and silent acceptance/clamping of an actually invalid covariance were not acceptable.6ed74a7d37492976133bd5450efcf0c1d6ecaa80removed those heuristics and required exact mirrored binary64 inputs.13d2159ae15903b26b5f002c9caa583db5b110b1preserves the version identity, scalar scale invariance/fail-closed behavior, known matrix recovery, scale invariance, malformed-input admission, and invalid-covariance rejection that were unique to feat(core): own reusable covariance standardization #1721.82d4362082ac50e8987f96b731126b8e68896d8ereproduced an exactly admissible represented covariance for which sequential binary64 division rounds the raw result tonext_up(1.0).e7a9ebf1a35162af60b30c836965fa5fc0afa6c5replaced the floating threshold with an exact represented-input check ofc² <= v_i*v_jusing integer significands and powers of two. Only after that exact admission proof may boundary arithmetic be projected back to[-1,1]; genuinely invalid covariance still fails closed.a15fba524c74ac336827068afe610f3818d8a3aareproduced order-dependent intermediate underflow withf64::MAX, the smallest positive subnormal variance, and a nonzero admissible covariance.6bda7010f2c9796037544446e26b591f2d4980fedivides by the smaller marginal standard deviation first, making that correlation nonzero and permutation-invariant while retaining the exact pairwise admission proof.759c9dbddcf78f5dc4a6877df0ffa457c290eae3reproduced the remaining exact-binary64 symmetry defect: Rust numeric equality treated+0.0and-0.0as equal mirrored evidence even though the documented contract requires exact represented symmetry.73a930e76b084ea7eae08465bb0e72646fbdac6acompares mirrored cells byto_bits(), so signed-zero mismatch now fails closed without changing the already-reviewed pairwise-admission, roundoff, or scale-order behavior.(1/sqrt(v))*v*(1/sqrt(v))can round tonext_up(1.0)for finite positive inputs such asv=3. After finite-positive admission, the scalar contract now evaluatesv/v, preserving an arithmetic implementation while returning exact binary641.0for an admitted scalar variance instead of transferring matrix-rounding artifacts into the one-variable correlation contract.f70cb9beffdacca30ded281c804ed80504baa47eintegrates protectedmain@493326f2de49ea1704da0ded19868ed05d2fe00fas the second parent while preserving this PR's Rust owner-contract delta. Commit28b0305595107fd0ba21d7b27c1ac5db68ae8bf1adds the required unreleased changelog fragment. The writer ref advanced withforce=false; relative to protected main it isbehind_by=0and the effective scope is the original four files plusdocs/changelog.d/1722-covariance-standardization.md.All currently observed review threads on the predecessor source head were resolved after the corresponding source/test proof. No predecessor-head check, review, or artifact is transferred to the reconciled head.
Scientific / DDD boundary
Driver, Oud, & Voelkle (2017), DOI 10.18637/jss.v077.i05, supplies the motivating ctsem use case. The owner kernel implements the ordinary covariance-to-correlation identity and does not claim that pairwise admissibility proves full PSD. PSD, model identification, EventTime admission, and temporal state semantics remain separate caller/model invariants.
This PR adds Rust numerical ownership only. It adds no Python production arithmetic, provider/LLM path, temporal event ontology, database coupling, or cross-service SQL.
context-graph-contractsand EA Core remain read-only dependencies under their dedicated writer; no unreleased sibling PR is treated as a production contract.Landing
Current exact source head:
28b0305595107fd0ba21d7b27c1ac5db68ae8bf1.Protected base observed at this update:
main@493326f2de49ea1704da0ded19868ed05d2fe00f.Fresh exact-current GitHub Actions evidence and a qualifying independent approval are required after this reconciliation. The live repository default-branch ruleset requires one qualifying approval, dismisses stale reviews on push, requires review-thread resolution, requires approval from someone other than the last pusher, and requires extra approval for unattributed changes. Queued/pending/predecessor evidence is non-passing. No self-approval, routine admin bypass, force-push, destructive rebase, or gate weakening is authorized.