← Blog/blog/posterior-sampler-mean-zero-test

The Bayesian audit that can average violations away

A policy can match Thompson sampling's reward curve without sampling from a Bayesian posterior. Chen and colleagues test that distinction in decision-pretrained transformers: sequence models trained to choose good actions in bandit problems, then adapted to a new problem only through their context. The models often act like posterior samplers. The paper asks whether the mechanism survives two necessary audits.

01

Posterior sampling forgets irrelevant history

In a bandit, an agent repeatedly chooses an arm and observes its reward. Thompson sampling draws a possible environment from the Bayesian posterior, then chooses the action that is best in that draw. For Gaussian and Bernoulli arms, the posterior depends on each arm's observation count and reward sum—not the order in which those rewards arrived. Those counts and sums are sufficient statistics: a compressed history containing all information used by the assumed likelihood.

def stats(context, arms):
    counts = [0] * arms
    sums = [0.0] * arms
    for arm, reward in context:
        counts[arm] += 1
        sums[arm] += reward
    return counts, sums

def paired_difference(original, transformed):
    return [p - q for p, q in zip(original, transformed)]

The authors transform a context while preserving those statistics. They either sort action–reward pairs by reward or replace rewards while keeping each arm's total fixed. A genuine posterior sampler should return the same next-action distribution. The paired difference in the code is therefore zero under the exact condition.

ContextArm countsReward sums
original2, 24, 12
sorted2, 24, 12
reward-replaced2, 24, 12
Deterministic illustrative contexts computed by the core, not paper data. Both transformations preserve the statistics a conjugate bandit posterior uses.
02

The relaxed test can average a miss into a hit

Exact invariance is pointwise: every context and its transformed partner should produce equal action probabilities. Testing that equality literally would reject for tiny approximation errors, so the paper uses a paired Hotelling test of whether the average probability difference is zero. This is a deliberate, pragmatic relaxation.

action 0 paired differencebatch mean
Seeded-free synthetic cancellation example computed by the core. The action-0 probability changes by +0.20 in one pair and −0.20 in the other. The mean-difference norm is 0.00, even though the largest pointwise gap is 0.20.

In the actual experiments, this caveat does not rescue DPT. Across Gaussian, Bernoulli, and linear bandits, every one of the 56 reported sufficient-statistic tests rejects at the 5% level. The bars count rejections by domain and deployment mode; they reproduce the paper's test grid rather than a synthetic effect size.

Paper-reported DPT sufficient-statistic invariance results: 24 of 24 Gaussian, 12 of 12 Bernoulli, and 20 of 20 linear-bandit tests reject. Many Gaussian and Bernoulli p-values are below 10⁻³⁰⁰.
03

A Bayesian forecast is a martingale

Posterior probabilities obey a second necessary condition. Before seeing more data, the expected future posterior equals the current posterior. Applied to actions, the average next-action probability after model-generated continuations should equal today's probability. This is the martingale property: beliefs may move after evidence, but they should not drift predictably in expectation.

Ordinary DPT predicts actions but not rewards, so it cannot generate the joint continuations needed for this audit. The paper trains DPT′ with an added reward prediction and GDPT as a generative decision transformer over action–reward pairs. Using 5,000 environments or continuations per test, every DPT′ martingale test rejects. GDPT rejects 78 of 80; the only non-rejections are online Bernoulli cases with p-values 0.099 and 0.094.

Paper-reported share of martingale tests rejecting at α=0.05. DPT′ rejects all 80; GDPT rejects 78 of 80. The core recomputes the percentages from those counts.
Paper-reported GDPT online-Bernoulli p-values at context length n=50 as continuation length m changes. Orange bars reject; the green 9.9% bar does not. A non-rejection is not evidence of exact martingale behavior.
04

Removing order sensitivity fixes only the easy failure

A transformer with positional encodings can react to a reorder even when a Bayesian posterior would not. The authors therefore remove positional encodings, replace causal attention with bidirectional attention, and mean-pool the context. The ablated DPT becomes exactly invariant to sorting, as its architecture requires. Yet all 12 reward-replacement tests still reject.

Paper-reported permutation-invariant DPT ablation across 12 Gaussian-bandit tests. Sorting now causes exact equality, but every sufficient-statistic-preserving reward-replacement test still rejects.
AuditWhat rejection saysWhat non-rejection does not say
sufficient-statistic invariancebehavior uses history discarded by the assumed posteriorall context pairs are invariant or the model is Bayesian
martingaleaction beliefs drift predictably under generated evidencethe full latent likelihood and decision kernel are correct
regret / rewardthe policy underperforms on the chosen taskthe policy samples a posterior rather than mimicking outcomes
The logical scope of the three diagnostics. The first two are necessary mechanism tests; reward is an outcome test.
05

What to probe next

Report the paired-difference distribution alongside its mean: maximum gaps, quantiles, and context-conditioned slices would reveal cancellation. Pre-register transformations whose distributions differ from the originals, and test several sufficient-statistic-preserving families. For martingales, separate model misspecification in the reward head from drift in the action head.

The present evidence is intentionally narrow: stateless bandits, specific latent likelihoods, trained model classes, and finite tests. Extending the audit to state-dependent control will require a careful definition of what the posterior conditions on. For the sequence-model mechanics behind these policies, continue with the Transformer walkthrough.

References

  1. Chen, W.; Du, X.; Scutari, G.; and Honnappa, H. (2026). Is In-Context Reinforcement Learning A Posterior Sampler? An Empirical Study. arXiv:2610.28977
  2. Falck, F.; Wang, Z.; Holmes, C. C.; and Willetts, M. (2024). Is In-Context Learning in Large Language Models Bayesian? A Martingale Perspective. Proceedings of ICML, PMLR 235
  3. Lee, J. N.; Xie, A.; Pacchiano, A.; Chandak, Y.; Finn, C.; Nachum, O.; and Brunskill, E. (2023). Supervised Pretraining Can Learn In-Context Reinforcement Learning. NeurIPS 2023