Skip to content
GATEiit

GATE DA · Machine Learning

Multi-layer perceptron and feed-forward neural networks

From the single perceptron to multi-layer feed-forward networks: activation functions, parameter counts, the forward pass, loss functions and training by backpropagation and gradient descent. GATE asks forward-pass and gradient numericals, parameter counts and XOR-type questions.

Before you start

Concept notes

1. The perceptron and linear separability

A perceptron computes a weighted sum and applies a step (threshold) function: Its decision boundary w⊤x+b=0 is a hyperplane, so it can only separate linearly separable classes.

Perceptron learning rule: for each training point, w←w+η (y−y^) x and b←b+η (y−y^). A correctly classified point causes no change.

Convergence theorem: if the data is linearly separable, the rule finds a separating hyperplane in a finite number of updates. If it is not separable, the weights never settle.

AND, OR and NOT are linearly separable, so one perceptron can compute each. XOR is not: the points (0,1) and (1,0) (output 1) cannot be split from (0,0) and (1,1) (output 0) by one line. A hidden layer solves this.

2. Multi-layer feed-forward networks

A multi-layer perceptron (MLP) has an input layer, one or more hidden layers and an output layer. It is feed-forward: connections go only from one layer to the next, with no cycles. In a fully connected layer every neuron receives every output of the previous layer.

Layer l computes z(l)=W(l)a(l−1)+b(l),a(l)=f(z(l)) with a(0)=x. If layer l has nl neurons, W(l) is nl×nl−1 and b(l) has nl entries.

Parameter count: ∑l(nl−1+1) nl (weights plus one bias per neuron). The input layer has no parameters.

Universal approximation: one hidden layer with enough neurons and a non-linear activation can approximate any continuous function on a bounded region as closely as needed. Deeper networks often need far fewer neurons for the same function.

x1 x2 h1 h2 h3 ŷ inputhidden: f(Wx + b)output
A 2-3-1 feed-forward network: 2×3 + 3 = 9 parameters in the hidden layer and 3×1 + 1 = 4 at the output, 13 in total

3. Activation functions

Activation f(z) Range f′(z)
Sigmoid σ(z)=11+e−z (0,1) σ(z)(1−σ(z)), at most 0.25
tanh ez−e−zez+e−z (−1,1) 1−tanh⁡2z, at most 1
ReLU max⁡(0,z) [0,∞) 1 if z>0, 0 if z<0
Linear z all reals 1

Softmax turns the output scores into class probabilities: y^k=ezk∑jezj; outputs are positive and sum to 1.

Key facts:

  • Non-linearity is essential. If every layer is linear, the whole network is WL⋯W1x, a single linear map, no matter how many layers.
  • tanh⁡(z)=2σ(2z)−1, so tanh is a scaled, zero-centred sigmoid.
  • Sigmoid and tanh saturate: for large ∣z∣ the derivative is near 0, so gradients vanish. ReLU does not saturate for z>0, which is why it is the default in hidden layers.
  • Output layer: linear for regression, sigmoid for binary classification, softmax for multi-class.

4. Loss functions and gradient descent

Training minimises a loss over the training set by adjusting all weights and biases.

  • Regression: squared error L=12(y^−y)2 (the 12 only tidies the derivative).
  • Binary classification: cross-entropy L=−[ yln⁡y^+(1−y)ln⁡(1−y^) ] with a sigmoid output.
  • Multi-class: L=−∑kykln⁡y^k=−ln⁡y^c for the true class c, with a softmax output.

Gradient descent update with learning rate η: w←w−η ∂L∂w.

  • Batch: gradient over the whole training set per step.
  • Stochastic (SGD): one example per step; noisy but cheap.
  • Mini-batch: a small batch per step; the usual choice.

A too-large η makes the loss oscillate or diverge; a too-small η makes training slow. The loss of a network with hidden layers is not convex, so gradient descent may stop at a local minimum or saddle point.

Do not initialise all weights to the same value (for example 0): every hidden neuron then computes the same output and gets the same gradient, so they stay identical (the symmetry problem). Use small random values.

