A Hopfield network corrects a noisy pattern by changing its internal state. A Boltzmann machine learns a probability distribution over patterns and can sample from it. An autoencoder learns to turn an input into a code from which it can reconstruct the input.
For a first pass, work through one update in each model with a pencil. Then close the note and explain what is being updated in each case. CT2 Set A tests Hopfield recall, the Hopfield–Boltzmann comparison, sigmoid and autoencoders. CT2 Set B tests the Boltzmann–RBM comparison and sigmoid versus softmax.
1. Hopfield networks and associative recall
A Hopfield network is a recurrent network that acts as an associative memory. You give it a damaged or incomplete version of a pattern. The connections between its units guide their states toward a stable pattern. For example, a network trained on simple binary images can fill in a damaged image if the starting state is close enough to a stored memory.
The classical discrete model uses bipolar states , symmetric connections , and . The weights are fixed during recall. There is no separate clean image to compare against at that stage.
Store a pattern with the Hebbian rule
If two bits agree in a stored pattern, their product is . If they disagree, it is . The Hebbian rule adds those products across memories. With the -th stored pattern, an unscaled version is
Some notes divide by the number of units. Use the convention specified in the question. Once the weights have been built, initialise the network state with the noisy input. For one unit at a time, calculate its local field . A positive field sets , a negative field sets , and a zero field leaves its state as it is. Use the latest available states for subsequent updates. Stop when a full sweep produces no changes.
PYQ — CT2 Set A 2026, Q1(a) · Hopfield simulation (5 marks)
A Hopfield network is a recurrent neural network used as an associative memory. Its neurons have bipolar states . Its connections are symmetric, , and a neuron has no connection to itself, so . The weights store the pattern. During recall, the network starts from a noisy cue and updates the neuron states one at a time.
For a stored pattern , the Hebbian rule is for . The local field of neuron is . A positive field sets to , a negative field sets it to , and a zero field leaves it unchanged. Each update uses the latest states of the other neurons.
For example, take zero biases and store . The resulting weight matrix is
Suppose the noisy cue is . Updating the neurons in the order gives
| Neuron | Local field | State after the update |
|---|---|---|
| 2 | ||
| 1 | ||
| 3 |
The second neuron flips to , and another sweep leaves all states unchanged. Thus the network retrieves the stored pattern from a corrupted cue. With symmetric weights, the energy change of an asynchronous update is . Here the flip gives . Each actual flip lowers the energy until the network reaches a stable state.
Why asynchronous recall settles
The energy measures compatibility with the learned weights. The factor counts each symmetric connection once.
During a single-unit update, stays fixed because . Every change under the rule lowers energy. For the second bit above, . There are finitely many bipolar states, so repeated asynchronous sweeps settle at a fixed point. A fixed point can be another memory or a spurious pattern. The single-unit argument relies on symmetric weights and asynchronous updates.
2. Boltzmann machines
A Boltzmann machine is a stochastic recurrent model. Its visible units represent observed data, and hidden units can represent dependencies that help explain those observations. The symmetric weights and biases define an energy for every joint state of the visible and hidden units. The model prefers lower-energy states through probability.
From energy to a probability
Write here. With temperature , the full-state probability is
The partition function sums over all possible full states so the probabilities add to one. Lowering sharpens the preference for low energy. For a two-unit machine with energies and at , the four unnormalised weights are . Thus and each other state has probability about . Even the most probable state appears less than half the time in this example.
Gibbs sampling and pattern completion
To update one binary unit, hold the others fixed. If , setting to 1 instead of 0 lowers the energy by . Normalising the two possibilities gives
At and , this is . Draw uniformly on . A draw of gives state 1 and a draw of gives state 0. Sweep through the units to sample new configurations. To complete a partial input, clamp the observed bits to their given values and sample the unknown ones.
Learning through two phases
The positive phase clamps the observed training pattern and estimates which units co-activate, averaging over hidden states. The negative phase lets the model run freely and estimates how often the same units co-activate in its own samples. The weight gradient for maximising data log-likelihood at unit temperature is the difference of those correlations.
For correlations and at learning rate , the change is . The connection is strengthened because the model produces that association too rarely. Sampling the model well can be slow when many units interact.
PYQ — CT2 Set A 2026, Q1(a) · Hopfield versus Boltzmann (3 marks)
A Hopfield network is used for associative recall. It starts from an input pattern and updates each neuron deterministically according to the sign of its local field. With symmetric weights and single-neuron updates, every flip lowers the energy, and the state settles at a local minimum.
A Boltzmann machine learns a probability distribution over patterns. A unit with local field takes state 1 with probability in the binary convention. At temperature , it can visit higher-energy states, although lower-energy configurations have greater probability under . It can therefore generate samples or complete missing parts of an observation by holding the known units fixed and sampling the unknown ones.
3. Restricted Boltzmann machines
An RBM is a Boltzmann machine with two layers, visible units and hidden units . Connections go across the layers. If you fix all visible values, the hidden units can be sampled independently in parallel. The same applies to visible units when hidden values are fixed. This property allows alternating block Gibbs sampling. Averaging over the hidden layer can still induce dependencies among visible units.
With visible biases , hidden biases and cross-layer weight matrix :
Worked example — one reconstruction and CD-1 update
Take one hidden unit, input , weights , and zero biases.
- The hidden field is , so . A draw of gives .
- With this hidden state, both visible probabilities are . Draws of and give .
- The new hidden probability is . A draw of gives .
- For the second weight, the data-pair product is and the reconstruction-pair product is . At , this sampled update changes the weight from to . The first weight stays at for these draws.
Contrastive divergence with one Gibbs step (CD-1) uses the short reconstruction chain to approximate the negative phase. A single draw illustrates the update; training averages over examples and repeatedly adjusts the parameters.
PYQ — CT2 Set B 2026, Q1(a) · Boltzmann machine versus RBM (3 marks)
A general Boltzmann machine is a stochastic energy-based network. It can have symmetric visible–visible, hidden–hidden and visible–hidden connections. Because same-layer units can interact, fixing the other layer does not in general make them independent. Sampling the model for learning can therefore be expensive.
A restricted Boltzmann machine (RBM) has visible and hidden layers and allows connections only between them. Given all visible values, the hidden units can be sampled independently. Given all hidden values, the visible units can be sampled independently. The RBM can therefore alternate between updating the whole hidden layer and the whole visible layer. This makes block Gibbs sampling and approximate learning methods such as contrastive divergence practical.
PYQ — 2021–22 semester, Q12 · Define an RBM (2 marks)
A restricted Boltzmann machine is a stochastic energy-based model with a visible layer for the input and a hidden layer for learned features. Its connections run only between visible and hidden units. Fixing one layer therefore makes the units in the other layer conditionally independent, allowing the model to sample the two layers alternately.
4. Sigmoid networks and output probabilities
A sigmoid neuron first forms a score , then outputs
Sigmoid provides a smooth, nonlinear alternative to a hard threshold. In a hidden layer its output is an activation. At a binary classifier’s output, it can represent the estimated probability of class 1. In a Boltzmann unit it gives the probability used for a random draw. The output is at , approaches 1 for large positive scores, and approaches 0 for large negative scores. The derivative becomes small at both extremes, which can make a deep stack of sigmoid layers train slowly.
One learning step. If , , and the target is , then and . For binary cross-entropy, . Thus . With learning rate , the new weight is approximately if we hold the bias fixed. The model increases the score for the desired class on this input.
Connecting sigmoid units. For input , suppose two hidden units have scores and . Their activations are . An output neuron with weights and bias has score and output about . Each layer passes its activations forward, and backpropagation uses the derivatives of both layers to update the weights.
PYQ — CT2 Set A Q1(b) (2 marks) and Set B Q1(a) (2 + 2 marks) · Sigmoid and softmax
Set A, Q1(b), first part. The sigmoid function turns a neuron’s weighted input into a smooth nonlinear activation between 0 and 1. Its derivative allows the activation to be differentiated during backpropagation. In a binary classifier, the output can represent the probability of class 1, with giving the probability of class 0.
Set B, Q1(a), softmax and the comparison. Softmax converts a vector of class scores into a probability distribution. For class ,
For example, scores give
The probabilities sum to one because they share the same denominator. This is appropriate when exactly one class is correct, as in digit classification. A sigmoid acts on one score at a time. Applying two sigmoids to the same scores gives , which need not sum to one. Independent sigmoid outputs are appropriate when several labels can be true at once, such as an image containing both a car and a road.
5. Autoencoders
An autoencoder is a network trained to reconstruct each input. It divides the forward pass into an encoder, which maps the input to a latent code , and a decoder, which maps that code back into input space as . The target is the input itself, so training can use unlabelled examples.
A narrow bottleneck forces the encoder to represent a higher-dimensional input with fewer numbers. Reconstruction loss measures what the code retained. Use mean squared error for real-valued reconstruction or, where appropriate, binary cross-entropy for binary input coordinates. Backpropagation updates both halves through the same reconstruction loss. A high-capacity model can learn an identity mapping, so the bottleneck or a training constraint such as denoising is important when the goal is useful features.
PYQ — CT2 Set A 2026, Q1(b) · The two phases of an autoencoder (5 marks)
An autoencoder is a neural network trained to reconstruct its input. It has two parts, an encoder that maps the input to a latent representation , and a decoder that uses to produce a reconstruction . When the latent layer is smaller than the input, it acts as a bottleneck, so the encoder has to represent the information needed for reconstruction using fewer values.
1. Encoding. The encoder computes , where denotes its weights and biases. For example, let and let the two latent neurons use sigmoid activation. For one set of encoder weights and biases, the latent code is
Thus the encoder represents the three input values with the two numbers .
2. Decoding. The decoder computes , where denotes its own weights and biases. If its three output scores are , and , then
The decoder has expanded the two-value code back into three output values, each corresponding to one input coordinate.
Training. The target is the original input . The mean squared reconstruction error for this example is
Backpropagation sends the loss gradient through the decoder, the latent code and the encoder. Gradient descent updates both sets of weights and biases to reduce the reconstruction error over the training data. Since the inputs supply their own reconstruction targets, separate class labels are unnecessary.
PYQ — 2021–22 semester, Q11 · Define an autoencoder (2 marks)
An autoencoder is a neural network trained to reconstruct its input. Its encoder transforms into a latent code , and its decoder transforms that code back into an approximation . The network learns by minimising a reconstruction loss, such as the mean squared error between and .
6. Closed-book revision
| Given this task | Write or do this first |
|---|---|
| Recall a noisy memory | Set , find the local field and update one unit at a time |
| Sample a binary unit | Turn the local field into , then compare a random draw to that probability |
| Explain why RBM training is easier | Draw two layers and explain what fixing one layer lets you sample |
| Explain a sigmoid or softmax output | Decide whether the probabilities are independent or share one normalising sum |
| Explain encoding and decoding | Draw and show where the reconstruction target comes from |
Try CT2 Set A Q1 without the note. Then answer the Boltzmann, RBM and softmax parts of Set B Q1(a). Replace the initial Hopfield state by and check which field corrects the last bit.





