arXiv:2609.35514cs.LGSep 2026

Manuscript Offprint

arXiv:2609.35514

One Proposal for Every Margin: Zero-Shot Amortized Sequential Importance Sampling for Binary Matrices

Ruishuo Chen, Weijia Li, Xun Wang, Yu Chen, Leheng Cai, Longbo Huang

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Ruishuo Chen1^{1}, Weijia Li2^{2}, Xun Wang1^{1}, Yu Chen1^{1}, Leheng Cai2^{2}, Longbo Huang1^{1}

1^{1}Institute for Interdisciplinary Information Sciences, Tsinghua University

2^{2}Department of Statistics and Data Science, Tsinghua University

Correspondence: longbohuang@tsinghua.edu.cn

Abstract. In ecology, psychometrics, and the analysis of social and financial networks, binary matrices are often analyzed conditional on their observed row and column sums, which restricts the problem to a finite sample space of matrices with the same margins. Two fundamental problems are to count this space and to sample uniformly from it. Sequential importance sampling (SIS) addresses both with independent weighted samples and an unbiased count estimator, but its efficiency depends critically on the proposal distribution. Existing proposals are analytically designed, and their accuracy can vary substantially with the margins. We show that the ideal SIS proposal, under which every weight equals the count and the variance vanishes, is exactly the policy of a generative flow network (GFlowNet) with unit reward on every matrix that has the given margins. We therefore propose MarginFlow, a framework that turns the design of the proposal into a learning problem and amortizes it across margins by exploiting their self-similarity. Every partial matrix is itself an instance with reduced margins, so one set transformer that reads the remaining margins serves every margin. We train MarginFlow on a pool of 1904 margins and evaluate it zero-shot on 1190 held-out margins, synthetic and real, from 3×33 \times 3 to 870×6870 \times 6. On 1187 of the 1190 margins it matches or beats the best of 31 analytically designed configurations, chosen post hoc for each margin, and its median effective sample fraction is 99.8%. On the 56 margins where that best loses more than one nat of effective sample size, MarginFlow wins every one and raises the median effective sample fraction from 10.3% to 94.1%.

1. Introduction

Given prescribed row sums r and column sums c, let

Ω(r,c)={X∈{0,1}m×n:X1=r,  X⊤1=c}\Omega(r,c)=\{X\in\{0,1\}^{m\times n}:X\mathbf{1}=r,\;X^{\top}\mathbf{1}=c\}

denote the finite sample space of binary matrices with these margins. Two fundamental computational problems are to evaluate its cardinality Z(r,c)=∣Ω(r,c)∣Z(r, c) = |\Omega(r, c)| and to sample uniformly from it. Ecologists compare the co-occurrence patterns observed across a set of sites with random binary matrices that preserve every species' prevalence and every site's richness (Connor & Simberloff, 1979; Neal et al., 2024). The same comparison is routine wherever a binary table is judged against its own row and column totals, in psychometrics (Chen & Small, 2005; Draxler & Kurz, 2025), social network analysis (Snijders, 1991; Neal, 2025), cancer genomics (Gobbi et al., 2014), and the study of financial and ecological networks (Glasserman & Lelo de Larrea, 2023; Sun et al., 2025).

The two computational tasks are closely linked through completion counts. If the first i−1 rows have been fixed, each feasible next row defines a child of the current partial matrix, and exact uniform sampling selects that child with probability proportional to its number of valid completions. Exact dynamic programming exploits this recursion to provide both counting and uniform sampling, but its state space grows exponentially with the number of columns, so even moderate sizes are out of reach (Miller & Harrison, 2013). Markov-chain methods instead generate matrices with the prescribed margins and approximate the uniform distribution (Verhelst,

(a)

Figure

q∗=Z(child)/Z(parent)q^* = Z(\text{child}) / Z(\text{parent})

(b)

Figure

next-row probabilities

(c)

Figure

post-hoc best of 31, ESS/N (%)

Figure 1 | (a) The five binary matrices with margins r=c=(2,1,1)r = c = (2, 1, 1), built row by row. Each state carries its number of completions ZZ, and the ratio q∗q^* on each edge is the zero-variance proposal: along the bold path q∗(X)=25⋅12=15q^*(X) = \frac{2}{5} \cdot \frac{1}{2} = \frac{1}{5}, so the weight 1/q∗(X)1/q^*(X) is the count 5. (b) The outlined remainder is itself an instance with margins r′=(1,1)r' = (1, 1), c′=(1,0,1)c' = (1, 0, 1); one set transformer reads the remaining margins of any instance and returns next-row probabilities. (c) Effective sample fraction of MarginFlow, zero-shot, against the post-hoc best of 31 configurations on 1190 held-out margins; circles are synthetic margins, triangles real ones, amber the 56 where that best loses over one nat.

2008; Gotelli & Ulrich, 2012; Strona et al., 2014; Fosdick et al., 2018; Fu et al., 2026; Nie et al., 2026). Their draws are typically correlated, and the chains do not directly estimate the number of feasible matrices.

