Skip to content
AI.info

Research

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

Overview Research area: Machine learning and probabilistic inference applied to combinatorics — specifically sequential importance sampling (SIS), generative flow networks (GFlowNets), and binary matr

One Proposal for Every Margin: Zero-Shot Amortized Sequential Importance Sampling for Binary Matrices
arXiv
2609.35514
Published
2026-09-28
Authors
Ruishuo Chen, Weijia Li, Xun Wang, Yu Chen, Leheng Cai, Longbo Huang

AI summary

Overview

Research area: Machine learning and probabilistic inference applied to combinatorics — specifically sequential importance sampling (SIS), generative flow networks (GFlowNets), and binary matrix counting under fixed row and column sums.

Technical level: Advanced. The paper combines GFlowNet theory (trajectory balance, log-variance objectives, flow consistency), importance sampling theory (Rényi divergence, effective sample size), and a set-transformer architecture. Familiarity with Monte Carlo methods and deep generative models is assumed.

Scope: The paper proves that the ideal zero-variance SIS proposal for binary matrices with fixed margins is exactly the forward policy of a GFlowNet with unit reward, and builds MarginFlow, a single set transformer that learns this proposal once and applies it zero-shot to unseen margins.

What This Paper Is About

Many scientific fields analyze binary matrices (rows = species or items, columns = sites or tests) conditional on the observed row and column sums, which restricts attention to a finite set of matrices sharing those margins. Two core computational problems arise: counting how many such matrices exist, and drawing uniformly from them. Sequential importance sampling solves both with weighted samples and an unbiased count estimator, but its efficiency hinges entirely on the proposal distribution — and existing proposals are hand-designed formulas whose accuracy degrades substantially as margins change. This paper reformulates the search for a good proposal as a learning problem and amortizes that learning across all margins with one neural network.

Key Contributions

  1. Equivalence between zero-variance SIS and GFlowNets. The authors prove that the ideal proposal, under which every importance weight equals the total count and the variance vanishes, is exactly the forward policy of a GFlowNet with unit reward on every binary matrix having the given margins, and that the network's total flow equals the count. This converts analytic proposal construction into a learning problem that never needs the count known in advance.

  2. MarginFlow, an amortized proposal. Exploiting the self-similarity of the problem — every partial matrix is itself an instance with reduced row and column sums — the authors train one set transformer that reads the remaining margins and scores candidate next rows. This single network serves every margin, with no per-instance training, tuning, or selection.

  3. Zero-shot evaluation against a strong post-hoc baseline. On 1190 held-out margins (synthetic and real, from 3×3 to 870×6), MarginFlow matches or beats the best of 31 analytically designed proposal configurations — a baseline chosen with hindsight per margin — on 1187 of 1190, with a median effective sample fraction of 99.8%.

  4. Theory linking training loss to sampling quality. The trajectory-balance residual of any proposal is shown to be its log weight up to a constant; the log-variance loss equals the variance of the log weights, whose expected gradient maximizes the entropy of the draws; and the effective sample fraction converges to e^(−D₂(p‖q)), tying the training objective directly to the precision of the SIS count.

Main Findings

  • Zero-variance proposal equals GFlowNet flow policy: The flow through a partial matrix equals its number of completions, the total flow at the empty state equals the count Z, and the flow-proportional policy Z(X_≤i)/Z(X_<i) is precisely the zero-variance proposal q*.

  • Loss is the spread of the sampler's own weights: Under trajectory balance, the residual for any matrix X is log Z_θ − log w_θ(X); under the log-variance objective, the loss is Var_b[log w_θ(X_b)]. Training therefore measures and minimizes the spread of the importance weights, without ever evaluating Z. With uniform target p, each expected update raises the entropy of the draws.

  • The count should come from SIS, not the GFlowNet: The scalar log Z_θ that trajectory balance fits falls short of log Z by whatever KL divergence training has not yet removed (on the reported 88×6 Web of Life margin, it starts 0.9 nats below log Z and remains 0.005 nats short at the end of training). The mean importance weight of SIS, in contrast, stays within 0.02 nats of log Z from the first thousand steps onward.

  • Main benchmark result: Median effective sample fraction across 1190 held-out margins: CDHL (default conditional Poisson at u=1) 41.5%, Harrison–Miller 97.4%, post-hoc best of 31 configurations 99.4%, MarginFlow 99.8%. Win/tie/loss counts against the post-hoc best are 415/772/3.

  • Results by margin source: synthetic with new seeds (880 margins) 99.8% for MarginFlow versus 99.4% post-hoc best; interpolated synthetic (100 margins) 99.9% versus 99.7%; real tables (210 margins) 99.8% versus 99.2%.

  • The hardest margins show the largest gains: On the 56 margins where the post-hoc best falls below 37% effective sample fraction (the threshold where it loses more than one nat, since e^(−1) = 36.8%), MarginFlow wins all 56 and raises the median from 10.3% to 94.1%. The post-hoc best, CDHL, and Harrison–Miller score 10.3%, 0.5%, and 7.7% respectively on that tier.

  • Tail improvement: MarginFlow raises the tenth percentile of effective sample fraction across the test set from the post-hoc best's 68.5% to 98.1%.

  • Error compounds over rows: Because a matrix weight is a product over rows, a proposal erring by δ nats per row loses up to mδ² nats in total. On power-law margins with six columns in the dense band, the Harrison–Miller proposal falls from 98.7% at 6 rows to 0.6% at 840 rows, while MarginFlow stays below 0.1 nat lost at 840 rows and below one nat in every group of the dense band. On the family of Bezáková et al. (2012), it extrapolates to five times the number of rows it trained on.

  • Tightening theory confirms practice: On the 88×6 Web of Life table, training three seeds alone reduces the log-weight variance from 1.1 nats to 0.01 over 15,000 steps, while the exact Rényi divergence D₂(p‖q_θ) falls from 4.7 nats to 0.01. Initially the three quantities differ by a factor of four; from about a thousand steps on they coincide, as the theory predicts near the optimum.

