Persistent Hamiltonian categorical sampler
Implementation & benchmark of arXiv:2608.17961 — Hamiltonian dynamics for sampling on discrete spaces
Source paper: Hamiltonian dynamics for sampling on discrete spaces arXiv:2608.17961 ⓘ · analyzed Sep 1, 2026
AI-generated research hypothesis, automatically tested. Not peer-reviewed.
Idea description
Replace independent categorical proposals or reversible Metropolis updates for discrete latent variables with a lifted sampler carrying persistent continuous edge momenta. Neighbor transitions are biased by the momentum and use a symmetric energy factor, so momentum reversal gives the required balance relation for the target Gibbs distribution while ordinary dynamics remain non-reversible. This should reduce random-walk behavior when sampling multimodal categorical latents or token sequences.
Formulas
Mathematical statement
Use a discrete state graph G=(S,E), where x is the current discrete configuration, U(x) is the negative log target up to an additive constant, and x^e is the neighbor reached by oriented edge e. For every oriented edge define a signed momentum p_e with p_{\bar e}=-p_e, and let [z]_+=\max(z,0). The lifted jump rate is q_e(x,p)=[p_e]_+\exp(-\Delta_e U(x)/2), where \Delta_e U(x)=U(x^e)-U(x). Under momentum reversal R p=-p, the reverse edge has momentum -p_e and \Delta_{\bar e}U(x^e)=-\Delta_eU(x). Therefore q_e(x,p)\exp(-U(x))=q_{\bar e}(x^e,Rp)\exp(-U(x^e)), which is skew detailed balance for the joint invariant density proportional to \exp(-U(x))\exp(-\|p\|^2/2). A Gaussian momentum refresh p\leftarrow\rho p+\sqrt{1-\rho^2}\,\xi, with \xi\sim N(0,I), preserves the Gaussian momentum marginal and controls ergodicity.
Implementation notes
Integrate the sampler into a categorical latent-variable model or a discrete diffusion reverse sampler. Let x be a batch of categorical configurations, and let U(x) be the model-defined negative log target; for a VAE this can be -log p_theta(x,z) at fixed observed data, while for a diffusion model it can be the negative conditional log probability at one reverse-time noise level. Construct a small neighbor set E(x), initially all single-coordinate substitutions. Maintain one momentum p_e per candidate substitution, or more cheaply one signed scalar p_i for each coordinate and draw a random candidate replacement from the positive-momentum directions. At each event, compute the neighbor energies U(x^e), form delta=U(x^e)-U(x), and set rate q=[p_e]_+*exp(-delta/2). Sample the next event time as Exponential(sum_e q_e), select edge e with probability q_e/sum_e q_e, apply x<-x^e, and retain momentum. Every K events perform p<-rho*p+sqrt(1-rho^2)*Normal(0,1); optionally flip momentum when a configured boundary or truncation rule is hit. The displayed generator gives the exact continuous-time process; use Gillespie simulation for the first correctness test. The mathematical quantity is the rate q and its skew-balance identity; estimate U only with the target network, and do not estimate gradients. First test a 16- or 32-dimensional categorical VAE with 16 categories per coordinate on synthetic mixtures and MNIST discrete latents. Compare against random-walk Metropolis, Gibbs, and categorical local Metropolis using the same number of U evaluations. Measure autocorrelation time, effective samples per evaluation, mode coverage, and target-distribution bias. Success means at least 2x larger effective sample size at equal target evaluations with no measurable increase in stationary-distribution error.
Verification
Stage 1 · Toy mechanism gate: Passed ✓
Stage 2 · Mechanism transferred to benchmark: Not reproduced ✗
Stage 2 · Practical benchmark result: Inconclusive
Methodology: 8 paired seeds, permutation test (p<0.05) against a learning-rate-tuned baseline. How verification works
Stage 1 — Mechanism check agent confidence 9/10
Built a Gillespie persistent-momentum sampler for a uniform categorical ring and numerically checked the skew detailed-balance identity. The predicted sign correlation 2 asin(rho)/pi and run length 1/(1-correlation) matched all five rho values with absolute correlation errors below 0.004. Persistence improved the ring position autocorrelation metric from 187.7 at rho=0 to 151.0 at rho=0.75, but this is only about a 20% improvement, so the mechanism manifested without demonstrating the claimed 2x sampling gain.
- Agent confidence
- 9/10
- Baseline
- rho=0: position_tau=187.72, sign_corr=0.00257
- Idea
- rho=0.75: position_tau=150.96, sign_corr=0.53851; predicted sign_corr=0.53989, predicted run_length=2.1734, observed run_length=2.1669
Limitations: Only a uniform one-dimensional ring was tested; no multimodal nonuniform categorical target, Metropolis/Gibbs baseline, batch latent model, FLOP-matched comparison, or high-dimensional token-sequence experiment was evaluated. The continuous-time waiting-time estimate is noisy because Gaussian momentum produces heavy-tailed inverse-rate waits.
How to run: python3 sampler_experiment.py
Stage 2 — Benchmark vs. tuned baseline (arXiv:2608.17961)
Ahead of the baseline (−1.6%) but not statistically significant (p=0.3411, wins 4 / 8 paired seeds).
- Benchmark
- Categorical_persistent_sequences
- Model
- mlp_token_logits
- Paired seeds
- 8
- Baseline mean
- 0.4945
- Idea mean
- 0.4864
- Effect (Δ)
- -0.008 (−1.6%; negative = idea better)
- Wins
- 4 / 8 paired seeds
- p-value
- 0.3411 (permutation test, 20 000 shuffles)
- Smallest detectable effect
- n/a
- Mechanism
- Not confirmed ✗
- Practical effect
- Inconclusive
- Baseline tuning
- swept over 0 configs
The custom benchmark uses a small synthetic binary multi-token classification task and an approximate fixed-step sampler rather than exact continuous-time Gillespie dynamics. No larger categorical VAE, real-language token sequence, multimodal target, or FLOP-normalized production-scale evaluation was tested.
How to run: python3 stage2_bench.py
Verdict computed by deterministic test code from paired-seed statistics — not by the language model.
Stage 2 — Benchmark latest Failed ✗
Agent confidence: 9/10
Implemented an end-to-end categorical multi-token benchmark with a shared MLP, independent categorical decoding baseline, and persistent Hamiltonian momentum sampler intervention. Across 8 paired seeds, the best idea configuration achieved error 0.48641 versus baseline 0.49445, but the paired delta was not significant (p=0.3411). The mechanism signature was not confirmed: observed sign correlation was 0.065 versus predicted 0.540.
- Baseline
- test err mean=0.494453125, std=0.0157818301, best_cfg={lr:0.003,temp:0.8}
- Comparison
- delta_mean=-0.008046875, idea_wins=4/8, p_value=0.3411, verdict=no significant win
- Idea
- test err mean=0.48640625, std=0.0130644063, best_cfg={lr:0.01,temp:1.0,rho:0.0}
- Mechanism signature
- predicted sign correlation=0.5398931; observed mean=0.0651730; mean absolute error=0.4747211; confirmed=false
Benchmark result
Ahead of the baseline (−1.6%) but not statistically significant (p=0.3411, wins 4 / 8 paired seeds).
- Benchmark
- Categorical_persistent_sequences
- Model
- mlp_token_logits
- Paired seeds
- 8
- Baseline mean
- 0.4945
- Idea mean
- 0.4864
- Effect (Δ)
- -0.008 (−1.6%; negative = idea better)
- Wins
- 4 / 8 paired seeds
- p-value
- 0.3411 (permutation test, 20 000 shuffles)
- Smallest detectable effect
- n/a
- Mechanism
- Not confirmed ✗
- Practical effect
- Inconclusive
- Baseline tuning
- swept over 0 configs
The custom benchmark uses a small synthetic binary multi-token classification task and an approximate fixed-step sampler rather than exact continuous-time Gillespie dynamics. No larger categorical VAE, real-language token sequence, multimodal target, or FLOP-normalized production-scale evaluation was tested.
How to run: python3 stage2_bench.py
Artifacts
- bench_report.json 14.8 KB View Raw
- categorical_track.py 1.1 KB View Raw
- report.md 1.4 KB View
- report_bench_2026-09-01T165112.md 3.5 KB View
- results.json 2.3 KB View Raw
- sampler_experiment.py 3.1 KB View Raw
- stage2_bench.py 4.7 KB View Raw