arXiv ScienceSearch

arXiv · 2608.17531

The Snake Algorithm: A Rejection-Free Sampler for Binary Matrices with Fixed Margins

Abstract

We study uniform sampling of binary matrices with fixed row and column sums, a recurring problem in ecological null models, Rasch-model testing, network analysis, and combinatorics. We propose the Snake algorithm, a rejection-free Markov chain Monte Carlo sampler that grows an alternating path until its first self-intersection and flips the resulting loop. The chain is reversible and irreducible on the fixed-margin state space, hence has the uniform stationary distribution. We prove that one step flips on the order of $\sqrt{n}$ entries in sparse and balanced square regimes, give upper bounds on the per-step path length, and show that the resulting work per flipped entry is rate optimal in sparse and balanced regimes and near-optimal up to a polylogarithmic factor under a one-sided half-balanced condition. A Markov-chain comparison, combined with the recently established universal spectral-gap bound for the swap chain, proves that the lazy Snake chain is rapidly mixing for every feasible pair of margins; in the permutation-matrix case, the raw chain has the sharp total-variation mixing time $Θ(n \log n)$. We also describe a directed-graph extension and an equal-margin label-shuffling variant. Numerical experiments against Swap, Rectangle Loop, Curveball, sequential importance sampling, and a directed edge-swap algorithm show consistent gains in move size, wall-clock convergence, and sampling efficiency.

Explore related subjects

Keep this discovery

Explore connections, maps & timelines

BibTeXRIS

Zipei Nie, Guanyang Wang, Peng Zhang. 2026-08-18. The Snake Algorithm: A Rejection-Free Sampler for Binary Matrices with Fixed Margins. https://arxiv.org/abs/2608.17531

Cite the original work for its findings. Save a collection to share your selection of sources.

KEEP EXPLORING

Related papers

Meta-analysis with the glmmTMB R package

Two common formulations of meta-analytical models include the standard two-stage normal-normal models, which synthesise estimated effect sizes, and the one-stage generalised linear mixed model (GLMM), which directly model the underlying outcome data across studies. The general-purpose glmmTMB R package provides flexible response distributions and random-effect covariance structures through Template Model Builder (TMB). Its existing functionality can fit one-stage meta-analytic GLMM specifications. However, incorporating known sampling variances and covariances in the conventional two-stage inverse-variance formulation of meta-analysis was previously not easily accomplished in glmmTMB. Here, we introduce equalto, a new covariance structure in glmmTMB that allows users to supply a known sampling error variance-covariance matrix when fitting meta-analytic models. This enables explicit modelling of heteroscedasticity and dependence among sampling errors. Using simulations, we show that glmmTMB produces estimates identical to those from the corresponding metafor package functions for normal-normal models and similar estimates for GLMM specifications. We illustrate these models using published meta-analysis datasets in medicine, evolutionary ecology, and the social sciences. With the addition of the equalto covariance structure, glmmTMB now provides a unified and flexible framework for fitting two-stage normal-normal models and one-stage meta-analytic GLMMs, including multivariate specifications. These models can be fitted using the same glmmTMB() function, expanding the R toolkit available for evidence synthesis.

stat.CO

Edgewise Envelopes Between Balanced Forman and Ollivier-Ricci Curvature

Evaluating Ollivier-Ricci (OR) curvature on large-scale graphs is computationally prohibitive due to the necessity of solving an optimal transport problem for every edge. We bypass this bottleneck by deriving explicit, two-sided, piecewise-affine transfer moduli between the transport-based OR curvature and the combinatorial Balanced Forman (BF) curvature. We establish deterministic bounds for $\mathfrak{c}_{\rm OR}(i,j)$ parameterized by 2-hop local graph combinatorics, reducing the edgewise evaluation complexity from an optimal transport linear program to a worst-case $\mathcal{O}\left(\max_{v \in V} \operatorname{deg}(v)^{2.5}\right)$ time, entirely eliminating the reliance on global solvers. Empirical scalability benchmarks confirm these theoretical guarantees, demonstrating that the proposed transfer moduli yield significant asymptotic and constant-factor speedups over the steep polynomial scaling of exact OR evaluation. Furthermore, the tightness of these bounds is validated via distributional analyses on canonical random graphs and empirical networks, with the derived analytical bands enclosing the empirical distributions independent of degree heterogeneity, geometry, or clustering, providing a scalable, computationally efficient framework for rigorous statistical network analysis.

stat.CO

Markov Chain Monte Carlo with Diffusion Paths

Sampling from multimodal distributions is a longstanding challenge for classical local Markov chain Monte Carlo (MCMC) methods. A popular remedy is to introduce a sequence of intermediate distributions that interpolate between the target and a simpler reference. The classical choice, tempering, raises the density to a power, but distorts the relative weights of asymmetric modes and can lead to poor mixing. We instead propose interpolating along the diffusion path, the marginals of a noising diffusion process that carries the target toward a Gaussian. This path preserves the relative weights of the modes and enjoys favorable mixing properties, which we make precise through a spectral-gap analysis of the corresponding ideal transition kernel. Sampling along the path requires its intermediate scores, which can be estimated from the unnormalized target through variational approaches, yielding only an approximate sampler. To remove the resulting bias, we introduce the Metropolis-adjusted diffusion path (MAD-Path) sampler, which corrects the diffusion-path proposal in an augmented path space and leaves the target invariant regardless of the accuracy of the learned score or the discretization error. We further quantify how these two errors affect the acceptance probability, providing guidance for practical tuning. Experiments on a range of Bayesian posteriors show that MAD-Path improves global exploration and mode-weight estimation relative to tempering-based MCMC methods and unadjusted diffusion samplers.

stat.CO