Both samplers target the same Ising model on an L × L torus, p(x) ∝ exp(J Σi~j xixj). Gibbs updates one spin from its full conditional σ(2Jηi). Swendsen–Wang adds a bond variable on every edge, switches it on with probability 1 − e−2J when the two spins agree, and gives every connected cluster a fresh random spin. Near and below the critical temperature (J ≥ 0.4407) whole domains flip in one sweep, where Gibbs needs an astronomically long time.
One Gibbs sweep updates the black squares of the checkerboard, then the white ones (each colour class is conditionally independent given the other). One Swendsen–Wang sweep draws all bonds from p(v | x), finds the clusters, and draws every cluster's spin uniformly, an exact draw from p(x | v). Onsager's exact magnetisation of the infinite lattice is (1 − sinh(2J)−4)1/8 for J above 0.4407 and 0 below. Seeded: Reset replays the same run.
code/ch12_mcmc.py (ising_gibbs, swendsen_wang, demo_ising_run); Figure 12.S2 in the code index.