Foundations to Frontier
Tests
E. Deep Learning › E6 Early and Energy-Based Networks

The Boltzmann Machine

A Boltzmann machine is a stochastic Hopfield network: binary units switch on with a probability given by a logistic function of their input, so the network samples states from a Boltzmann distribution p(s) ∝ exp(−E(s)). Hidden units let it model dependencies that no pairwise model of the visible units can, and its learning rule compares correlations under the data with correlations under the model. This page covers the energy, Gibbs sampling, the learning rule, the role of hidden units, and why exact learning is impractical. In the exercises you show Gibbs sampling reproduces the exact distribution, then train exactly on 3-bit parity and find a visible-only machine is stuck at the uniform distribution (KL = log 2), while hidden units let it capture the third-order structure.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

A network that dreams up likely states

A Boltzmann machine is like a Hopfield network whose neurons are a little random. Instead of always switching to whatever their inputs say, they switch on with a probability that rises with the input. Run it for a while and it wanders through states, visiting each in proportion to how “comfortable” (low-energy) it is. Training adjusts the connections so that the states it visits look like the training data. Hidden units, which are never shown data, let it capture patterns that involve many units at once.

Gibbs sampling a 4-unit Boltzmann machine
0000000100100011010001010110011110001001101010111100110111101111
KL(sample ‖ exact) = 0.015 · switches between all-down (0000) and all-up (1111): 54
Outlines: exact probabilities of the 16 states; filled bars: fraction of sweeps the chain spent in each. With weak coupling the chain mixes quickly and the histogram matches. With strong coupling at low temperature the two aligned states dominate and are separated by improbable states, so the chain rarely switches: after a few hundred sweeps it may never have visited one of them. That slow mixing is why exact Boltzmann-machine learning is impractical and why RBMs use contrastive divergence.
Why engineers care

Boltzmann machines are the ancestors of energy-based and generative models; Geoffrey Hinton shared the 2024 Nobel Prize in Physics partly for them. Their difficulties (sampling that mixes slowly, intractable normalisation) explain why later generative models use restricted architectures, contrastive divergence, variational methods or diffusion.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Boltzmann machine units switch on…
  2. 2. Low-energy states are visited…
  3. 3. Hidden units let the model capture…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Energy: E(s) = −½sᵀWs − bᵀs for binary s, symmetric W, zero diagonal. Example: s = (1, 1), W = [[0, 2], [2, 0]], b = (0.5, −1): E = −2 + 0.5 = −1.5.
  • Distribution: p(s) = exp(−E(s)/T)/Z. Energies 0 and log 3 at T = 1 give probabilities 0.75 and 0.25.
  • Gibbs update: p(sᵢ = 1 | rest) = σ((Σⱼ Wᵢⱼsⱼ + bᵢ)/T). With input 2 at T = 1: σ(2) ≈ 0.881.
  • Learning rule: ∂log p(data)/∂Wᵢⱼ = ⟨sᵢsⱼ⟩_data − ⟨sᵢsⱼ⟩_model. The first average has visible units clamped to data and hidden units sampled; the second runs the network freely. Example: 0.7 − 0.4 = 0.3.
  • Cost: n units have 2ⁿ states (1024 for 10, 2¹⁰⁰ for 100), so Z and the model average must be estimated by sampling.
📝 Quick check (Level 1)
0/3 answered
  1. 1. Probabilities for energies 0 and log 3:
  2. 2. Weight gradient for data correlation 0.7, model 0.4:
  3. 3. States of 10 binary units:

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

Boltzmann machines in code

Exercise 1. A 4-unit machine with random weights was Gibbs-sampled for 40 000 sweeps; the sampled frequencies of the 16 states matched the exact probabilities to within 0.002, with KL below 10⁻³.

Practice.

  • General Boltzmann machines are rarely trained today: the free-running statistics need long Gibbs chains that mix slowly when weights are large (see the demo).
  • Restricting the connectivity (no visible–visible or hidden–hidden links) gives the RBM (E6-9), whose conditionals factorise and which trains with contrastive divergence.
  • Persistent chains, parallel tempering and annealed importance sampling are the standard tools for sampling and estimating Z.
