Skip to content

Fix extended battery rejecting correct samplers on its default path - #7

Merged
tprest merged 1 commit into
masterfrom
saga-fix-battery-default-samples
Jul 9, 2026
Merged

Fix extended battery rejecting correct samplers on its default path#7
tprest merged 1 commit into
masterfrom
saga-fix-battery-default-samples

Conversation

@tprest

@tprest tprest commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Found while answering "how do I run the univariate battery?" — the documented, default way to call it gives a guaranteed false alarm.

The bug

UnivariateSamples.run_extended_battery() without an explicit samples= rebuilds the sample list from the histogram:

samples = [z for z in self.histogram for _ in range(self.histogram[z])]

That list is sorted. The three sequence tests — Ljung-Box, runs, block homogeneity — measure ordering, so they see a perfectly monotone stream and reject at p ≈ 0. Every correct sampler fails the default battery.

Measured on 20 000 samplerz draws:

default path (before) with samples= after this fix
ljung_box 0.0000 0.2642 0.2642
runs_test 0.0000 0.7209 0.7209
block_homogeneity 0.0000 0.8981 0.8981
all_pass False True True

The fix

The class already receives the ordered samples in __init__ and discards them. Keep them (by reference — no memory cost, MultivariateSamples passes a pandas Series view) and use them as the default.

Why CI missed it

Every existing test passes samples= explicitly, so the default path was never exercised — the same blind spot as the earlier nan bug. Added test_extended_battery_default_samples, which exercises it. Verified: that test fails on all six good vectors without this fix, passes with it.

Suite: 140 passed, 1 skipped.

🤖 Generated with Claude Code

UnivariateSamples.run_extended_battery() called without an explicit `samples=`
argument rebuilt the sample list from the histogram:

    samples = [z for z in self.histogram for _ in range(self.histogram[z])]

which is *sorted*. The three sequence tests -- Ljung-Box, runs, block
homogeneity -- measure ordering, so they saw a perfectly monotone stream and
rejected at p ~ 0. Any correct sampler therefore failed the default battery
(all_pass=False, is_valid_extended=False).

The class already receives the ordered samples in __init__ and threw them away.
Keep them (by reference, no memory cost) and use them as the default.

Verified on 20k samplerz draws: default path went from ljung_box/runs/
block_homogeneity all at p=0.0000 to p=0.26/0.72/0.90, all_pass=True.

The suite never caught this because every test passed `samples=` explicitly, so
the default path was unexercised -- the same blind spot as the earlier nan bug.
Added test_extended_battery_default_samples, which exercises the default path
and fails on all six good vectors without this fix.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tprest
tprest merged commit 5e03fda into master Jul 9, 2026
4 checks passed
@tprest
tprest deleted the saga-fix-battery-default-samples branch July 9, 2026 21:57
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