Repository navigation
feat(rung4): every memory row carries a weight; the refit and the oracle weigh a row by t × weight, and weight one is today's run bit for bit - #91
Conversation
…every opponent hand and every physical entry of its key, and the walk's arrival rate, from the rules alone PR 1 of the targeted-sampling plan. `minidrawmaha/solver/exact_target.py` computes, for any table row, the regret the walk's samples there estimate (the mean over the opponent's hands of u − ⟨σ, u⟩, weighted by the deck and the opponent's own play, normalised by the arrival) and the probability one walk visits the row. It re-derives the public tree, key maps, draw maps and showdown from rules/ and never imports the grader, which grades what this will feed. Measured: a round-2 row costs 0.8 ms, the arrival alone 0.3 ms; a draw row 45–85 ms and a round-1 row 0.2–0.6 s, because the value below expands over the traverser's own replacements and the second board card. Tests: the back-solved reach equals the grader's carried vector on every board of every point (1e-10, full and restricted deals); arrival at a seat's first decision is the grader's frequency and sums to one; regret and arrival equal a world-by-world walk through MiniState on a small restricted game (1e-9) and the mean and visit count of 6,000 Collector walks row by row within 4 s.e. and pooled; the module's import block holds no grader.
…, 5,190 vectors, re-derived by a test; the sampled tests select rows by expected count, so a row cannot enter because it fluctuated high Review follow-ups on #89. The docstring counted the memo's level-1 points alone (29) where the chance nodes on the paths are memoised too (66 in all); the test now walks the ancestor closure and pins 66, 20 and 5,190. `reach()` hands out a copy. The pooled z² windows are a 4-sd band on the chi-square mean, √(2/n), instead of fixed numbers. The gated 200,000-walk test kept rows by observed count ≥ 100, which let seat 1's draw rows in only when they had fluctuated high (mean z +1.8 on two seeds); rows are now kept by expected count ≥ 80 against an observed cutoff of 40, and both seats read mean z within 0.01 of zero over thousands of rows. The module docstring names the double-visit caveat and no longer points at a plan outside the repo without saying where it is.
… the mean of z², and cap a single row at six standard errors — the deal alone dealt one picture 292 times against 220 at seed 12 The pooled mean is the sharp bias test (a tenth of a standard error in every row is caught at 1,600 rows); the per-row cap is loose because of about 3,000 rows one passes 5 in a run out of a thousand, and the deal itself did it at seed 12 in a count that involves nothing of this module. Run with MINIDRAWMAHA_FULL_TARGET=1: both seats pass.
…e band's assumptions written beside it — the "caught at 1,600 rows" line was a half-truth; the band is reached there and reliable at about 3,000
…9 at n = 10, biting from n ≈ 45 — and the arrival seeds checked named
…width drops under 1, not from 45
…caller says otherwise; a file without the column loads as ones PR 2 of the targeted-sampling plan, first of three commits. The reservoir's row grows from (row, t, target) to (row, t, target, weight): 24 to 28 bytes, a 50M-row memory 1.2 to 1.4 GB. The weight rides its row's slot through Algorithm R's eviction, save and load; merge without a weight stamps ones; a file with no weight key is from before the column and loads with ones. Refused by name: a negative, non-finite, mis-shaped weight on merge, and a weight array of the wrong length or dtype on load. The learner seam still takes three arrays, so tests/deepcfr/test_train.py is red until the next commit, which threads the column through it.
…y's loss bit for bit and a row of weight zero is inert Second of PR 2's three commits. _weighted_loss scales each row's squared error by (t · w) / mean(t · w): with w ≡ 1 that is t / mean(t) in the same bits, since t · 1.0 is t in float32. fit_from_scratch and batch_loss take the weight as a fourth positional array, None meaning ones, and refuse a weight that is not 1-D, not the memory's length, non-finite, negative, or all zero (nothing to fit, as an empty memory is). A batch whose every row weighs 0 divides by a clamped mean and has loss 0, not NaN. fit_policy takes the column positionally so the policy memory's contents() unpack straight in; its weights are all one.
…cle banks Σ t′ · w · r in LCFR's order, so weight one keeps the pin bit for bit Last of PR 2's three commits. Learner.fit takes the memory's four arrays, the weight positional with no default so no learner can drop it by accident; step is unchanged, the four-tuple from contents() flowing through. NetLearner hands the weight to fit_from_scratch and the held batch's loss, after the pot scaling and the regret rules act on the target: the weight says how loudly a row counts, never what it says. The oracle multiplies each sample by its weight in float64 before the per-t′ np.add.at sum, where × 1.0 is exact, so the LCFR pin passes unchanged; a weight of 2 banks what the row offered twice would, a weight of 0 nothing. Oracle model files carry the weight and load as ones without it.
… refused by name — the ones default ran ahead of the checks it relied on; and the weight-one pin is against the old loss formula, not the code itself From the fresh-context review before the push. Reservoir.load sized the default weight from a negative `offered` before refusing it; merge and fit_from_scratch sized it from a 0-d rows before the 1-D check; a 0-d weight on load indexed its own empty shape. Each now fails on the by-name ValueError the old code gave. test_weight_one_is_the_unweighted_fit_bit_for_bit compared the fit to itself (both paths built the same ones); it now restates the pre-column loss, t / mean(t) over the legal squared error, and pins batch_loss at weight one and by default against it to the bit, then the whole fit.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Claude finished @AlecROndo's task in 39s —— View job Review of PR #91 (weight column for rung 4)I read the diffs of 1. Docstring claim is overstated: "a row of weight 2 banks what the same row offered twice would"
2.
3. Possible float32 overflow in
4. Weight-zero rows in the held batch
5. The oracle's
6. Scope
7. Small things
Tests
|
…ight for overflow, on merge, on load and in the fit — a float64 weight past float32's range passed the finite check and was stored as inf; and the oracle's "offered twice" claim holds to the bit only when the two are alone at the column - `_validate_offer` casts to float32 first and checks finite, non-negative and t × weight finite after; a bool or non-numeric weight is refused by name. - `Reservoir.load` refuses a weight that is NaN, negative or overflows t × weight, naming the file, as `merge` never writes one. - `fit_from_scratch` refuses a t × weight that overflows float32, the loss's scale. - `OracleLearner` docstring: weight 2 equals the row offered twice exactly only when nothing else sits at the column in that t′; otherwise up to rounding, since `np.add.at` sums one at a time. A new test pins two rows of widths 2 and 3 with weights 3 and 2 against the rows offered three and two times, so a weight landing on a neighbour's columns would show. - `batch_loss` says why it defaults the weight while `Learner.fit` does not; `NetLearner.fit` notes the held loss is a log line nothing decides on.
|
Claude finished @AlecROndo's task in 20s —— View job Re-review of PR #91 after the latest push (
|
|
Round 1 of the review, dispositioned in 11b6e7b.
Tests at 11b6e7b: |
|
Round 2, against 11b6e7b. No code changed; every open item is already in that commit or dismissed with the reason below.
|
…high-noise row — board card, both seats' replacements, the opponent's actions and range — each unbiased against the exact sum, which stays as EXACT, with the arrival always exact and one stream per (seed, t, seat, row) exact_target.py becomes boost_target.py (ExactTargets → BoostTargets). targets() takes a required Sampling; EXACT reproduces the previous output bit for bit.
… one branch at a time, averaged, is the exact sum to 1e-10 — and the range draw is tested where a key's two entries face different ranges; the stream's tail is two words, not one, and seed and t take any integer
|
Claude finished @AlecROndo's task in 20s —— View job Re-review of PR #91 at
|
… — None, or a chance count at its fan — so it needs no seed and refuses extra play-outs; counts take any integer type, as seed and t do; the stream comment says when six words hold
|
Claude finished @AlecROndo's task in 29s —— View job Re-review of PR #91 at
|
…that draws nothing
|
Claude finished @AlecROndo's task in 24s —— View job Re-review of PR #91 at
|
|
Checked: the refusal tests match on |
|
Claude finished @AlecROndo's task in 12s —— View job Re-review of PR #91 at
|
PR 2 of the targeted-sampling plan for rung 4, built on PR 1's head (#89). Every memory row now carries a
weight; the refit's loss and the oracle weigh a row by t × weight. Nothing yet offers a weight other than one, so a run is bit for bit what it was: the oracle pin passes unchanged, and the net's fit at weight one is the unweighted fit's weights exactly.What it is
The targeted-sampling plan's boost stage (PR 4) will add, at a chosen infoset, one row holding the EXACT regret under the current strategy, weighted (1 − α) · K · arrival — the number of sampled rows the walk would have put there in expectation — and turn the walk's own rows there down to α. This PR is the column that carries that factor, and the two places that read it:
reservoir.py— the row is(row, t, target, weight), 28 bytes (was 24); a 50M-row memory is 1.4 GB (was 1.2). The weight rides its row's slot through Algorithm R's eviction, save and load.mergewithout a weight stamps ones; a file with noweightkey is from before the column and loads with ones, so a saved run resumes as the run it was. Refused by name: a negative, non-finite (checked after the cast to float32, so a float64 past its range is caught as the inf it became), mis-shaped or non-numeric weight onmerge, and one whose t × weight overflows float32 at the stamp's t; onload, aweightarray of the wrong length or dtype, or holding a valuemergewould have refused.fit.py—_weighted_lossscales each row's squared error by (t · w) / mean(t · w). With w ≡ 1 that is t / mean(t) in the same bits (t · 1.0 is t in float32). A batch whose every row weighs 0 divides by a clamped mean and has loss 0, not NaN.fit_from_scratchandbatch_losstake the weight as a fourth positional array, None meaning ones, and refuse a weight that is not 1-D, not the memory's length, non-finite, negative, overflowing t × weight in float32, or all zero (nothing to fit, as an empty memory is).train.py—Learner.fit(rows, t, targets, weight, *, seed), the weight positional with no default so no learner can drop it by accident;stepis unchanged, the four-tuple fromcontents()flowing through.NetLearnerhands the weight to the fit and the held batch's loss afterpot_scaledandrule_targetsact on the target: the weight says how loudly a row counts, never what it says.OracleLearner.writemultiplies each sample by its weight in float64 before LCFR's per-t′np.add.atsum, where × 1.0 is exact.policy.py—fit_policytakes the column positionally sofit_policy(*memory.contents(), …)in the grader keeps working; policy rows always weigh one.No new
DeepConfigfield, so nothing forADDED_LATERorSAMPLE_FIELDS; the resume state's file set is unchanged.Tests
test_the_oracle_loop_is_lcfr_bit_for_bitpasses unchanged.reservoir: a weight rides its row through eviction and the later-offer-wins tie-break; rows offered without a weight weigh one; bad weights refused on merge; a file written before the column loads with ones and keeps filling; a weight of the wrong length or dtype is refused naming the file.
fit (torch): weight one is the unweighted fit bit for bit (
torch.equalon every parameter); a row of weight 0 is inert; the loss weighs a row by t × weight (the weighted least-squares answer moves from +0.5 to 0 when weights (1, 3) cancel t = (3, 1)); a batch of weightless rows has loss 0 and finite gradients; bad weights refused by name.train: a weight of 2 banks what the row offered twice would (to the bit when alone at the column; otherwise up to rounding, as the docstring says), and a weight of 0 nothing (
array_equalon the whole table); a 2-wide and a 3-wide row with weights 3 and 2 in one model bank what the rows offered three and two times would, so a weight on a neighbour's columns would show; oracle models round-trip the weight and load as ones without it;NetLearnerhands the weight through untouched under pot scaling and under DCFR.The weight-one pin is against the pre-column loss restated inline in the test (t / mean(t) over the legal squared error), to the bit, then through the whole fit.
A scalar
rowsorweightand a corrupt pre-column file are refused by name (a fresh-context review found the ones default running ahead of the checks it relied on; fixed in the last commit).uv run pytestwith torch installed: 1,747 passed, 17 skipped. Without torch: the rung-4 directory 156 passed, 6 skipped (the torch tests skip).Rulings against the plan's appendix
mergetakesweight=Nonemeaning ones rather than requiring the column, socollect.rows_ofandstepare untouched and the policy memory never names a weight; the Learner seam, by contrast, requires it.fit_from_scratchrefuses a memory whose weights are all zero, which the appendix does not mention: 4,000 steps of zero gradient would "fit" nothing and say so nowhere.OracleLearner.loadreads a model file without a weight as ones, like a reservoir file, so a test-saved oracle run from before this PR still opens.Not in this PR
PR 3 (targeting) and PR 4 (the boost stage) wait on the plan's open decisions.
Carried from PR 1 and main by merge (2026-11-06)
This branch is stacked on PR 1 (#89) by merge, per the repo's PR rule. Its diff against
maintherefore also shows PR 1's files until #89 lands:src/drawmaha_solver/minidrawmaha/solver/boost_target.py(renamed fromexact_target.py, now with theSamplingframework)tests/minidrawmaha/test_boost_target.pydocs/superpowers/plans/2026-11-06-boost-target-modular-sampling.mdThey are reviewed on #89, not here.
mainwas merged in too, for #92; the one conflict was insrc/drawmaha_solver/deepcfr/AGENTS.md, where both notes are kept. Nothing in this PR's weight column changed.On the two weight formulas. The boost row's stored
weightis(1 − α) · K · arrival, the number of sampled rows it stands for. The refit then weighs every row byt × weight. So the boost module'sK · arrival · tand this PR's(1 − α) · K · arrivalare the same quantity at α = 0: one counts the fit'st, the other leaves it to the fit.