perf(had): hoist Stute bootstrap loop invariants — bit-identical, ~2x#641
Open
igerber wants to merge 2 commits into
Open
perf(had): hoist Stute bootstrap loop invariants — bit-identical, ~2x#641igerber wants to merge 2 commits into
igerber wants to merge 2 commits into
Conversation
PR Review ReportOverall Assessment✅ Looks good — no unmitigated P0/P1 findings. Executive Summary
Methodology
Code Quality
Performance
Maintainability
Tech Debt
Security
Documentation/Tests
|
c90fb4d to
a234af1
Compare
|
🔁 AI review rerun (requested by @igerber) Head SHA: Overall Assessment✅ Looks good — no unmitigated P0/P1 findings. Executive Summary
Methodology
Code Quality
Performance
Maintainability
Tech Debt
Security
Documentation/Tests
|
4dfc90f to
a6c74b4
Compare
|
🔁 AI review rerun (requested by @igerber) Head SHA: Overall Assessment✅ Looks good — no unmitigated P0/P1 findings. Executive Summary
Methodology
Code Quality
Performance
Maintainability
Tech Debt
Security
Documentation/Tests
|
a6c74b4 to
772f0a0
Compare
|
🔁 AI review rerun (requested by @igerber) Head SHA: Overall Assessment✅ Looks good — no unmitigated P0/P1 findings. Executive Summary
Methodology
Code Quality
Performance
Maintainability
Tech Debt
Security
Documentation/Tests
|
…ws, precomputed d-moments + tie blocks (bit-identical, ~2x) The stute_test / stute_joint_pretest unweighted Appendix-D refit loops re-derived loop invariants every replicate: a fresh rng.choice per eta draw, d-moments inside _fit_ols_intercept_slope, and np.unique tie blocks inside _cvm_statistic. Draws are now batched through memory-bounded rng.choice calls (numpy fills C-order, so the variate stream — and every draw — is identical to per-iteration draws; peak memory stays bounded via _iter_mammen_rows instead of a full (B,G) matrix), and the helpers accept precomputed d_moments / tie_blocks (deterministic functions of d computed with identical expressions). bootstrap_S, cvm_stat and p_value are bit-identical to the literal per-iteration form — locked by a frozen byte-copy parity test, per-helper equality tests, and a joint-loop per-iteration-draw invariance test. Measured 2.5x/2.1x/1.9x at G=1e3/1e4/1e5 (B=999). REGISTRY Phase-3 Stute notes updated (the once-sketched O(G^2) M-matrix form was NOT shipped — it would not scale in memory); the large-G advisory cites post-hoist timings. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…en stream (review P3) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
772f0a0 to
999f0f3
Compare
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
stute_test/stute_joint_pretestunweighted Appendix-D bootstrap loops re-derived loop invariants every replicate: a freshrng.choiceper Mammen draw, the d-moments inside_fit_ols_intercept_slope, and thenp.uniquetie-block indices inside_cvm_statistic.rng.choicecalls (_iter_mammen_rows; numpy fills C-order, so the variate stream — and therefore every draw — is identical to per-iteration draws, and peak memory stays bounded instead of a full(B, G)matrix at large G), and the helpers accept precomputedd_moments/tie_blocks(deterministic functions ofdcomputed with identical expressions — tie-safety logic stays single-source).bootstrap_S,cvm_stat,p_valueexactly equal the literal per-iteration form. Locked byTestStuteBootstrapHoistedInvariants: a frozen byte-copy of the pre-hoist loop (end-to-end p-value equality on a seed×DGP grid with tie blocks), per-helper equality tests, RNG stream-identity (sequential vs batched vs chunked), and a joint-loop invariance test that monkeypatches back per-iteration draws.M = I − X(X'X)⁻¹X'materialization — that form is O(G²) memory and would not scale; REGISTRY's Phase-3 Stute notes updated accordingly (the shipped change is loop-invariant hoisting, exactly identical rather than "functionally identical"). Large-G advisory now cites measured post-hoist timings.Methodology references (required if estimator / math changes)
Validation
tests/test_had_pretests.py::TestStuteBootstrapHoistedInvariants(5 tests: stream identity incl. chunked batches, d-moments equality, tie-blocks equality, frozen literal-loop p-value parity, joint-loop per-iteration-draw invariance).tests/test_had_pretests.pypasses (250); the pre-existing w=ones(G) weighted-reduction bit-exact lock and survey-path tests are unaffected (survey path untouched).Security / privacy
Generated with Claude Code