Sequential importance sampling (SIS) instead addresses both tasks with independent weighted samples and an unbiased estimator of the count (Snijders, 1991; Chen et al., 2005). It builds a matrix row by row from a proposal over feasible next rows and weights each completed matrix by the reciprocal of its proposal probability. Its efficiency depends critically on the proposal, whose accuracy can vary substantially with the margins (Harrison & Miller, 2013). On some margin families the mismatch is large enough that SIS requires exponentially many draws to avoid severe underestimation (Bezáková et al., 2012). A long line of work has therefore refined the analytic proposal (Blanchet, 2009; Blitzstein & Diaconis, 2011; Harrison & Miller, 2013; Glasserman & Lelo de Larrea, 2023). These proposals differ in how they approximate the completion counts behind the ideal next-row probabilities. We instead learn those probabilities directly from the proposal's own draws.

In this paper, we view the proposal through the lens of generative flow networks (GFlowNets) (Bengio et al., 2021; da Silva et al., 2025), amortized samplers that build objects stepwise and end at each in proportion to its reward. We show that, with unit reward on every matrix that has margins (r,c)(r, c), the flow at any partial matrix equals its number of completions, while the flow at the initial state equals the total count. Consequently, selecting each child in proportion to its flow yields exactly the ideal zero-variance SIS proposal, as Figure 1(a) shows. A GFlowNet learns this policy by enforcing flow consistency on the matrices it samples itself (Whitammer et al., 2022; Tiapkin et al., 2024; Fawkes & Hartford, 2026), so the proposal can be learned without the count ever being known.

Training a separate GFlowNet per margin, however, costs far more than any analytically designed proposal. We therefore propose MarginFlow, which amortizes the learning across all margins by exploiting their self-similarity. Once k rows are filled, what remains is the same problem on the remaining rows and reduced column sums, so every partial matrix met while sampling is itself an instance, as Figure 1(b) outlines. A set transformer that reads the remaining margins and scores a candidate row is therefore a proposal for every margin at once. We train one such transformer over the column sums on a pool of 1904 margins from six synthetic families and published ecological, mutualistic-network, and psychometric tables, with every test dataset held out by source.

We then evaluate it zero-shot on 1190 held-out margins, synthetic and real, from 3×33 \times 3 to 870×6870 \times 6. The baseline is the best of 31 analytically designed proposal configurations, chosen post hoc for each margin. That choice takes all 31 runs and an effective sample size estimated from their draws, and the estimate misses the rare heavy weights behind the exponential underestimate above, so the baseline is stronger than any analytically designed proposal a user can run.

MarginFlow matches or beats this post-hoc best on 1187 of 1190 margins in Figure 1(c), with a median effective sample fraction of 99.8%. On the 56 margins where that best loses more than one nat, it wins every one and lifts the median from 10.3% to 94.1%. One proposal, learned once and never tuned, thus takes over from the analytically designed proposals and the choice among them.

Our contributions are as follows.

• We establish the equivalence between the zero-variance SIS proposal and the forward policy of a GFlowNet with unit reward on every binary matrix that has the given margins, whose total flow is the number of such matrices. This turns analytic proposal construction into a learning problem.

• We propose MarginFlow, which amortizes this learning across all margins through the self-similarity of the problem, since every partial matrix is itself an instance. One set transformer that reads the remaining margins is trained on a pool of margins. It then serves zero-shot as the proposal on margins it has never seen, with no per-instance training, tuning, or selection.

• On 1190 held-out margins MarginFlow matches or beats the post-hoc best of 31 analytically designed configurations on all but three, with a median effective sample fraction of 99.8%. On the 56 margins where that post-hoc best loses more than one nat, it keeps a median of 94.1% and wins every one, so the learned proposal holds where analytical design gives out.

References (76)