Methodology in Plain English

The authors start from the observation that SIS builds a matrix one row at a time, and that the perfect proposal for the next row would pick it with probability proportional to how many valid completions it leaves. That perfect proposal is as hard to compute as the count, which is why classical proposals use closed-form approximations instead.

The paper's first move is to reframe the problem as a GFlowNet: a directed acyclic graph whose states are partial matrices, whose actions are feasible next rows (checked by the Gale–Ryser test), and where every completed matrix carries reward one. In this setting the flow through any state is exactly its completion count, and the flow-proportional policy is the perfect proposal. A GFlowNet can be trained to match this policy using only rewards of sampled matrices — never the counts — by minimizing the variance of the log importance weights across a batch.

The second move is amortization. After k rows are filled, what remains is the same kind of problem on the remaining rows and reduced column sums, so every partial matrix encountered during sampling is itself an instance. One network can therefore serve all margins. The authors exploit symmetry further: because permuting columns leaves the optimal probabilities unchanged, rows that have the same counts of ones in columns of each reduced sum value share a "type," and the network outputs a distribution over types rather than over the (far more numerous) individual rows. A combinatorial term counting how many rows a type contains, plus the log weight from the Harrison–Miller analytic proposal as a prior, are added outside the network; the network learns only a correction. The architecture is a set transformer with four pre-norm attention layers of width 256 and no positional encoding, initialized so that training starts from the analytic proposal.

Training uses a pool of 1904 margins. Evaluation is zero-shot on 1190 held-out margins, against 31 analytic configurations (five proposals each raised to six exponents u ∈ [0.5, 2], plus uniform). Where the type-level state graph has at most 4×10⁵ states — 681 of the 1190 test margins — the limiting effective sample fraction e^(−D₂(p‖q)) is computed exactly by dynamic programming; the other 509 are estimated from N = 4000 draws with medians over 16 repetitions. Reported MarginFlow values are medians over three training seeds, each trained for 25 hours on eight A100s; the baseline sweep took roughly 9,000 hours of compute.

Why This Matters

Impact on research. The paper closes a long-standing gap between what SIS theory says the optimal proposal should be and what analytic formulas can deliver. It gives a precise theoretical bridge between GFlowNets and importance sampling — flow equals completion count, training loss equals log-weight variance, effective sample fraction equals a Rényi divergence — and shows empirically that a learned proposal can match or beat a baseline chosen with perfect hindsight. It also demonstrates a template for amortizing combinatorial inference across problem instances via self-similarity.

Real-world applications (all cited as domains where margins-conditional analysis is routine):

  • Ecology and biogeography: comparing observed species-by-site co-occurrence patterns against random matrices that preserve every species' prevalence and every site's richness, the null model introduced by Connor and Simberloff (1979).
  • Psychometrics: testing item-response and test-theory tables against their own row and column totals, as in the Rasch model and the networksis package's default use case.
  • Social network analysis: assessing affiliation and interaction networks (for example the Davis et al. 1941 dataset and Web of Life mutualistic networks) against degree-preserving randomizations.
  • Cancer genomics and financial networks: the paper cites binary-table analyses in cancer genomics (Gobbi et al., 2014) and in financial network studies (Glasserman and Lelo de Larrea, 2023).

Industry relevance. Counting and sampling binary matrices with fixed margins underlies any pipeline that needs exact or unbiased null distributions for binary data: network science tooling, psychometric software, ecological statistics packages, and financial contagion modeling. The method replaces a per-dataset search over proposal formulas and exponents with a single pretrained checkpoint that requires one forward pass per row at deployment. The authors note that the same row-by-row construction extends to contingency tables with integer entries and to graphs with prescribed degrees, both of which appear in industry settings.

Future Directions

  • Extending beyond binary matrices. The conclusion explicitly states that contingency tables with integer entries and graphs with prescribed degrees are also built row by row from a remainder that is itself an instance, and that the same construction carries over to each.

  • Scaling the enumeration constraint. The network enumerates feasible row types at every state, and training was limited to states with fewer than 2×10⁴ types (evaluation under 10⁵). Scaling to wider, denser margins without exhaustive type enumeration remains open.

  • Tightening type-level tractability. Exact evaluation of the limiting effective sample fraction via dynamic programming was feasible on only 681 of 1190 test margins (those with at most 4×10⁵ type-level states); the remaining 509 required finite-sample estimation from N = 4000 draws.

  • Understanding the residual gap between log Z_θ and log Z. The authors show the GFlowNet's fitted scalar stays below log Z by the remaining divergence and therefore use SIS for the count. Whether the small residual divergence (0.005 nats at the end of the reported run) can be systematically driven to zero, or closed cheaply, is left open.

Target Audience

This paper is for researchers and practitioners in machine learning and computational statistics working on Monte Carlo inference, GFlowNets, or discrete generative modeling, as well as quantitative scientists in ecology, psychometrics, social network analysis, and genomics who routinely need null distributions for binary matrices with fixed margins. Readers who use or maintain tools such as networksis will find the benchmark comparison directly relevant. A background in probabilistic graphical models and importance sampling is helpful; the appendix-level proofs and flow-consistency arguments will be most accessible to readers already familiar with GFlowNet training objectives.

Authors’ 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\times3$ to $870\times6$. 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%.

Read the original paper