AI Glossary / Probabilistic machine learning / Intermediate

Contrastive divergence

Definition

Contrastive divergence, often abbreviated CD, is an approximate learning method for certain probabilistic models, especially energy-based models such as restricted Boltzmann machines. It contrasts statistics from observed data with statistics from a short Markov chain initialized at those data, avoiding a full equilibrium-sampling calculation at each update.

What it means

An energy-based model assigns relative plausibility through an energy function. Training should make observed patterns more plausible without indiscriminately increasing the plausibility of everything else. Exact likelihood learning therefore involves both observed-data statistics and expectations under the model.
Obtaining representative model samples can be expensive. CD starts from a real training example and runs only a small number of sampling steps. The resulting reconstruction supplies a practical approximation to the model-side comparison. This saves work, but the short-chain distribution usually differs from the model's equilibrium distribution.

How it works

For a restricted Boltzmann machine, begin with a visible training vector. Sample hidden units conditional on that vector, then sample a new visible vector conditional on the hidden state. Repeat for k alternating Gibbs steps in CD-k.
Use the difference between observed-data associations and associations at the chain endpoint to update weights. In a binary RBM, a weight connecting visible unit v and hidden unit h uses a term resembling their data-side average product minus their short-chain average product.
The name also refers to a difference between two Kullback - Leibler divergences: one from the data distribution to the model, and one from the k-step distribution to the model. The usual update omits a parameter-dependence term, so it is not generally the exact gradient of that full contrastive-divergence expression.

Three practical examples

  • Binary-pattern modeling: train a small RBM on co-occurring indicators, checking whether generated patterns reflect more than immediate reconstructions.
  • Feature learning: learn hidden features with an RBM and evaluate them in a downstream task, rather than treating a low reconstruction error as proof of useful representation.
  • Energy-model research: compare short-chain learning with longer-chain or persistent alternatives to understand computation, bias, and sampling behavior.

Think of it this way

Think of an editor comparing a draft with a quickly altered version to identify which local changes make it worse. This can provide useful feedback without exploring every possible document. The analogy is limited: a nearby alteration may miss problems elsewhere. Similarly, a short chain initialized at data can overlook regions where the model assigns unwanted probability.

Worked example

Consider an original RBM with one binary visible unit v and one binary hidden unit h, zero biases, and weight w = log(3). Its joint probability is proportional to exp(wvh). Thus P(h = 1 | v = 1) = 3 / 4, while P(h = 1 | v = 0) = 1 / 2; the visible conditional is symmetric.
Suppose the training distribution always has v = 1. The data-side expected product vh is 0.75. After one Gibbs step, P(v_new = 1) = 0.75 × 0.75 + 0.25 × 0.5 = 0.6875.
Using the hidden conditional at this new visible state, the endpoint expected product is 0.6875 × 0.75 = 0.515625. The expected CD-1 weight direction is therefore 0.75 − 0.515625 = 0.234375.
For comparison, the four equilibrium joint states have unnormalized weights 1, 1, 1, and 3. Their total is 6, so the exact model expectation of vh is 3 / 6 = 0.5. The exact likelihood direction is 0.75 − 0.5 = 0.25. This tiny example explicitly shows the short-chain approximation differs from the exact gradient.

Illustrative case study

Fictional case: Fir Analytics tests an RBM on anonymized binary equipment-status patterns. CD-1 produces improving reconstructions, but longer sampling runs reveal combinations that engineers consider implausible.
The analysts compare additional Gibbs steps and a persistent-chain approach, and evaluate held-out behavior rather than selecting solely by reconstruction error. They also verify the tiny model above by enumeration to test their update code. The case illustrates a diagnostic workflow, not evidence that an RBM or any particular training method is best for equipment monitoring.

Common misconceptions and mistakes

CD is not the same as modern contrastive representation learning with positive and negative example pairs. The shared word “contrastive” does not make their objectives interchangeable.
A one-step reconstruction is not an independent draw from the trained model's equilibrium distribution. Increasing k can improve the approximation when the chain mixes appropriately, but does not automatically solve every learning problem. Reconstruction error is also not likelihood. The usual CD update is generally biased as an estimate of the exact maximum-likelihood gradient.

Business use

Businesses are most likely to encounter CD when reviewing older representation-learning systems, RBM-based tools, or specialized energy models. Understanding it helps assess what a model's training claims actually establish.
Ask how negative samples were obtained, how many transitions were used, and how sampling quality was evaluated. Require metrics appropriate to the intended application. An attractive reconstruction result may be useful, but should not be presented as evidence that the model accurately represents all possible inputs or their probabilities.

People also ask

What does the number in CD-1 mean?

It specifies one full alternating Gibbs step from the data initialization in the standard RBM setting.

Is contrastive divergence exact maximum likelihood?

Generally no. It replaces the equilibrium expectation with a short-chain approximation.

How does persistent contrastive divergence differ?

It maintains sampling chains across updates rather than restarting every chain at a data example, changing the approximation strategy and its practical behavior.

Check your understanding

In the worked example, why does the CD-1 direction differ from the exact likelihood direction even though the arithmetic uses exact expectations?

Answer: The expectations are taken under different distributions. CD-1 uses the one-step endpoint distribution, while exact likelihood uses the equilibrium model distribution. Eliminating Monte Carlo noise does not eliminate that approximation.

Related terms

  • Restricted Boltzmann Machine
  • Energy-based model
  • Gibbs sampling
  • Markov Chain
  • Persistent contrastive divergence
  • partition function
  • maximum likelihood
  • KL divergence

Learn next

Learn the positive and negative terms in an energy-model likelihood gradient. Enumerate a tiny RBM exactly, then compare one-step, multi-step, and equilibrium statistics. Only afterward move to larger models where exact enumeration is unavailable and sampling diagnostics become essential.

More in Probabilistic machine learning

  • Consistent estimator - A consistent estimator is an estimation rule whose output converges in probability to the quantity being estimated as the sample size grows, under stated...
  • Continuous-time normalizing flow - A continuous-time normalizing flow is a generative density model that transforms a simple probability distribution through an ordinary differential equation.
  • Contractive autoencoder - A contractive autoencoder is an autoencoder trained to reconstruct its inputs while discouraging its encoded representation from changing sharply under...
  • Control as inference - Control as inference is a framework that expresses action selection as probabilistic inference in a model linking states, actions, dynamics, and preferences.
  • Correlated topic model - A correlated topic model, or CTM, is a probabilistic topic model that uses a logistic-normal distribution for a document's topic proportions.
  • Coupling flow - A coupling flow is a normalizing flow built from invertible coupling transformations.

Sources

Hinton, “Training Products of Experts by Minimizing Contrastive Divergence,” original author-hosted technical-report version, learning-rule derivation: https://www.cs.toronto.edu/~hinton/absps/tr00-004.pdf Independent source review: Author-hosted report section 3, Gibbs reconstruction procedure and omitted derivative term were read.

Previous: Contrast stretching Next: Contrastive Hebbian learning

  • Home
  • Daily AI Updates
  • Blog
  • AIFBL Academy
  • AI Glossary
  • Products and Tools
  • Store
  • Free CFO AI Prompt Pack
  • About Shihan Sheriff
  • Privacy Policy
  • Terms of Use
  • Refund Policy
  • Cookie Policy
  • Earnings Disclaimer