Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Two layers, and nothing in between
A restricted Boltzmann machine keeps only the connections between a visible layer (the data) and a hidden layer (features); units within a layer do not talk to each other. That restriction makes everything easier: given the data, all hidden units can be sampled at once, and given the hidden units, all visible units can. Training then compares the data with the network’s own reconstruction of it a few steps later, and adjusts the weights to make reconstructions look more like data.
The demo shows why sampling general Boltzmann machines is slow; the RBM’s layered structure and contrastive divergence were the practical answer.
RBMs were the building blocks of the deep belief networks that restarted deep learning in 2006, an early workhorse for collaborative filtering (the Netflix prize) and are still used for representing quantum many-body states. Their training trick, contrastive divergence, is the template for many energy-based learning methods.
- 1. An RBM has connections…
- 2. Given the visible units, the hidden units are…
- 3. Contrastive divergence compares data with…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- Energy: E(v, h) = −bᵀv − cᵀh − vᵀWh.
- Conditionals: p(hⱼ = 1 | v) = σ(cⱼ + (vW)ⱼ) and p(vᵢ = 1 | h) = σ(bᵢ + (Wh)ᵢ). Example: v = (1, 0), W = [[2, 0], [0, 0]], c = 0: p(h) = (σ(2), σ(0)) ≈ (0.881, 0.5).
- Free energy: F(v) = −bᵀv − Σⱼ log(1 + exp(cⱼ + (vW)ⱼ)), and p(v) = exp(−F(v))/Z. With all parameters zero and one hidden unit, F = −log 2.
- CD-k update: ΔW = η(v₀ᵀp(h | v₀) − v_kᵀp(h | v_k))/batch, where v_k is reached by k steps of block Gibbs sampling from the data v₀. Example: v₀ = (1, 0), v₁ = (0, 1), both hidden probabilities 1, η = 0.5: ΔW = (0.5, −0.5)ᵀ.
- Persistent CD (PCD): keep the chains running across updates instead of restarting them at the data.
- 1. p(h₁ = 1 | v) with input 2:
- 2. F(v) with all parameters zero and one hidden unit:
- 3. PCD differs from CD by…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.RBMs in code
Exercise 1. For a 4-visible, 3-hidden RBM, the free-energy formula reproduced the brute-force marginal p(v) for all 16 visible states, and p(h | v) computed by brute force matched the factorised logistic formula.
Practice.
- Initialise weights small (0.01 scale); use mini-batches, momentum and a small weight decay.
- CD-1 is fast and fine for learning features; for density estimation use CD-k with larger k or PCD with a small learning rate.
- Monitor reconstruction error only as a rough guide: it can fall while the likelihood gets worse. For small models, compute the likelihood exactly; for large ones, estimate log Z with annealed importance sampling.
ph0 = sigmoid(v0 @ W + c); v = v0
for _ in range(k): h = rng.uniform(size=ph0.shape) < sigmoid(v @ W + c); v = rng.uniform(size=v.shape) < sigmoid(h @ W.T + b)
W += lr * (v0.T @ ph0 - v.T @ sigmoid(v @ W + c)) / len(v0)- 1. For density estimation prefer…
- 2. Reconstruction error is…
- 3. log Z of large RBMs is estimated by…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Why CD works (approximately). The exact gradient needs ⟨vhᵀ⟩ under the model, which requires a chain run to equilibrium. CD-k approximates it after k steps starting at the data. Hinton (2002) showed CD approximately follows the gradient of KL(p₀‖p_∞) − KL(p_k‖p_∞); it is biased, but the bias shrinks as k grows (Carreira-Perpiñán and Hinton, 2005).
PCD. Tieleman (2008) kept chains alive across updates, so with a small learning rate the chains stay close to the slowly changing model distribution and the gradient estimate is nearly unbiased. With a large learning rate the model changes faster than the chains mix, and the estimate degrades.
Representational power. Adding hidden units can always improve the likelihood, and an RBM with enough hidden units can represent any distribution over binary vectors (Le Roux and Bengio, 2008).
Beyond binary units. Gaussian–Bernoulli RBMs model real-valued data; conditional RBMs model time series; RBM-like networks represent quantum wavefunctions (Carleo and Troyer, 2017).
- 1. CD's bias shrinks as…
- 2. PCD needs a learning rate that is…
- 3. RBMs have been used to represent…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.Comparing training rules exactly
History.
- P. Smolensky (1986) introduced the harmonium.
- G. Hinton (2002) introduced contrastive divergence; T. Tieleman (2008) persistent CD.
- R. Salakhutdinov, A. Mnih and G. Hinton (2007) used RBMs for collaborative filtering.
- G. Carleo and M. Troyer (2017) used them as neural quantum states.
Exercise 2. The 14 distinct 3 × 3 bars-and-stripes images, an RBM with 8 hidden units, 3000 full-batch epochs. With 9 visible units the exact log-likelihood can be computed by enumerating all 512 images. The best possible average log-likelihood is −log 14 = −2.639; a uniform model gives −6.238. Means of three seeds:
| training rule | average log-likelihood |
|---|---|
| CD-1, η = 0.2 | −3.302 |
| CD-10, η = 0.2 | −2.919 |
| PCD-1, η = 0.1 | −3.718 |
| PCD-1, η = 0.2 | −6.662 |
- CD-10 came within 0.28 nats of the best possible model; CD-1 was 0.38 nats worse than CD-10.
- PCD was sensitive to the learning rate: at 0.2 it ended worse than a uniform model; at 0.1 it was stable but behind CD.
- Lesson: exact likelihoods on toy problems reveal biases and instabilities that reconstruction error hides; longer chains give better density models.
RBMs in AI, robotics and aerospace
- Anomaly detection: the free energy of a trained RBM scores how typical an input is; unusual sensor patterns get high free energy.
- Feature learning for small datasets of binary or discretised sensor data.
- Quantum simulation for materials and chemistry uses RBM-style wavefunctions.
References
- G. E. Hinton (2002). “Training products of experts by minimizing contrastive divergence.” Neural Computation 14(8).
- T. Tieleman (2008). “Training restricted Boltzmann machines using approximations to the likelihood gradient.” Proc. ICML.
- M. Á. Carreira-Perpiñán, G. E. Hinton (2005). “On contrastive divergence learning.” Proc. AISTATS.
- G. Carleo, M. Troyer (2017). “Solving the quantum many-body problem with artificial neural networks.” Science 355.