Commit 74edd3b
authored
fix(cfr): dedupe ActionPicker weights by quantised action index (#265)
`ActionPicker::pick_action` iterated `possible_actions` and read
`weights[idx]` for each action independently. When two actions (e.g.,
two nearby bet sizes) quantise to the same 52-slot index via
`ActionIndexMapper`, both contributed the same weight to the cumulative
distribution — biasing the sampler toward the collided index
proportional to the collision multiplicity.
`explore_all_actions` already dedupes by index before training, so the
picker's view was inconsistent with how the regret matcher was updated.
Dedupe by index in both `pick_action` and `pick_best_action`, keeping
the first action per index and preserving input order. Add a regression
test with two colliding bet sizes that verifies the distribution is
split 50/50 with dedupe vs. ~67/33 without.
On the CFR hot path, avoid heap allocations:
- Introduce a stack-allocated `DedupedActions` buffer (`[(u8, &AgentAction); 16]`,
initialised with a `static` fallback sentinel) that replaces the
`Vec<(usize, &AgentAction)>` previously built every call. No `unsafe`,
no `MaybeUninit`.
- `pick_action` uses the buffer for the weighted path so the two passes
(total weight, then cumulative sample) don't re-call `action_to_idx`,
which has `ln()` calls for `Bet` variants.
- No-matcher `pick_action` uses inline reservoir sampling — one pass over
`possible_actions`, no buffer.
- `pick_best_action` walks inline with an `ActionBitSet` and tracks the
max-weight action — no buffer.
Add `benches/action_picker.rs` micro-benchmarks to measure the four
picker paths directly (the full CFR bench has ±15% run-to-run variance
that obscures this signal). Measured on this machine:
pick_action_typical 77.3 ns -> 68.0 ns (-12.0%)
pick_action_collisions 87.5 ns -> 79.5 ns ( -9.1%)
pick_best_action 64.1 ns -> 60.7 ns ( -5.3%)
pick_action_uniform 33.7 ns -> 30.9 ns ( -8.3%)1 parent 9985048 commit 74edd3b
3 files changed
Lines changed: 307 additions & 57 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
138 | 143 | | |
139 | 144 | | |
140 | 145 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
0 commit comments