Computer Engineering 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 learning

Boltzmann learning: how Boltzmann machines (stochastic binary networks) learn by gradient ascent on likelihood, producing a learning rule that is the difference between data-driven and model-driven expectations (positive and negative phase).

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 learning trains stochastic neural networks (Boltzmann machines and Restricted Boltzmann Machines, RBMs). Engineers use it to learn probability models of data (for feature learning, dimensionality reduction and pretraining deep nets) and as a building block in unsupervised pattern-recognition pipelines (see Related topics: Pattern representation and feature extraction; Pattern recognition approaches).

Key ideas

Start with definitions and assumptions in plain English.

  • Boltzmann machine: a network of binary stochastic units (nodes) that have symmetric connections (weights). Each unit can be in state 0 or 1. The network defines a probability distribution over binary states via an energy function.
  • Energy function (E): a scalar function that assigns lower values to more probable configurations. For a general Boltzmann machine with binary units x = (x1,...,xN) the energy is often written as E(x) = -1/2 Σ_i Σ_j x_i W_ij x_j - Σ_i b_i x_i, where W is symmetric and W_ii=0, b_i are biases. (Assumption: units are binary {0,1}. Some texts use {-1,+1}; pay attention to the convention.)
  • Boltzmann distribution: the probability of configuration x is P(x) = exp(-E(x)) / Z, where Z = Σ_x exp(-E(x)) is the partition function normalising the probabilities.
  • Log-likelihood for data: Given training data D = {x^(d)}, the log-likelihood is L = Σ_d log P(x^(d)). Learning aims to maximise L with respect to parameters (weights W and biases b).