5. Backpropagation

Backpropagation computes ∂L∂w for every weight with the chain rule, working backwards from the output. Define the error of layer l as δ(l)=∂L∂z(l).

  1. Forward pass: compute and store every z(l) and a(l).
  2. Output error: δ(L)=∂L∂a(L)⊙f′(z(L)).
    • Squared error with sigmoid output: δ=(y^−y) y^(1−y^).
    • Cross-entropy with sigmoid, or with softmax: δ=y^−y (the derivatives cancel neatly).
  3. Propagate back: δ(l)=(W(l+1))⊤δ(l+1)⊙f′(z(l)).
  4. Gradients: ∂L∂W(l)=δ(l)(a(l−1))⊤ and ∂L∂b(l)=δ(l).

So the gradient for the weight from neuron j to neuron i is (error at i) × (activation of j).

Vanishing gradients: each layer multiplies the error by f′(z). With sigmoid, f′≤0.25, so after k layers the factor is at most 0.25k and early layers barely learn. ReLU, careful initialisation and normalisation reduce this.

Formulas to remember

Layer computation
a(l)=f(W(l)a(l−1)+b(l))
Parameter countn0 = number of inputs
∑l=1L(nl−1+1) nl
Perceptron rule
w←w+η (y−y^) x
Sigmoid derivative
σ′(z)=σ(z) (1−σ(z))
Softmax
y^k=ezk∑jezj
Cross-entropy loss
L=−∑kykln⁡y^k
Gradient descent
w←w−η ∂L∂w
Backpropagated errorWeight gradient =δ(l)(a(l−1))⊤
δ(l)=(W(l+1))⊤δ(l+1)⊙f′(z(l))

Common mistakes

  • Forgetting the biases when counting parameters: each neuron adds one.
  • Counting parameters for the input layer; it has none.
  • Applying the activation to the output when the question says the output is linear.
  • Writing the perceptron update with the wrong sign: it is +η(y−y^)x, while gradient descent is −η ∂L/∂w.
  • Using δ=y^−y for squared error with a sigmoid output; that shortcut holds for cross-entropy, while squared error keeps the factor y^(1−y^).
  • Initialising all weights to zero, which keeps every hidden neuron identical.

Worked examples

Try each step yourself, then reveal the working.

Example 1: Counting parameters

numerical

A fully connected network has 4 inputs, one hidden layer of 5 neurons and 3 output neurons. Every neuron has a bias. How many trainable parameters are there?

  1. Step 1: Count the hidden layer's weights and biases.

    Try it on paper first.

Example 2: A forward pass with ReLU

numerical

Input x=(1,2). Hidden ReLU neurons: h1=ReLU(x1−x2+0.5), h2=ReLU(0.5x1+x2−1). Linear output y^=2h1+h2+0.5. Find y^.

  1. Step 1: Compute the pre-activations.

    Try it on paper first.

Example 3: XOR with one hidden layer

conceptual

Using step units (step(z)=1 if z≥0, else 0), build a two-layer network that computes XOR of x1,x2∈{0,1}.

  1. Step 1: Write XOR in terms of OR and AND.

    Try it on paper first.

Example 4: One gradient step on a sigmoid neuron

numerical

A sigmoid neuron has w1=0.5, w2=−0.25, b=0. Input (1,2), target y=1, loss L=12(y^−y)2, learning rate η=0.1. Find the updated w1 and w2.

  1. Step 1: Do the forward pass.

    Try it on paper first.

Previous year questions

5 official GATE DA questions on this topic, newest first.

Practise these 5 PYQs →

Topic test

10 questions: up to 4 official PYQs and original practice questions, with GATE marking (MCQ wrong answers lose marks). Score 60% or more to pass. A new set is drawn each time.

Mark as mastered

Loading your progress…

My revision notes

Notes written by the GATEiit team against the official GATE DA syllabus; being checked by a reviewer. Updated 2026-11-21. Spotted a mistake? Use Report an issue on any question, or contact us.