Skip to content

Commit baca42f

Browse files
krukahandyafter
andcommitted
test(kuhn): guard sampling-distribution normalization (#53)
Asserts sampling_distribution sums to ~1 across Kuhn infosets. Fails on the pre-#57 code (Z ≈ 1.04 for J|Bet), where the per-edge smoothing pseudocount and curiosity floor left the distribution unnormalized; passes with the normalized sampling. Locks in the #53 fix. Co-authored-by: andyafter <3354145+andyafter@users.noreply.github.com>
1 parent 624e4fb commit baca42f

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

crates/kuhn/src/solver.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,23 @@ mod tests {
156156
kuhn_info(true, rank, node)
157157
}
158158

159+
/// Regression guard for #53: `sampling_distribution` must be a true
160+
/// probability distribution (Σ ≈ 1), so `sampling_reach` uses the same
161+
/// probability `WeightedIndex` draws from. Before the fix the per-edge
162+
/// smoothing pseudocount and the curiosity floor left it summing to Z > 1.
163+
#[test]
164+
fn sampling_distribution_is_normalized() {
165+
let solver = Kuhn::<FlooredRegret, LinearWeight, ExternalSampling>::default().solve(1 << 12);
166+
let p = solver.profile();
167+
for rank in [Rank::J, Rank::Q, Rank::K] {
168+
for node in [History::Open, History::Bet, History::Check, History::CheckBet] {
169+
let info = view(rank, node);
170+
let sum = p.sampling_distribution(&info).iter().map(|(_, q)| *q).sum::<f32>();
171+
assert!((sum - 1.0).abs() < 1e-4, "sampling_distribution({rank:?}, {node:?}) sums to {sum:.5}, not 1");
172+
}
173+
}
174+
}
175+
159176
#[test]
160177
#[rustfmt::skip]
161178
fn nash_equilibrium() {

0 commit comments

Comments
 (0)