Derivation universities expect (gradient of log-likelihood):

  1. Write log-likelihood for a single datum x: log P(x) = -E(x) - log Z.
  2. Differentiate with respect to a parameter θ (element of W or b): ∂/∂θ log P(x) = -∂E(x)/∂θ - ∂/∂θ log Z.
  3. Note ∂/∂θ log Z = (1/Z) ∂Z/∂θ = (1/Z) Σ_{x'} ∂/∂θ exp(-E(x')) = -Σ_{x'} P(x') ∂E(x')/∂θ = -⟨∂E/∂θ⟩_model (expectation under model distribution).
  4. So ∂/∂θ log P(x) = -∂E(x)/∂θ + ⟨∂E/∂θ⟩_model.
  5. Average over data distribution p_data(x) (empirical), we get gradient of expected log-likelihood: ∂⟨log P⟩/∂θ = -⟨∂E/∂θ⟩_data + ⟨∂E/∂θ⟩_model.

Interpretation: learning moves parameters so that model expectations match data expectations. The first term is the positive phase (data-driven), the second is the negative phase (model-driven).

Special case — Restricted Boltzmann Machine (RBM): the network has a visible layer v and a hidden layer h with no intra-layer connections. For binary units the energy is E(v,h) = -Σ_i a_i v_i - Σ_j b_j h_j - Σ_i Σ_j v_i w_ij h_j. Because of the bipartite structure, the conditional distributions factorise: P(h_j=1 | v) = sigmoid(b_j + Σ_i v_i w_ij). This gives an efficient positive-phase computation. The negative phase requires sampling from the full model (often approximated). Symmetrically, P(v_i=1 | h) = sigmoid(a_i + Σ_j w_ij h_j).

Practical approximation: exact negative-phase expectations require summing over exponentially many states. Common approximations: Gibbs sampling (long-run Markov Chain Monte Carlo) or Contrastive Divergence (CD-k), which uses k steps of Gibbs sampling starting from data to approximate the model expectation. CD-1 (one step) is commonly used in practice. Persistent Contrastive Divergence (PCD) maintains persistent model chains across updates to better approximate the model distribution.

Diagram to draw for an exam (exactly what to draw):

  • For RBM: draw two horizontal layers of circles: top labelled "hidden h_j" and bottom labelled "visible v_i". Draw undirected lines between every visible and every hidden unit; label one line w_ij. Put biases a_i next to visible units and b_j next to hidden units. Annotate that there are no visible-visible or hidden-hidden connections (bipartite). For a general Boltzmann machine, draw a small fully connected graph of 4 nodes with symmetric weights on edges and self-biases on nodes.

Where I am unsure: sign conventions and binary-state convention (0/1 vs ±1) vary in texts; check which convention your exam uses.

Formulas

E(v,h) = -Σ_i a_i v_i - Σ_j b_j h_j - Σ_i Σ_j v_i w_ij h_j — E is an energy measured in units of k_B T; with the common convention k_B T = 1, E is dimensionless. Applies to RBM with visible v_i and hidden h_j, biases a_i,b_j, weights w_ij.

P(v,h) = exp(-E(v,h)) / Z — joint probability. Z = Σ_{v,h} exp(-E(v,h)) is the partition function (dimensionless).

P(v) = Σ_h P(v,h) — marginal probability of visible vector v. Equivalently for a binary RBM, the free energy is F(v) = -Σ_i a_i v_i - Σ_j log(1 + exp(b_j + Σ_i v_i w_ij)), and P(v) = exp(-F(v)) / Z.

P(h_j=1 | v) = sigmoid(b_j + Σ_i v_i w_ij) — conditional probability for binary hidden unit given visible vector; also P(v_i=1 | h) = sigmoid(a_i + Σ_j w_ij h_j) — conditional probability for binary visible unit given hidden vector. sigmoid(x) = 1 / (1 + exp(-x)).

∂⟨log P⟩/∂θ = -⟨∂E/∂θ⟩_data + ⟨∂E/∂θ⟩_model — gradient of average log-likelihood with respect to parameter θ.

For weight w_ij in RBM: ∂E/∂w_ij = -v_i h_j, so learning update (stochastic gradient ascent) is Δw_ij = η (⟨v_i h_j⟩_data - ⟨v_i h_j⟩_model) — η is learning rate (dimension: unitless multiplier). Applies under binary {0,1} unit assumption.

Bias updates: Δa_i = η (⟨v_i⟩_data - ⟨v_i⟩_model), Δb_j = η (⟨h_j⟩_data - ⟨h_j⟩_model).

Notes: Expectations are over empirical data distribution (positive phase) and over model distribution (negative phase). All probabilities dimensionless.

Worked examples

Example 1 — small RBM numerical update (complete enumeration). Data: single training vector v = (1,0). Model: 2 visible units v1,v2 and 1 hidden h. Parameters: w1 (between v1 and h) = 0.4, w2 (v2-h) = -0.6, visible biases a1 = 0.2, a2 = -0.1, hidden bias b = 0.0. Learning rate η = 0.1. Units are binary {0,1}.

Step 1: positive-phase expectations. Compute P(h=1 | v) = sigmoid(b + v1w1 + v2w2) = sigmoid(0 + 10.4 + 0(-0.6)) = sigmoid(0.4) = 1/(1+e^-0.4) ≈ 0.5987. So ⟨v1 h⟩_data = v1 * P(h=1|v) = 1 * 0.5987 = 0.5987. ⟨v2 h⟩_data = 0 * 0.5987 = 0.

Step 2: negative-phase expectations by enumerating all 2^3 = 8 states (v1,v2,h). Compute energy E for each state using E = -a1 v1 - a2 v2 - b h - v1 w1 h - v2 w2 h, then compute exp(-E). (I show a summarized table you should write in the answer.) The computed exp(-E) values (rounded):

  1. (0,0,0): 1.000000
  2. (0,0,1): 1.000000
  3. (0,1,0): 0.904837
  4. (0,1,1): 0.496585
  5. (1,0,0): 1.221403
  6. (1,0,1): 1.822119
  7. (1,1,0): 1.105171
  8. (1,1,1): 0.904837 Partition function Z = sum ≈ 8.454952.

Step 3: compute model expectations ⟨v1 h⟩_model = [exp(-E) sum over states with v1=1,h=1] / Z = (1.822119 + 0.904837)/8.454952 ≈ 0.3226. Similarly ⟨v2 h⟩_model ≈ (0.496585 + 0.904837)/8.454952 ≈ 0.1658.

Step 4: weight updates: Δw1 = η(⟨v1 h⟩_data - ⟨v1 h⟩_model) = 0.1*(0.5987 - 0.3226) = 0.02761. Δw2 = 0.1*(0 - 0.1658) = -0.01658.

Final updated weights: w1_new = 0.4 + 0.02761 = 0.42761, w2_new = -0.6 - 0.01658 = -0.61658.

Example 2 — theoretical derivation model answer (exam style). Question: "Derive the learning rule for a Boltzmann machine weight w_ij." Model answer steps: start from log P(x) = -E(x) - log Z; differentiate; show ∂ log Z/∂w_ij = -Σ_x P(x) ∂E(x)/∂w_ij; substitute ∂E/∂w_ij = -x_i x_j (for pairwise connection), get gradient = ⟨x_i x_j⟩_data - ⟨x_i x_j⟩_model; conclude Δw_ij = η(⟨x_i x_j⟩_data - ⟨x_i x_j⟩_model). Provide brief note on implementation: positive term computed by clamping visible to data and sampling hidden; negative term requires sampling from free-running model. In an RBM, the positive-phase correlation can be computed exactly using conditional means: ⟨v_i h_j⟩_data = ⟨v_i P(h_j=1|v)⟩_data.

Common mistakes

  • Thinking positive and negative phases mean good/bad — they are simply data-driven and model-driven expectations.
  • Trying to compute negative-phase expectation exactly for large networks (exponential complexity) without mentioning approximations (Gibbs sampling, CD-k).
  • Using sigmoid formula for RBM conditional probability but applying it with incorrect bias/weight sign.

For your exam

Types of questions:

  • Definitions: define Boltzmann machine, energy function, partition function, positive/negative phase.
  • Short notes: RBM and why it simplifies sampling; Contrastive Divergence algorithm description.
  • Derivations: gradient of log-likelihood to get difference-of-expectations learning rule (full derivation expected).
  • Numericals: small RBM weight updates by enumeration (like Example 1); carry units as dimensionless probabilities.
  • Diagrams: draw RBM bipartite graph and label weights and biases.

What full-marks answers include: clear statement of conventions (binary state and sign), step-by-step calculus for the derivative with justification of moving derivative inside the sum, identification of expectations under data and model, and final update equations. For numericals, show every computed probability, Z, and arithmetic leading to the update.

Quick check

  1. What is the partition function Z?
  2. For RBM binary units, write P(h_j=1|v).
  3. State the weight update Δw_ij in words.

Answers: Z = Σ_{states} exp(-E(state)).; P(h_j=1|v) = 1/(1+exp(-(b_j + Σ_i v_i w_ij))).; Δw_ij = η(times) [data-driven correlation ⟨v_i h_j⟩ minus model-driven correlation ⟨v_i h_j⟩].

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

Stuck on something here?