Skip to content
QFT.org

Search QFT.org

Enter a word or phrase.

    You can also browse the main navigation and chapter contents.

    An autoregressive sampler can generate independent configurations and evaluate their normalized probabilities without knowing a partition function. The independence is a property of the fitted model. It does not make that model equal to the physical Gibbs measure. A nine-spin example lets us train the distribution, enumerate its remaining bias, and check exactly what a subsequent Metropolis correction changes.

    Preparation: Finite Gibbs measures and the exact Ising example, likelihoods and training objectives, and corrected learned proposals.

    Generate a configuration one conditional at a time

    Choose an ordering of NN spins si∈{−1,+1}s_i\in\{-1,+1\}. The probability chain rule suggests

    qθ(s)=∏i=1Nqθ(si∣s1,…,si−1).q_\theta(s)=\prod_{i=1}^{N}q_\theta(s_i\mid s_1,\ldots,s_{i-1}).

    Each factor is normalized over its own spin for every earlier assignment. Summing over sNs_N first removes the final factor; summing successively over sN−1,…,s1s_{N-1},\ldots,s_1 proves ∑sqθ(s)=1\sum_s q_\theta(s)=1. This construction is the central ingredient in Wu–Wang–Zhang, main Eq. (4), Appendix A, Eqs. (6)–(11).

    A small trainable choice is a triangular logistic model,

    hi=bi+∑j<iWijsj,qθ(si∣s<i)=σ(sihi),σ(h)=11+e−h.h_i=b_i+\sum_{j<i}W_{ij}s_j,\qquad q_\theta(s_i\mid s_{<i})=\sigma(s_i h_i), \qquad \sigma(h)=\frac1{1+e^{-h}}.

    Thus q(si=+1∣s<i)=σ(hi)q(s_i=+1\mid s_{<i})=\sigma(h_i) and q(si=−1∣s<i)=1−σ(hi)q(s_i=-1\mid s_{<i})=1-\sigma(h_i). The logarithm of the joint density is

    log⁡qθ(s)=−∑ilog⁡(1+e−sihi).\log q_\theta(s)=-\sum_i\log(1+e^{-s_i h_i}).

    A stable log-sum-exp evaluates this expression without exponentiating a large logit. For finite parameters every configuration has positive probability. This is a restricted family of conditionals: exact conditionals obtained by summing over future interacting spins need not have logits linear in the earlier spins.

    To sample, draw s1s_1 from its Bernoulli law, evaluate h2h_2 using that realized value, draw s2s_2, and continue. New independent random numbers give a new independent model configuration. Dependence among spins within a configuration is intended. Sampling a complete configuration is sequential in this ordering, although evaluating the density of an already known configuration can calculate all logits together. A dense triangular model uses O(N2)O(N^2) coefficients and arithmetic; neither its ordering nor its matrix automatically respects lattice translations.

    Normalized-looking local factors are insufficient if they depend cyclically on future variables. For example, set h1=cs2h_1=c s_2 and h2=cs1h_2=c s_1. Then

    ∑s1,s2σ(cs1s2)2=1+tanh⁡2(c/2)>1(c≠0).\sum_{s_1,s_2}\sigma(c s_1s_2)^2 =1+\tanh^2(c/2)>1\qquad(c\ne0).

    The nested normalization proof no longer applies. Our deliberate c=0.8c=0.8 control reproduces this failure, while the actual model excludes every future-spin weight.

    Train a finite physical distribution

    Use the periodic 3×33\times3 ferromagnetic Ising model with coupling one and zero external field,

    H(s)=−∑x(sxsx+1^+sxsx+2^),pT(s)=e−H(s)/TZT.H(s)=-\sum_x\left(s_xs_{x+\hat1}+s_xs_{x+\hat2}\right), \qquad p_T(s)=\frac{e^{-H(s)/T}}{Z_T}.

    Each positive-coordinate bond is counted once. There are N=9N=9 spins and 512512 configurations. Row-major site order fixes the triangular model, with nine biases and 3636 lower-triangular weights: 4545 real parameters. We use T=2.3T=2.3 and 1.61.6. These are two finite systems; the calculation does not locate a thermodynamic critical point.

    The exact enumeration supplies ZTZ_T, all target moments and all model expectations. An independently assembled row-transfer matrix checks ZTZ_T, and explicit bond loops check the energy. Full enumeration also makes training deterministic. It is exponentially expensive in NN and is used here to expose the approximation, not presented as a scalable replacement for simulation.

    Two losses ask different approximation questions. The forward divergence is

    DKL(pT∥qθ)=∑spT(s)log⁡pT(s)qθ(s).D_{\rm KL}(p_T\Vert q_\theta) =\sum_s p_T(s)\log\frac{p_T(s)}{q_\theta(s)}.

    Its parameter-dependent part is the target-weighted cross entropy −∑spTlog⁡qθ-\sum_s p_T\log q_\theta. For the triangular logistic architecture this is a sum of convex logistic-regression losses. It requires the exact target weights in this example.

    The reverse divergence instead satisfies

    DKL(qθ∥pT)=∑sqθ(s)[H(s)T+log⁡qθ(s)]+log⁡ZT.D_{\rm KL}(q_\theta\Vert p_T) =\sum_s q_\theta(s)\left[\frac{H(s)}T+\log q_\theta(s)\right]+\log Z_T.

    Define Rθ(s)=H(s)/T+log⁡qθ(s)R_\theta(s)=H(s)/T+\log q_\theta(s) and Fθ=T⟨Rθ⟩q\mathcal F_\theta=T\langle R_\theta\rangle_q. Then

    Fθ−FT=TDKL(qθ∥pT)≥0,FT=−Tlog⁡ZT.\mathcal F_\theta-F_T=T D_{\rm KL}(q_\theta\Vert p_T)\geq0, \qquad F_T=-T\log Z_T.

    The expectation Fθ\mathcal F_\theta is a variational upper bound. A finite Monte Carlo estimate of that expectation can fluctuate below FTF_T; the inequality is not a deterministic bound on every sample average. The variational formulation and reverse score gradient appear in Wu–Wang–Zhang, Eqs. (2)–(5) and Appendix B. Here the expectation is summed over every state.

    Differentiate the distribution as well as its log likelihood

    Let ui=(si+1)/2u_i=(s_i+1)/2. Differentiation gives the local logit score

    ∂log⁡qθ(s)∂hi=ui−σ(hi).\frac{\partial\log q_\theta(s)}{\partial h_i} =u_i-\sigma(h_i).

    Multiplying it by 11 or a preceding spin supplies the bias or weight score. Forward-loss differentiation weights the negative score by pTp_T.

    For the reverse loss, qθq_\theta itself depends on the parameters. With Sθ(s)=∇θlog⁡qθ(s)S_\theta(s)=\nabla_\theta\log q_\theta(s),

    ∇θ⟨Rθ⟩q=⟨RθSθ⟩q+⟨Sθ⟩q=⟨RθSθ⟩q,\nabla_\theta\langle R_\theta\rangle_q =\langle R_\theta S_\theta\rangle_q+\langle S_\theta\rangle_q =\langle R_\theta S_\theta\rangle_q,

    because ⟨Sθ⟩q=∇θ∑sqθ(s)=0\langle S_\theta\rangle_q=\nabla_\theta\sum_s q_\theta(s)=0. Any state-independent baseline can therefore be subtracted:

    ∇θ⟨Rθ⟩q=⟨[Rθ−⟨Rθ⟩q]Sθ⟩q.\nabla_\theta\langle R_\theta\rangle_q =\left\langle [R_\theta-\langle R_\theta\rangle_q]S_\theta \right\rangle_q.

    The code uses the exact finite-sum baseline. A same-batch random estimate needs more care, as Exercise 2 shows. Differentiating only the sampled log⁡q\log q while treating the sampled states as fixed would omit the changing-distribution term.

    The implementation compares scalar-loop and vectorized likelihoods, checks the mean score, and finite-differences both losses along five declared directions at two fixed parameter vectors. Every direction reaches scaled error below 1.3×10−101.3\times10^{-10} on the retained step scan. This tests the implemented derivative; it does not establish that a nonconvex optimizer reaches a global minimum.

    What the actual fits learn

    At each temperature, train two reverse-loss starts and one forward-loss start. All parameters lie in [−8,8][-8,8], with independent initial values of SD 0.050.05. The fixed L-BFGS-B budget is 500500 iterations, 25002500 function evaluations, relative objective tolerance 10−1310^{-13} and projected-gradient tolerance 10−910^{-9}. The companion records the exact seeds and every stopping status.

    All six runs stop by the relative objective-change test. Their final maximum gradient components range from 1.10×10−81.10\times10^{-8} to 1.53×10−71.53\times10^{-7}, so none meets the separately requested gradient tolerance. No bound is active. The primary reverse fit is start zero; the second start remains a sensitivity result, not a replacement selected after inspecting errors.

    The following are exact enumerated diagnostics of the returned models, with no sampling error attached:

    TTFitted lossDKL(q∥p)D_{\rm KL}(q\Vert p)DKL(p∥q)D_{\rm KL}(p\Vert q)Total variation
    2.32.3Reverse, start zero4.4254×10−44.4254\times10^{-4}4.3483×10−44.3483\times10^{-4}0.0082070.008207
    2.32.3Forward4.4311×10−44.4311\times10^{-4}4.3428×10−44.3428\times10^{-4}0.0079630.007963
    1.61.6Reverse, start zero4.8530×10−44.8530\times10^{-4}4.3710×10−44.3710\times10^{-4}0.0034500.003450
    1.61.6Forward4.9217×10−44.9217\times10^{-4}4.3090×10−44.3090\times10^{-4}0.0029140.002914

    The forward fit has the smaller forward divergence, while the reverse fit has the smaller reverse divergence, as intended here. These are small but nonzero errors. Similar probabilities for the dominant configurations do not prove that every rare configuration is accurately represented.

    For m=N−1∑isim=N^{-1}\sum_i s_i, the exact T=2.3T=2.3 value is ⟨∣m∣⟩p=0.864079\langle|m|\rangle_p=0.864079, whereas the primary reverse model gives 0.8629720.862972. At T=1.6T=1.6, the corresponding numbers are 0.9781180.978118 and 0.9777660.977766. Enumeration identifies these biases without conflating them with sampling noise. The returned bias parameters leave tiny spin-flip defects, at most 3.8×10−73.8\times10^{-7} over all six fits; symmetry was not imposed by hand.

    Exact and fitted magnetization probabilities at two finite Ising temperatures, with probability differences exposing small residual model bias.

    The magnetization probabilities and their differences are summed over all 512512 configurations. The reverse curves use the prescribed start zero, and the forward curves use their single fixed start. These are model probabilities, not sampled histograms.

    Fresh ancestral sampling uses eight independent replicas of 40964096 configurations for each displayed model. For the T=2.3T=2.3 reverse fit, the sampled mean magnetization is 0.011910.01191 with replica SE 0.002940.00294, although its exact model mean is only 8.2×10−88.2\times10^{-8}. This approximately four-estimated-SE fluctuation is retained; eight replicas provide only seven variance degrees of freedom, and many observables are examined. We neither redraw it nor infer a physical nonzero magnetization. The likelihood and enumeration distinguish a finite sample fluctuation from the model's known bias.

    Exact correction creates a different stochastic process

    Freeze qq and propose an independent new configuration. Independence Metropolis accepts it with

    A(i,j)=min⁡(1,pjqipiqj).A(i,j)=\min\left(1,\frac{p_jq_i}{p_iq_j}\right).

    For i≠ji\ne j, Pij=qjA(i,j)P_{ij}=q_jA(i,j), and the diagonal includes rejected proposals as well as accepted proposals equal to the current state. Detailed balance follows directly:

    piPij=min⁡(piqj,pjqi)=pjPji.p_iP_{ij}=\min(p_iq_j,p_jq_i)=p_jP_{ji}.

    Thus pp is stationary. All entries of our finite proposal are positive, so this finite-state chain is irreducible and aperiodic. That argument identifies its stationary law, not the finite burn-in needed for a large or poorly covered target.

    Here the complete 512×512512\times512 transition matrix can be built. Its row, stationary and detailed-balance residuals are below 1.2×10−151.2\times10^{-15}. For a centered observable ff its stationary lag-one correlation is calculated exactly as

    ρf(1)=∑ijpifiPijfj∑ipifi2.\rho_f(1)= \frac{\sum_{ij}p_i f_iP_{ij}f_j}{\sum_i p_if_i^2}.

    The primary reverse model gives:

    TTAccepted proposal fractionActual state-change fractionρH/N(1)\rho_{H/N}(1)
    2.32.30.987970.987970.767250.767250.016590.01659
    1.61.60.994850.994850.564200.564200.038930.03893

    Acceptance includes a proposal identical to the current state, so it differs from the move probability. Even high acceptance leaves nonzero correlations. In the independent-model draws the observations follow qq and have no Markov dependence; in the corrected chain the stationary law is pp and the retained states are correlated. This calculation uses the full matrix rather than adding a second chain experiment. The continuous-field correction example measures finite-chain behavior separately.

    A final exact diagnostic is worth distinguishing from a heuristic. If RθR_\theta has zero variance under a full-support qq, it is constant on every configuration. Therefore q(s)∝e−H(s)/Tq(s)\propto e^{-H(s)/T} and normalization gives q=pq=p. A small variance measured on a short sample need not see a missed region. The support condition is indispensable to the argument in Wu–Wang–Zhang, Appendix C.

    Summary

    Normalized conditional distributions give an exactly normalized model and an ordered sampler. The finite example performs real optimization and still has measurable target bias. Full enumeration separates that bias from random sampling errors, while the complete Metropolis matrix shows how exact stationary correction replaces independent model draws by a correlated target-preserving process.

    Exercises

    1. Build the exact two-spin autoregressive model

    For H=−Js1s2H=-J s_1s_2 at inverse temperature β\beta, find normalized conditionals in the stated order and derive ⟨s1s2⟩\langle s_1s_2\rangle. Does independence of different generated configurations mean that their two spins are independent?

    Solution

    Summing the four weights gives Z=4cosh⁡(βJ)Z=4\cosh(\beta J). Summing over s2s_2 gives p(s1)=1/2p(s_1)=1/2. At fixed s1s_1,

    p(s2∣s1)=eβJs1s22cosh⁡(βJ)=σ(2βJs1s2).p(s_2\mid s_1) =\frac{e^{\beta J s_1s_2}}{2\cosh(\beta J)} =\sigma(2\beta J s_1s_2).

    Thus h1=0h_1=0, h2=2βJs1h_2=2\beta J s_1 reproduces the exact joint distribution. Summing over s2s_2 first proves normalization. The correlation is

    ⟨s1s2⟩=∂βJlog⁡[4cosh⁡(βJ)]=tanh⁡(βJ).\langle s_1s_2\rangle =\partial_{\beta J}\log[4\cosh(\beta J)] =\tanh(\beta J).

    Each spin has mean zero, but their nonzero correlation for J≠0J\ne0 shows dependence within a configuration. Repeating the ancestral procedure with independent random numbers produces independent pairs with precisely this internal correlation. Only J=0J=0 makes the two spins independent as well.

    2. A baseline estimated from the same batch

    Let Si=∇θlog⁡qθ(si)S_i=\nabla_\theta\log q_\theta(s_i) and Ri=Rθ(si)R_i=R_\theta(s_i) for BB independent draws. Assume ESi=0\mathbb E S_i=0 and write g=E(RiSi)g=\mathbb E(R_iS_i). Is

    g^=1B∑i(Ri−R‾)Si,R‾=1B∑jRj,\widehat g=\frac1B\sum_i(R_i-\overline R)S_i,\qquad \overline R=\frac1B\sum_jR_j,

    unbiased? Give a corrected baseline construction.

    Solution

    For j≠ij\ne i, independence gives E(RjSi)=ERj ESi=0\mathbb E(R_jS_i)=\mathbb E R_j\,\mathbb E S_i=0. The j=ij=i contribution remains, so

    E(R‾Si)=gB,Eg^=(1−1B)g.\mathbb E(\overline R S_i)=\frac gB,\qquad \mathbb E\widehat g=\left(1-\frac1B\right)g.

    At B=1B=1 the estimator is identically zero, despite a generally nonzero true gradient. For B>1B>1, multiply by B/(B−1)B/(B-1) or use a leave-one-out baseline

    b−i=1B−1∑j≠iRj,g^loo=1B∑i(Ri−b−i)Si.b_{-i}=\frac1{B-1}\sum_{j\ne i}R_j,\qquad \widehat g_{\rm loo}=\frac1B\sum_i(R_i-b_{-i})S_i.

    Each b−ib_{-i} is independent of SiS_i, so its expected contribution vanishes. A separate independent baseline batch also works. A known exact expectation, as in the enumerated training above, is state-independent and needs no such correction. These statements concern unbiased gradients at fixed parameters; they do not prove convergence of a stochastic optimizer.

    References

    • D. Wu, L. Wang and P. Zhang, “Solving Statistical Mechanics Using Variational Autoregressive Networks,” Physical Review Letters 122 (2019), 080602, arXiv:1809.10606v2, main Eqs. (1)–(5), Appendices A–C. The nine-spin fitted benchmark and exact transition-matrix comparison above are calculated here.

    Scrollable formula. Use Left and Right arrow keys to reveal hidden content.

    Scrollable table. Use Left and Right arrow keys to reveal hidden columns.

    Scrollable figure. Use Left and Right arrow keys to reveal hidden content.