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.

Perceptron and feed-forward networks

Perceptron is the simplest linear classifier; feed-forward (multi-layer perceptron) networks stack neurons to learn non-linear functions, trained by gradient-based backpropagation.

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

Perceptrons and feed-forward networks are the basic building blocks of deep learning. An engineer uses the perceptron to understand linear classification and uses feed-forward (multilayer perceptron) networks to build function approximators for tasks such as classification and regression before moving to CNNs/RNNs.

Key ideas

  • Decision rule: output y = +1 if w·x + b > 0, and y = −1 otherwise. Draw on paper: a 2D plane, draw a straight line labelled w·x + b = 0; mark two groups of points on opposite sides and label them +1 and −1.

  • Perceptron learning algorithm (PLA): start with initial w and b (often zeros), iterate over training samples (x, y) with y ∈ {+1, −1}. If the current sample is misclassified (y (w·x + b) ≤ 0), update: w ← w + η y x b ← b + η y where η > 0 is the learning rate. Continue until no misclassifications or max epochs.

  • Perceptron convergence theorem (exact university-style statement): If the training set is finite and there exists a vector w* and bias b* such that y_i (w*·x_i + b*) ≥ γ > 0 for all training points (i.e., the data are strictly linearly separable with margin γ), then the perceptron learning algorithm with fixed η > 0 will make a finite number of updates and will find a separating hyperplane. Assumptions: finite dataset, nonzero margin γ, fixed positive η; without loss of generality take ||w*|| = 1 so that γ is the geometric margin. (A standard mistake bound is M ≤ (R/γ)^2, where R = max_i ||x_i||; if you absorb the bias into an augmented weight by appending 1 to x, use R = max_i ||[x_i; 1]||.) Draw diagram for the proof: show current weight vector, true separator, angle decreasing with each update.

  • Limitations of perceptron: can separate only linearly separable datasets. It cannot learn XOR in two dimensions.

  • Feed-forward network / Multilayer Perceptron (MLP): layers of neurons where outputs of one layer are inputs to the next. Each neuron computes z = w·x + b and output a = φ(z) for an activation function φ (e.g., sigmoid, tanh, ReLU). A network with at least one non-linear activation in hidden layers can learn non-linear functions.

  • Universal approximation theorem (informal, exact enough for exams): A feed-forward network with a single hidden layer containing a finite number of neurons and a non-polynomial, continuous activation function (e.g., sigmoid) can approximate any continuous function on a compact subset of R^n to arbitrary accuracy, given enough hidden units. Assumptions: compact domain, continuous target function, suitable activation (nonlinear, e.g., sigmoid). This is an existence result, not a training recipe.

  • Loss and training: define a loss function E (e.g., mean squared error or cross-entropy). Training adjusts weights to minimise E using gradient-based optimisation. For binary classification with sigmoid output y = σ(z) and target t ∈ {0, 1}, the binary cross-entropy is E = −[t ln y + (1 − t) ln(1 − y)]. For multi-class classification with softmax outputs y_k = exp(z_k)/∑_j exp(z_j) and one-hot target t, the cross-entropy is E = −∑_k t_k ln y_k. With these choices, the output-layer gradient simplifies to δ_output = y − t (no φ'(z) factor at the output).

  • Backpropagation (exact chain-rule derivation sketch): for a layered network, compute forward pass to get outputs. For squared error E = 1/2 (t − y)^2 with output y = φ(z), where z = w·h + b and h are hidden activations:

    • Compute ∂E/∂w = ∂E/∂y · ∂y/∂z · ∂z/∂w = (y − t) · φ'(z) · h.
    • Define δ_output = (y − t) · φ'(z). Then ∂E/∂w = δ_output · h.
    • For hidden neuron j with activation h_j = φ(z_j), its error term is δ_j = φ'(z_j) · Σ_k w_kj δ_k (sum over outputs k connected forward). This comes from chain rule: ∂E/∂z_j = Σ_k ∂E/∂z_k · ∂z_k/∂h_j · ∂h_j/∂z_j.
    • Weight update with gradient descent: w ← w − η ∂E/∂w (or equivalently w ← w − η δ · input) and bias update b ← b − η δ.
  • Activation functions (define before use):

    • Step: u(z) = 1 if z > 0 else 0 (used in perceptron with 0/1 labels). For ±1 labels, use the sign function: sign(z) = +1 if z > 0, −1 otherwise.
    • Sigmoid: σ(z) = 1/(1 + e^{−z}). Derivative: σ'(z) = σ(z)(1 − σ(z)).
    • Tanh: tanh(z) = (e^{z} − e^{−z})/(e^{z} + e^{−z}). Derivative: 1 − tanh^2(z).
    • ReLU: φ(z) = max(0, z). Derivative: 1 for z>0, 0 for z<0 (undefined at 0; treat subgradient).
  • Diagram to draw for exam: 3-layer MLP (input, one hidden, output). Label inputs x1..xn, weights w_ij, biases b_j, pre-activations z_j, activations a_j, and show arrows and formula a_j = φ(z_j), z_j = Σ_i w_ji x_i + b_j.

Formulas

y = sign(w·x + b) — y is ±1, w is weight vector (unitless), x is feature vector (unitless). Applies to perceptron decision.

w ← w + η y x — perceptron weight update; η is learning rate (unitless), y∈{±1}, x feature vector. Applies when sample misclassified.

z = w·x + b — linear pre-activation (unitless). Applies to any neuron.

a = φ(z) — activation function applied to z; a is unitless.

E = 1/2 (t − y)^2 — squared error for single output; t is target, y network output (unitless).

∂E/∂w = δ · input where δ = (y − t) φ'(z) for output neuron. Applies in gradient descent/backprop for MLP with given loss and activation.

w ← w − η ∂E/∂w — gradient descent weight update; η > 0 is learning rate.

σ(z) = 1/(1 + e^{−z}) and σ'(z) = σ(z)(1 − σ(z)) — sigmoid and derivative (unitless). Verify values numerically when needed.

Worked examples

Example 1 — Perceptron training (numerical, step-by-step) Data (x in R^2), labels y ∈ {+1, −1}:

  1. x = (2, 2), y = +1
  2. x = (1, −1), y = −1
  3. x = (−1, −2), y = −1
  4. x = (2, 0), y = +1 Initial w = (0, 0), b = 0, η = 1. Use update when y(w·x + b) ≤ 0. Step 1: sample 1: w·x + b = 0 → misclassified. Update: w = (0,0) + 1·(+1)·(2,2) = (2,2), b = 0 + 1 = 1. Step 2: sample 2: w·x + b = 2·1 + 2·(−1) + 1 = 1 → predicted +1, true −1 → misclassified. Update: w = (2,2) + (−1)·(1,−1) = (1,3), b = 1 − 1 = 0. Step 3: sample 3: w·x + b = 1·(−1) + 3·(−2) + 0 = −7 → correct (−1). No change. Step 4: sample 4: w·x + b = 1·2 + 3·0 + 0 = 2 → correct (+1). No change. Check all again: sample 1: 1·2 + 3·2 = 8 (>0) correct. All classified correctly. Final answer: w = (1, 3), b = 0. Bold: w = (1, 3), b = 0.

Example 2 — Forward pass in a small MLP (numerical) Network: 2 inputs → 2 hidden sigmoid units → 1 linear output. Input x = (0.5, −1.5). Hidden neuron 1: weights (0.4, 0.2), bias 0.1. z1 = 0.4·0.5 + 0.2·(−1.5) + 0.1 = 0.0. a1 = σ(0.0) = 0.5. Hidden neuron 2: weights (−0.3, 0.1), bias −0.2. z2 = −0.3·0.5 + 0.1·(−1.5) − 0.2 = −0.5. a2 = σ(−0.5) ≈ 0.37754. Output neuron: weights (0.7, −1.2), bias 0.05 (linear activation). y = 0.7·a1 + (−1.2)·a2 + 0.05 = 0.35 − 0.453048 + 0.05 ≈ −0.053048. Bold: y ≈ −0.0530.

Example 3 — Backprop formula answer (theory long-question model answer) Given one output y = φ(z) with z = w·h + b and squared error E = 1/2 (t − y)^2: using chain rule, ∂E/∂w = (y − t) φ'(z) h. Show steps: ∂E/∂y = y − t, ∂y/∂z = φ'(z), ∂z/∂w = h. Then weight update w ← w − η ∂E/∂w. For hidden layer derive δ_hidden = φ'(z_hidden) Σ_k w_k δ_k and show propagation. End with update expressions for each weight.

Common mistakes

  • Thinking perceptron solves non-linearly separable problems (e.g., XOR).
  • Using sigmoid derivative formula σ'(z) = σ(z)^2 or wrong algebra — correct is σ(z)(1 − σ(z)).
  • For backprop, forgetting to multiply by activation derivative φ'(z) at hidden layers.
  • Not checking convergence condition for perceptron (needs linear separability).

For your exam

Types of questions you will see:

  • Definitions: define perceptron, linear separability, feed-forward network, activation function.
  • Short notes: perceptron learning algorithm, perceptron convergence theorem (state assumptions), universal approximation theorem (informal statement and assumptions).
  • Derivations: show backprop for a 2-layer MLP with squared error; prove perceptron convergence theorem sketch (use margin γ and norm bounds).
  • Numericals: run perceptron updates on a small dataset; compute forward pass of a small MLP; compute gradient update for given small network and one sample.
  • Diagrams: draw a 3-layer MLP and label pre-activations z, activations a, weights and biases.

What a full-marks answer includes: precise definitions with bold terms, clear assumptions for theorems, step-by-step derivations showing chain rule and intermediate partial derivatives, labelled diagram, and a numeric example or final formula with clear symbols.

Quick check

  1. What decision boundary does a perceptron implement?
  2. State the perceptron weight update rule for a misclassified sample (single step).
  3. In backprop, what is the expression for the output error term δ for squared error and activation φ?

Answers: 1) A hyperplane w·x + b = 0. 2) w ← w + η y x and b ← b + η y for y∈{±1}. 3) δ_output = (y − t) φ'(z).

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

Stuck on something here?