Repository navigation
Batch the exact subset refits in enumerate_game - #5
Conversation
Each subset's X'X and X'y is the proxy's plus the changes of its players, so all 2**m systems are assembled with one product against the mask bits and solved by a batched np.linalg.solve. Subsets whose design condition exceeds 1e3, and rank-deficient ones, still go through lstsq: the normal equations square the condition number, and against exact rational least squares their error was 3e-10 at cond 2e3 and 4e-6 at cond 2e5. n=2000, 16 players: 8.96 s -> 0.075 s median (119x, A/A 0.99). n=96, 8 players (committed benchmark): 5.6 ms -> 0.46 ms. Coefficients match the per-subset lstsq refits to 5.9e-15. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dad1b148da
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| gram = (gram0 + bits @ gram_changes).reshape(-1, p, p) | ||
| score = score0 + bits @ score_changes |
There was a problem hiding this comment.
Account for cancellation when assembling corrected Gram matrices
When a correction removes a large proxy covariate, subtracting its Gram contribution can destroy the remaining rows' information even though the corrected design is well conditioned. For example, use an intercept and proxy column [2**28, 3, -3, 3], correct row 0 to zero, and set the outcome to [0, 3, -3, 3]. The corrected target coefficient is exactly 1, but the assembled Gram diagonal rounds to a multiple of 16 instead of 27; a diagonal of 32 produces a coefficient of approximately 0.832. Its computed condition number is only approximately 2.96, so the existing fallback accepts this corrupted system. Detect cancellation relative to the original contributions and refit affected subsets explicitly rather than relying solely on the assembled matrix's condition number.
Useful? React with 👍 / 👎.
Each subset's X'X and X'y is the proxy's plus the per-player changes, so all 2^m subsets are assembled with one matrix product (chunks of 4,096) and solved with one batched
np.linalg.solve. Subsets with cond(X) > 1e3 or rank deficiency fall back tolstsq, which keeps the existing rank-deficiency error. The cutoff is 1e3, not 1e6: through X'X the error vs exact rational least squares is 2.7e-10 at cond 2e3 but 2.7e-4 at 2e6.Fractionoracle on a 4-player game; a test forces the fallback on two subsets and requires bitwise equality withlstsq. Planted bugs (dropped X'y change, wrong condition number, no fallback, old score not subtracted) are each caught.replicate_covariates.pyend to end 1.7x.macros.texand tables byte-identical. One test's exact float equality becameapprox(abs=1e-13).make ci-dockerpasses.🤖 Generated with Claude Code