Energy-Based & Boltzmann Machines
Energy-based models replace an explicit density with a scalar energy and a Boltzmann normalization, : simple to specify, but with an intractable partition function . The Boltzmann machine and its restricted variant make the energy bilinear so the hidden units factorize, and contrastive divergence sidesteps by replacing the model expectation with a few Gibbs steps started at the data.
╌╌╌╌
Every generative model so far has paid for tractability with structure. An autoregressive model factorizes into a chain of conditionals; a normalizing flow restricts itself to invertible maps with cheap Jacobians; a VAE optimizes a bound rather than the likelihood itself. Energy-based models make the opposite trade. They specify the density in the most flexible way possible, any scalar function of , and concentrate the entire difficulty in a single intractable normalizing constant.1
The energy and the partition function
An energy-based model assigns each configuration a scalar energy and turns it into a probability by the Boltzmann distribution: exponentiate the negative energy and normalize.
with the integral in the continuous case. The energy is unconstrained: any yields a valid density, because the exponential is positive and rescales it to integrate to one. That freedom is the source of both the model's flexibility and its central difficulty.
Three facts fall straight out of the definition and frame everything below.
| Quantity | Expression | Reading |
|---|---|---|
| Probability | low energy high probability | |
| Log-probability | up to an additive constant | |
| Energy difference | cancels — ratios are free |
The third row is the key fact. Comparing two configurations, scoring, or running a Markov chain that only ever looks at ratios — none of these need . Only an absolute probability, or the likelihood's gradient, requires it.
For example, suppose a model assigns energies and to two configurations. Their probability ratio needs no :
The lower-energy configuration is times more probable — a number we computed without ever summing over the configurations. To turn either into an absolute probability, though, we would need : even for a modest binary vector that is a sum over terms, and the count doubles with every added unit. That gap — cheap ratios, intractable absolutes — is the reason the training methods below exist.
The energy surface is the object to picture. Data modes are basins, regions the model deems probable, carved as wells in ; everything else is a high-energy plateau. The map flips the picture upside down, turning deep wells into tall probability peaks.
The Boltzmann machine
A Boltzmann machine is the energy-based model whose energy is a quadratic form over binary units. Split the units into a visible vector (the data) and a hidden vector (latent features), and the general Boltzmann machine couples every pair of units. The restricted Boltzmann machine (RBM) drops all within-layer couplings, keeping only the visible–hidden weights :
where are the interaction weights and the visible and hidden biases. The joint density is as before. The defining structural fact is that the RBM's interaction graph is bipartite: visible units connect only to hidden units, never to each other.
Conditional independence
The bipartite structure pays off immediately: given the visible units, the hidden units are conditionally independent of one another, and vice versa. This is what makes the RBM practical, so we derive it. Fix and expand the conditional . Every term in the energy that does not involve (namely and the constant ) is absorbed into the normalizer over , leaving
The exponential of a sum factorizes into a product over , and there is no term coupling to , precisely because the RBM has no hidden–hidden edge. Normalizing each factor over gives an independent product of logistic conditionals:
where is the logistic sigmoid. By the symmetry of the energy in and , the same argument run the other way gives with .3
This is the engine of block Gibbs sampling: because a whole layer is conditionally independent given the other, we resample all of at once, then all of at once, alternating — an exact Gibbs sampler whose blocks are entire layers. We lean on this in the negative phase below, and it rests on the Monte Carlo and MCMC machinery.
A worked Gibbs step
For example, take a tiny RBM with visible and hidden units, weights and biases
Clamp a data point and compute the hidden activations. Each hidden unit's input is :
Through the sigmoid, and . Say the Bernoulli draws give . Now sample the visible layer back from this , using :
Suppose these draw to . That single up-then-down pass is one CD-1 step: the reconstruction differs from the data at two coordinates, and the weight update nudges to make the data more probable and the reconstruction less so. The whole layer resampled in one parallel pass, exactly as the factorization allows.
The partition-function problem
To train by maximum likelihood we need the gradient of . Writing the free energy , the marginal is , so . Both pieces depend on . Differentiate:
The second term is where bites. Using and ,
The intractable sum has collapsed into an expectation under the model. Putting the two terms together (with likewise an expectation over the hidden units given the data), the log-likelihood gradient splits cleanly into two pieces of opposite sign:
For the RBM's bilinear energy the abstract gradient becomes concrete. With , the weight update is the difference of two correlation matrices:
The positive phase is cheap: clamp to a data point and use in closed form. The negative phase is the hard one: it needs samples from , which requires running the Markov chain to equilibrium, every gradient step.
Contrastive divergence
The negative phase asks for samples from , and reaching equilibrium can take an enormous number of Gibbs sweeps — far too many to afford on every gradient step. Contrastive divergence (CD-) makes a brutal but effective approximation: instead of running the chain to equilibrium from a random start, start it at the data and run it for only steps (typically ). The data already lives near the modes we care about, so a handful of steps produces a negative sample good enough to estimate the gradient direction.5
The two correlation matrices are then formed from the clamped data (, with its expected hiddens) and from the short-chain sample ( with its hiddens), and the weights step by their difference.
- 1sample from , each
- 2,
- 3for to dosteps of block Gibbs
- 4sample from , each
- 5sample from , each
- 6,the negative sample
- 7data minus model
- 8
- 9
- 10return
The three ways to supply the negative phase trade bias against cost along one axis: how faithfully the chain reaches the model distribution before each update.
| Method | Chain start | Steps per update | Negative-phase quality | Cost |
|---|---|---|---|---|
| Exact MLE | random | run to equilibrium | unbiased | impractical |
| CD- | the data batch | (often ) | biased, short-range | cheap |
| Persistent CD | previous chain state | , never reset | lower bias over time | cheap, less stable |
Deep belief networks and deep Boltzmann machines
Stacking turns a single RBM into a deep generative model. A deep belief network
(DBN) is trained greedily, layer by layer: fit an RBM to the data, freeze it,
treat its hidden activations as the data
for a second RBM, and repeat. Each new
layer models the distribution of the features below it.
A deep Boltzmann machine (DBM) keeps every layer undirected: it is a single energy-based model over all layers at once, , trained jointly rather than greedily. Both drove the 2006–2009 revival of deep learning: greedy RBM pretraining was the first reliable way to initialize deep nets, a story we pick up under representation learning. Modern practice has largely replaced them with directed latent-variable models and better initialization, but the conceptual lineage runs straight through here.6
Directed versus undirected deep generative models
The energy-based family is the undirected branch of deep generative modeling. Set it beside the directed branch (the VAE and its autoregressive kin) and the two trade exactly opposite difficulties.
| Directed (VAE) | Undirected (RBM / DBM) | |
|---|---|---|
| Factorization | ||
| Normalizer | each conditional self-normalizes | one global , intractable |
| Sampling | ancestral, one forward pass | MCMC (Gibbs), iterative |
| Inference | intractable variational bound | exact & factorized (RBM only) |
| Training | maximize the ELBO | CD / persistent CD on the gradient |
| Hard part | the posterior | the partition function |
The directed model self-normalizes but has an intractable posterior, so it leans on approximate inference; the undirected model has an exact, factorized posterior but an intractable normalizer, so it leans on Monte Carlo. Each is tractable exactly where the other is not.
Energy models after the RBM
The RBM and DBM faded from practice, but the energy-based idea did not — it resurfaced with modern neural energies and a new set of tricks for dodging the partition function.
Score matching sidesteps entirely. Hyvärinen's insight was that the gradient of the log-density, , does not depend on because the constant vanishes under the derivative. Fitting this score rather than the density avoids the partition function outright, and denoising score matching made it practical by learning the score of noise-corrupted data.7 This is the direct ancestor of score-based generative models.
Deep EBMs train by short-run MCMC. Replacing the bilinear RBM energy with a convolutional network gives a modern energy-based model over images, trained with Langevin-dynamics sampling in place of block Gibbs — persistent contrastive divergence with a neural energy.8 The negative-phase problem of this lesson is unchanged; only the sampler and the energy parameterization modernized.
The line runs straight into diffusion. A diffusion model learns exactly the noise-conditional score that denoising score matching targets, and sampling by reversing the noising process is Langevin dynamics on a sequence of smoothed energies.9 The partition function that blocked the Boltzmann machine is avoided rather than computed: the score never involves . The undirected, energy-surface picture of generation that began with the Boltzmann machine is, in this sense, the one that prevailed.
Takeaways
- An energy-based model writes with the partition function . Any scalar energy is a valid model; low energy means high probability, and probability ratios are free of .
- The RBM uses the bilinear energy on a bipartite visible–hidden graph. Bipartiteness forces to factorize, enabling parallel block Gibbs sampling.
- The log-likelihood gradient splits into a positive phase (lower energy at the data) and a negative phase that needs samples from the model: the partition-function problem in disguise.
- Contrastive divergence approximates the negative phase with Gibbs steps started at the data; it is biased but carves wells in the right places. Persistent CD improves the estimate by not restarting the chain.
- DBNs stack RBMs greedily; DBMs keep all layers undirected and train jointly. Both seeded deep learning's revival before directed models took over.
- Directed (VAE) and undirected (RBM/DBM) deep generative models trade opposite intractabilities — the posterior versus the partition function.
Footnotes
- Goodfellow, Deep Learning, §16.2.4 — energy-based models: an unnormalized log-density turned into by the Boltzmann normalization. ↩
- Goodfellow, Deep Learning, Ch. 18 — confronting the partition function , the central intractability of undirected models and the reason ratios are cheap but absolute likelihoods are not. ↩
- Goodfellow, Deep Learning, §20.2 — the restricted Boltzmann machine: a bipartite visible–hidden graph whose bilinear energy makes and factorize into logistic conditionals. ↩
- Goodfellow, Deep Learning, §18.1 — the positive/negative phase decomposition of the log-likelihood gradient, lowering energy at the data and raising it under the model's own samples. ↩
- Goodfellow, Deep Learning, §18.2 — contrastive divergence and persistent CD: approximating the negative phase with a few Gibbs steps started at the data rather than running the chain to equilibrium. ↩
- Goodfellow, Deep Learning, §20.3–20.4 — deep belief networks (greedy layerwise RBM stacking) and deep Boltzmann machines (jointly trained, fully undirected), and their role in the deep-learning revival. ↩
- Hyvärinen,
Estimation of Non-Normalized Statistical Models by Score Matching,
JMLR 2005, and Vincent,A Connection Between Score Matching and Denoising Autoencoders,
Neural Computation 2011 — fitting to avoid the partition function. ↩ - Du & Mordatch,
Implicit Generation and Modeling with Energy-Based Models,
NeurIPS 2019 — deep convolutional energy functions trained with Langevin-dynamics negative sampling. ↩ - Song & Ermon,
Generative Modeling by Estimating Gradients of the Data Distribution,
NeurIPS 2019 — score-based generation via denoising score matching and annealed Langevin sampling, the bridge to diffusion models. ↩
╌╌ END ╌╌