Skip to content

Batch the exact subset refits in enumerate_game - #5

Merged
soodoku merged 1 commit into
mainfrom
projpred-ports
Nov 24, 2026
Merged

soodoku merged 1 commit into
mainfrom
projpred-ports

Conversation

@soodoku

@soodoku soodoku commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

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 to lstsq, 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.

  • Equivalence: every subset's coefficients and condition numbers match the old path to 5.9e-15 (n 2000, 16 players); exact Fraction oracle on a 4-player game; a test forces the fallback on two subsets and requires bitwise equality with lstsq. Planted bugs (dropped X'y change, wrong condition number, no fallback, old score not subtracted) are each caught.
  • Timing (interleaved medians, A/A 0.99–1.01): 119x at n 2000 / 16 players (8.96 s → 0.075 s); 12x at the repo's n 96 / 8 players; replicate_covariates.py end to end 1.7x.
  • Regenerated outputs move by at most 1.6e-14; macros.tex and tables byte-identical. One test's exact float equality became approx(abs=1e-13).

make ci-docker passes.

🤖 Generated with Claude Code

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>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T03:37:40.305546Z dad1b14 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@soodoku
soodoku merged commit 0eab043 into main Nov 24, 2026
2 checks passed
@soodoku
soodoku deleted the projpred-ports branch November 24, 2026 03:36

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread covariate_swaps.py
Comment on lines +228 to +229
gram = (gram0 + bits @ gram_changes).reshape(-1, p, p)
score = score0 + bits @ score_changes

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant