Artificial Intelligence & Data Science is coming soon

We're still writing and reviewing the notes for every subject, and we'll open it when every subject is ready. Meanwhile you can practise aptitude, ask Aria about any subject, or see the branches that are ready.

Boltzmann machines and deep belief networks

Boltzmann machines (undirected probabilistic neural networks) model joint distributions using an energy function; Restricted Boltzmann Machines (RBMs) make learning tractable and are stacked to form Deep Belief Networks (DBNs) via greedy layer-wise pretraining.

Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.

Why it matters

Boltzmann machines give a principled probabilistic way to model complex data distributions and latent structure. Engineers use RBMs and DBNs for unsupervised feature learning, pretraining deep networks, density estimation, and as building blocks in generative models and hybrid architectures.

Key ideas

E(x) = - sum_i b_i x_i - sum_{i<j} W_ij x_i x_j. Assumption: pairwise interactions only (no higher-order terms).

  • Probability distribution: The model defines a Gibbs distribution p(x) = (1/Z) · exp(-E(x)/(k_B T)), where Z is the partition function (normaliser), k_B is Boltzmann's constant and T is temperature. In machine learning we usually absorb k_B T into energy units and set k_B T = 1 (dimensionless energy units). Assumption: all states considered in Z; in practice this is intractable for many units.

  • Restricted Boltzmann Machine (RBM): An RBM is a Boltzmann machine with two layers: visible units v and hidden units h, and no intra-layer connections (i.e., no visible-visible or hidden-hidden edges). This conditional independence yields simple sampling formulas (hidden units are independent given visibles, and vice versa). Define biases a (visible) and b (hidden), weight matrix W (visible × hidden).

  • RBM energy: For binary RBM, E(v,h) = - a^T v - b^T h - v^T W h. Assumption: binary variables and pairwise interactions only.

  • Conditional independence in RBM: Because of the bipartite structure, p(h_j = 1 | v) = sigmoid(b_j + sum_i v_i W_ij), p(v_i = 1 | h) = sigmoid(a_i + sum_j h_j W_ij). Where sigmoid(x) = 1/(1+exp(-x)). This is exact for binary units.

  • Learning (maximum likelihood): For data point v^(n) the log-likelihood is log p(v^(n)). The gradient with respect to a weight W_ij is ∂/∂W_ij log p(v) = <v_i h_j>_data - <v_i h_j>_model, where <·>_data is expectation under the posterior p(h|v) (positive phase) and <·>_model is expectation under the model joint p(v,h) (negative phase). The model expectation requires summing over all states → intractable for large models.

  • Contrastive Divergence (CD-k): Practical approximate learning replaces the expensive model expectation by running k steps of Gibbs sampling starting from the training data v^(n) and using the sample after k steps to approximate the negative phase. Common choice k=1 (CD-1). This gives a biased but often effective estimator for the gradient. Algorithm (high level):

    1. Given data v^0, sample h^0 ~ p(h|v^0).
    2. Sample v^1 ~ p(v|h^0).
    3. Optionally repeat up to k steps.
    4. Update weights by η( v^0 (h^0)^T - v^k (h^k)^T ). Assumption: small k and learning rate η; training may require careful choice of hyperparameters.
  • Deep Belief Network (DBN): A generative model formed by stacking RBMs and training them greedily layer-by-layer. The top two layers form an undirected RBM; lower layers form directed generative connections downward. After pretraining, the stack can be fine-tuned by wake-sleep or by gradient-based methods if labels exist. Precise generative process (L layers, visibles v = h^0):

    • Top-level joint p(h^{L-1}, h^{L}) is an RBM (undirected).
    • For l = L-2 down to 0: p(h^l | h^{l+1}) are directed conditional distributions parametrised by weights learned from RBMs. Assumption: greedy layer-wise training gives a good parameter initialisation for deep models.
  • Diagrams to draw in an exam:

    1. For RBM: draw two horizontal layers, bottom labelled "visible v_i", top labelled "hidden h_j". Draw bi-directional lines (or undirected edges) between every visible and every hidden unit. Label weights W_ij on a representative edge, biases a_i and b_j at units.
    2. For DBN: draw multiple layers stacked; indicate training as sequentially training RBM between layers 0–1, 1–2, etc. Mark top-level RBM as undirected, lower-level arrows downward for generative model. Annotate where recognition (upward) uses p(h|v).

Formulas

E(x) = - sum_i b_i x_i - sum_{i<j} W_ij x_i x_j — E(x) is energy (J if using physical units), b_i are biases (J), W_ij are weights (J).

p(x) = (1/Z) * exp(-E(x)/(k_B T)) — p(x) is probability (dimensionless), Z is partition function (dimensionless), k_B = 1.380649e-23 J/K, T is temperature (K). In ML set k_B T = 1 to use dimensionless energies.

Z = sum_x exp(-E(x)/(k_B T)) — partition function (dimensionless), sum over all configurations x.

E(v,h) = - a^T v - b^T h - v^T W h — RBM energy; a_i and b_j are biases (dimensionless if k_B T=1). F(v) = - a^T v - sum_j log(1 + exp(b_j + (W^T v)_j)) — RBM free energy after marginalising h. p(v) = (1/Z) * exp(-F(v)), with Z = sum_v exp(-F(v)) — marginal probability of visibles via free energy.

p(h_j = 1 | v) = sigmoid(b_j + sum_i v_i W_ij) — conditional probability (dimensionless), sigmoid(x)=1/(1+exp(-x)).

p(v_i = 1 | h) = sigmoid(a_i + sum_j h_j W_ij) — conditional probability (dimensionless).

∂/∂W_ij log p(v) = <v_i h_j>_{p(h|v)} - <v_i h_j>_{p(v,h)} — gradient of log-likelihood; expectations are dimensionless. ∂/∂a_i log p(v) = v_i - <v_i>_{p(v)} — visible-bias gradient (single data case). ∂/∂b_j log p(v) = <h_j>_{p(h|v)} - <h_j>_{p(v,h)} — hidden-bias gradient.

ΔW_ij = η ( <v_i h_j>_data - <v_i h_j>_model ) — SGD weight update, η is learning rate (dimensionless). Δa_i = η ( <v_i>_data - <v_i>_model ) — SGD visible-bias update. Δb_j = η ( <h_j>_data - <h_j>_model ) — SGD hidden-bias update.

CD-1 approx: ΔW_ij ≈ η ( v_i^{0} p(h_j=1|v^0) - v_i^{1} p(h_j=1|v^1) ) — contrastive divergence one-step update.

Worked examples

  1. Numerical: small RBM (2 visible, 1 hidden). Given: visible biases a = [0.2, -0.1], hidden bias b = 0.0, weights W = [0.8, -0.5] (W_1=0.8 connects hidden to v1, W_2=-0.5 to v2). All units binary {0,1}. Use k_B T = 1.

Step 1 — compute energies for all (v,h): list v = (0,0),(0,1),(1,0),(1,1) and h=0,1. Use E(v,h) = -a^T v - b h - v^T W h.

  • v=(0,0): E=0 (h=0) and E=0 (h=1).
  • v=(0,1): E(h=0)=+0.1; E(h=1)=+0.6.
  • v=(1,0): E(h=0)=-0.2; E(h=1)=-1.0.
  • v=(1,1): E(h=0)=-0.1; E(h=1)=-0.4.

Step 2 — compute partition function Z = sum_{v,h} exp(-E(v,h)). Evaluating numerically gives Z ≈ 9.99033.

Step 3 — compute conditional p(h=1 | v) via sigmoid:

  • p(h=1|v=(1,0)) = sigmoid(0.8) ≈ 0.689974.
  • p(h=1|v=(1,1)) = sigmoid(0.3) ≈ 0.574443.

Step 4 — compute exact gradient for weight W_1 for a single training example v_data = (1,0):

  • Positive phase <v1 h>_data = v1 * p(h=1|v) = 1 * 0.689974 = 0.689974.
  • Negative phase <v1 h>model = sum{v,h} v1hp(v,h). Only states with v1=1 and h=1 contribute: P(v=(1,0),h=1)=2.718282/9.99033≈0.2720; P(v=(1,1),h=1)=1.491825/9.99033≈0.1493. Sum ≈ 0.4213.
  • Gradient = 0.689974 - 0.4213 = 0.2687.

Step 5 — update with η = 0.1: ΔW_1 = 0.02687. New W_1 ≈ 0.82687.

(All exponentials and divisions checked; numbers rounded to 6 decimals where shown.)

  1. Theory: Derive gradient of log-likelihood for RBM weight W_ij (model answer expected in exam):
  • Start: p(v) = (1/Z) sum_h exp(-E(v,h)). Take log and derivative: ∂ log p(v)/∂W_ij = (1/p(v)) * (1/Z) * sum_h [ exp(-E(v,h)) * ( -∂E(v,h)/∂W_ij ) ] - (1/Z) * sum_{v',h'} [ exp(-E(v',h')) * ( -∂E(v',h')/∂W_ij ) ] .
  • Simplify first term to expectation under p(h|v): < -∂E/∂W_ij >{p(h|v)} and second term to expectation under p(v,h): < -∂E/∂W_ij >{p(v,h)}.
  • For RBM, -∂E/∂W_ij = v_i h_j, so gradient = <v_i h_j>{p(h|v)} - <v_i h_j>{p(v,h)}.
  • This is the positive minus negative phase. End.
  1. Model-answer explanation: describe greedy layer-wise pretraining for DBN (steps, motivation, and one drawing): expected to include RBM training between successive layers, how hidden activations of one layer become data for next RBM, and that top-level is RBM while lower levels are directed generative.

Common mistakes

  • Treating RBM conditional independence as approximate — it is exact (given the bipartite structure).
  • Confusing CD-k with true likelihood gradient: CD is an approximation and biased for finite k.
  • Forgetting to set k_B T = 1 when using standard ML formulas; units mismatch causes confusion.
  • Expecting tractable exact model expectations for large RBMs — they are intractable without approximation/sampling.

For your exam

Types of questions you will see: definitions (define RBM, energy, partition function), short notes (contrastive divergence, Gibbs sampling), derivations (derive gradient of log-likelihood), numericals (small RBM probabilities and a weight update), diagrams (sketch RBM/DBN and label), and conceptual (compare RBM vs Boltzmann machine, why greedy pretraining works).

What full-marks answers include:

  • Precise definitions with assumptions (binary units, k_B T convention).
  • Exact formulas (energy, p(x), partition function) and units or statement k_B T = 1.
  • Step-by-step derivations for gradients, showing expectations and where approximation enters.
  • For numerical questions: show all state energies, partition function computation, conditional probabilities, expectations, and final numeric update with units/dimensionless clarification.
  • Diagrams: layers, labels (v_i, h_j, W_ij, biases) and arrows or undirected edges as appropriate.

Quick check

  1. In an RBM, are hidden units conditionally independent given visibles? 2) Write the RBM conditional p(h_j=1|v). 3) In the gradient ∂ log p(v)/∂W_ij, which two expectations appear?

Answers: 1) Yes. 2) p(h_j=1|v)=1/(1+exp(-(b_j + sum_i v_i W_ij))). 3) The data (positive) expectation <v_i h_j>{p(h|v)} and the model (negative) expectation <v_i h_j>{p(v,h)}.

Finished this topic? Mark it so your progress, study plan and readiness keep up.

Stuck on something here?