for i in range(n):                                     # one Gibbs sweep
    s[i] = rng.uniform() < 1 / (1 + np.exp(-(W[i] @ s + b[i])))
🐍 Exercise 1: Gibbs sampling matches the exact distribution
Enumerate a 4-unit Boltzmann machine's distribution and compare it with the state frequencies of a long Gibbs chain.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Gibbs chains mix slowly when…
  2. 2. Restricting connectivity gives…
  3. 3. Parallel tempering helps by…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

The learning rule. log p(v) = log Σₕ exp(−E(v, h)) − log Z. Differentiating, ∂/∂Wᵢⱼ gives ⟨sᵢsⱼ⟩ under p(h | v), minus ⟨sᵢsⱼ⟩ under p(v, h). Averaged over data, this is the difference between clamped (“wake”) and free (“sleep”) correlations: Hebbian learning on data and anti-Hebbian unlearning on the model’s own fantasies.

Maximum entropy. A visible-only Boltzmann machine is the maximum-entropy distribution matching the data’s means and pairwise correlations. If the data’s structure lies in higher-order correlations, as in parity, whose pairwise statistics are those of the uniform distribution, no visible-only machine can do better than uniform.

Hidden units. Marginalising hidden units yields effective higher-order interactions among visibles. With enough hidden units, Boltzmann machines (even RBMs) can approximate any distribution over binary vectors (Le Roux and Bengio, 2008).

Intractability. Both Z and the free-phase statistics are sums over exponentially many states; sampling them by Gibbs chains is slow when the distribution has well-separated modes. This drove the move to RBMs and contrastive divergence.

📝 Quick check (Level 3)
0/3 answered
  1. 1. The free-phase correlations act as…
  2. 2. A visible-only BM is the max-entropy model matching…
  3. 3. Even parity's pairwise statistics equal those of…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

Why hidden units matter

History.

  • D. Ackley, G. Hinton and T. Sejnowski (1985) introduced Boltzmann machines and their learning rule.
  • P. Smolensky (1986) introduced the harmonium (the RBM).
  • R. Salakhutdinov and G. Hinton (2009) trained deep Boltzmann machines.
  • G. Hinton shared the 2024 Nobel Prize in Physics with J. Hopfield.

Exercise 2. Data: the four 3-bit strings with even parity, each with probability ¼. Boltzmann machines with 3 visible units and 0–3 hidden units, trained by exact gradient ascent (all states enumerated, 4000 steps, three seeds):

hidden units KL(data ‖ model)
0 0.6931 (= log 2)
1 0.1205
2 0.1022
3 0.0469
  • Without hidden units the machine learned exactly the uniform distribution (KL = log 2), because parity’s means and pairwise correlations are the uniform distribution’s.
  • Hidden units captured the third-order structure; three cut the KL to 0.05 within the training budget.
  • Note: from very small initial weights (scale 0.1) every machine stayed at log 2: the parity gradient vanishes at that symmetric starting point, and weights of scale 1 were needed to break the symmetry.
🐍 Exercise 2 (research): why hidden units matter
Train Boltzmann machines with 0–3 hidden units exactly on 3-bit even-parity data and compare the KL divergence achieved.

Boltzmann machines in AI, robotics and aerospace

  • Energy-based models for anomaly detection score inputs by energy; unusual telemetry gets high energy.
  • Combinatorial optimisation by simulated annealing samples a Boltzmann distribution while lowering the temperature, used for scheduling and planning.
  • Physics links: Ising models, quantum annealers and Boltzmann sampling hardware share the same mathematics.

References

  1. D. H. Ackley, G. E. Hinton, T. J. Sejnowski (1985). “A learning algorithm for Boltzmann machines.” Cognitive Science 9(1).
  2. N. Le Roux, Y. Bengio (2008). “Representational power of restricted Boltzmann machines and deep belief networks.” Neural Computation 20(6).
  3. R. Salakhutdinov, G. Hinton (2009). “Deep Boltzmann machines.” Proc. AISTATS.
  4. S. Kirkpatrick, C. D. Gelatt, M. P. Vecchi (1983). “Optimization by simulated annealing.” Science 220.