The MCMC methods of §18.2 confront the partition function directly. The methods here sidestep it — they train a model without ever computing . Almost all rest on one observation: in a ratio of probabilities, cancels.
Ratios cancel the partition function (eq 18.17)
| the same intractable normalizer sits in numerator and denominator | scalar | |
| so it cancels — a ratio of UNNORMALIZED probabilities is Z-free and cheap | scalar |
§18.3 Pseudolikelihood
A conditional distribution is a ratio, so it needs no . The pseudolikelihood pseudolikelihood Train by maximizing Σᵢ log p(xᵢ | x₋ᵢ); each conditional is a Z-free ratio (Z cancels), costing k·n instead of kⁿ evaluations; asymptotically consistent. defined in ch. 18 — open in glossary replaces the true joint likelihood with a product of one-variable conditionals:
The pseudolikelihood objective (eq 18.20)
| predict each variable from ALL the others — a Z-free ratio (marginalize only the single variable xᵢ) | conditional | |
| sum over all n variables. Cost: k·n evaluations of p̃ (k values × n variables) instead of the kⁿ needed for Z | n terms |
This is not a hack: maximizing pseudolikelihood is asymptotically consistent. The generalized pseudolikelihood generalized pseudolikelihood Pseudolikelihood with larger left-of-bar index sets S⁽ⁱ⁾, interpolating between pseudolikelihood (singletons) and the full log-likelihood. defined in ch. 18 — open in glossary (eq 18.21) conditions on all-but-a-set , interpolating between pseudolikelihood (singletons) and the full log-likelihood (one set of everything) — useful when structure lets you group correlated variables (e.g. local windows in images). Pseudolikelihood does poorly on tasks needing the full joint (density estimation, sampling) but can beat maximum likelihood on tasks that only use the conditionals it trains (filling in a few missing values). Its Achilles’ heel: sits in a denominator, so a lower bound on (as from variational inference, chapter 19) is useless — it only upper-bounds the objective.
§18.4 Score matching and ratio matching
Score matching score matching Train by matching the model's score ∇_x log p_model to the data's score ∇_x log p_data; since ∇_x Z = 0, Z drops out; needs 1st/2nd x-derivatives (continuous data only). defined in ch. 18 — open in glossary avoids a different way. The score score The gradient field ∇ₓ log p(x) of a log-density. Learning it is one way to learn p's structure: denoising autoencoders estimate it (arrows point uphill toward the data manifold, vanishing at density maxima); score matching proper appears in §18.4. defined in ch. 14 — open in glossary is the gradient of the log-density with respect to the input, — and since does not depend on , : the score is Z-free.
The score-matching objective (eq 18.22)
| the model score — computable from p̃ alone, because ∇_x log Z = 0 | vector (dim n) | |
| the data score — seemingly needs the true p_data, but the expected loss rewrites (eq 18.25) into 2nd derivatives of log p_model only | vector (dim n) | |
| match the two score fields in squared error; minimized when the model's log-density has the same slope everywhere as the data's | scalar |
Matching the slope of the log-density everywhere is matching a vector field — the same field the denoising autoencoder learns (§14.5.1). Revisit it:
Each arrow is the optimal denoising reconstruction minus the input, g(f(x̃)) − x̃ = 𝔼[x | x̃] − x̃ — the center of mass of the clean points that could have produced x̃, minus x̃. It estimates the score ∇ₓ log p(x) (up to a factor σ²): arrows climb toward the manifold and shrink to dots where the estimated density is flat or maximal. Moderate σ: a smooth field pointing cleanly back to the spiral — zeros ON the manifold (density maxima) and between the arms (density minima), long arrows in low-probability gaps where a step uphill gains the most.
Score matching needs first and second -derivatives, so it applies to continuous data only and, like pseudolikelihood, is incompatible with lower bounds on . For binary/discrete data the analogue is ratio matching ratio matching The discrete/binary analogue of score matching, using bit-flip probability ratios (Z cancels); pushes down fantasy states within Hamming distance 1 of the data. defined in ch. 18 — open in glossary (eq 18.26): it compares each data point to its single-bit flips, again cancelling in the ratio, and pushes down every fantasy state within Hamming distance 1 of the data.
§18.5 Denoising score matching
A consistent estimator with enough capacity collapses onto Dirac spikes at the training points. Denoising score matching denoising score matching Score-matching a noise-smoothed data distribution p_smoothed = ∫ p_data(y) q(x|y) dy; equivalent to several autoencoder training objectives (§14.5.1). defined in ch. 18 — open in glossary regularizes this by score-matching a noise-smoothed target instead of the raw empirical distribution:
Smoothing the target (eq 18.27)
| a corruption process — usually add a little noise to each data point y | noise kernel | |
| the blurred data distribution: no longer spikes, so the fitted model generalizes (at the cost of the exact-consistency property of §5.4.5) | density |
This is exactly why several autoencoder objectives (§14.5.1) turn out to be score matching in disguise — training a denoising autoencoder is a way around the partition function.
§18.6 Noise-contrastive estimation
Noise-contrastive estimation noise-contrastive estimation (nce) Learn log p_model = log p̃ + c (c a learned −log Z) by training a binary classifier to tell data from a noise distribution: p_joint(y=1|x)=σ(log p_model − log p_noise). defined in ch. 18 — open in glossary (NCE) makes the normalizer an explicit learned parameter: , with estimated alongside as an approximation of (maximum likelihood couldn’t do this — it would drive ). The trick: reduce density estimation to binary classification of data versus a tractable noise distribution . The optimal classifier turns out to be a logistic regression on the log-density difference:
step 1/4: Bayes with equal priors p(y=1)=p(y=0)=½: the posterior that x came from the model, not the noise.
Fit that classifier by ordinary maximum likelihood and you get a consistent estimator of . Tune the model and watch the classifier — the objective is best exactly when the model matches the data:
NCE trains p_model by making a binary classifier — σ(log p_model − log p_noise) — best separate data from noise. That objective is maximized exactly when p_model matches p_data, so a density-estimation problem becomes a classification problem. (A learned constant c absorbs −log Z, so p_model needn't be normalized.)
NCE shines when there are few variables (even with many values — e.g. a word given its context) but slows on high-dimensional data: the classifier can reject a noise sample by spotting any single wrong variable, so learning stalls once the marginals are right. When the noise distribution is set to the current model before each step, NCE becomes self-contrastive estimation self-contrastive estimation NCE with the noise distribution set to the current model before each step; its expected gradient equals the maximum-likelihood gradient. defined in ch. 18 — open in glossary , whose expected gradient equals the maximum-likelihood gradient. And the idea that “a good generative model should fool a classifier” is one step from generative adversarial networks (§20.10.4).
The Z-confronting toolbox at a glance
| Method | Handles Z by | Discrete data? | Lower-bound p̃ ok? | |
|---|---|---|---|---|
| CD / SML | CD / SML (§18.2) | estimates ∇log Z via model samples | yes | yes |
| Pseudolikelihood | pseudolikelihood | ratios cancel Z | yes | no |
| Score matching | score matching | ∇_x log Z = 0 | no (continuous only) | no |
| Ratio matching | ratio matching | bit-flip ratios cancel Z | yes (binary) | no |
| NCE | noise-contrastive estimation | learns c ≈ −log Z | yes | no |
Check yourself — pseudolikelihood, score matching & NCE
1.What single observation underlies most methods that train undirected models without computing Z?
2.How does pseudolikelihood reduce cost, and what is its main weakness?
3.Why does score matching avoid the partition function, and what does that restrict?
4.In NCE, the optimal data-vs-noise classifier simplifies to which form?
5.Predict the outcome — in NCELab you slide p_model's mean and width to maximize the classifier objective J. Where is J largest?