5. Single Layer Perceptron (SLP) vs Multi Layer Perceptron (MLP)
Single Layer Perceptron (SLP):
π SLP: The simplest ANN invented by Frank Rosenblatt (1958). Has only ONE layer of neurons (the output layer). Input is directly connected to output neurons. There are NO hidden layers.
Structure: Input Layer β Output Layer (direct connection)
Learning: Perceptron Learning Rule (supervised)
Limitation: Can only solve linearly separable problems (decision boundary must be a straight line/hyperplane)
Single Layer Perceptron:
xβ ββwββββ
xβ ββwββββ€βββ [Ξ£ + f()] βββ output y
xβ ββwββββ€
1 ββb βββ
f(x) = 1 if (Ξ£wα΅’xα΅’ + b) β₯ 0, else 0 (step function)
Linear Decision Boundary (can separate): Cannot separate:
Class A | Class B XOR problem
ββ | ββ β β
β | β β β β
ββββββββββββββββββββββ (not linearly separable!)
SLP β Only works for linearly separable data
Perceptron Learning Algorithm:
1. Initialize all weights wα΅’ = 0 (or small random values), bias b = 0
2. For each training example (x, target):
a. Compute output: y = f(Ξ£wα΅’xα΅’ + b)
b. Compute error: error = target - y
c. Update: wα΅’ = wα΅’ + Ξ± Γ error Γ xα΅’
d. Update bias: b = b + Ξ± Γ error
3. Repeat until error = 0 or max epochs reached
Convergence Theorem: If data is linearly separable, perceptron WILL converge to a solution!
Solved Numerical β SLP Training:
Q: Train a perceptron with Ξ±=1 to implement AND gate. Initial weights wβ=0, wβ=0, bias b=0.
Training data: (0,0)β0, (0,1)β0, (1,0)β0, (1,1)β1
Epoch 1:
Input (0,0), target=0: net=0Γ0+0Γ0+0=0, y=f(0)=0 (step, threshold=0.5), error=0-0=0. No update.
Input (0,1), target=0: net=0Γ0+0Γ1+0=0, y=0, error=0. No update.
Input (1,0), target=0: net=0Γ1+0Γ0+0=0, y=0, error=0. No update.
Input (1,1), target=1: net=0+0+0=0, y=0, error=1-0=1.
wβ=0+1Γ1Γ1=1, wβ=0+1Γ1Γ1=1, b=0+1Γ1=1
Epoch 2 (wβ=1, wβ=1, b=1, threshold at 0.5 β using f(x)=1 if xβ₯ΞΈ=1.5 to get AND):
(Note: For AND gate, perceptron converges β full trace leads to correct weights after a few epochs)
Final for AND gate: wβ=1, wβ=1, b=-1.5 (or ΞΈ=1.5)
Verify: (1,1): 1+1-1.5=0.5β₯0 β 1 β | (1,0): 1+0-1.5=-0.5<0 β 0 β | (0,1): 0 β | (0,0): 0 β
β οΈ XOR Problem β SLP Limitation (Minsky & Papert, 1969):
XOR: (0,0)β0, (0,1)β1, (1,0)β1, (1,1)β0
A single straight line CANNOT separate the 1s from 0s in XOR.
SLP CANNOT solve XOR β this caused the first "AI Winter"!
Solution: Use Multi-Layer Perceptron (MLP) with hidden layers!
Multi Layer Perceptron (MLP):
π MLP: A feedforward ANN with one or more hidden layers between input and output. Each layer is fully connected to the next. Uses non-linear activation functions (sigmoid, ReLU, tanh).
Training: Backpropagation algorithm (forward pass + backward error propagation)
Capability: Can solve ANY problem β linear or non-linear (Universal Approximator theorem)
Multi-Layer Perceptron:
Input Hidden Layer 1 Hidden Layer 2 Output
Layer (Hβ) (Hβ) Layer
xβ βββββββββββββββββββββββββββββ
β± β² β± β² β± β²
xβ βββββββββββββββββββββββββββββββββββ yβ
β² β± β² β± β² β±
xβ βββββββββββββββββββββββββββββ
yβ
bβ β hidden neurons
bβ β output neurons
Forward pass: x β hiddenβ β hiddenβ β output
Backward pass (Backprop): error β output β hiddenβ β hiddenβ β update weights
MLP Architecture β Multiple Hidden Layers
Backpropagation Algorithm (Training MLP):
Phase 1 β Forward Pass:
1. Input fed into network, flows forward layer by layer
2. Each neuron computes: activation = f(Ξ£wα΅’xα΅’ + b)
3. Final output compared with target β compute Error E = Β½Ξ£(target - output)Β²
Phase 2 β Backward Pass:
4. Error propagated backwards through network
5. Gradient of error w.r.t. each weight computed using chain rule
6. Weights updated: w = w - Ξ± Γ (βE/βw)
7. Repeat until error minimized
Time per epoch: O(layers Γ neurons Γ connections)
| Feature | Single Layer Perceptron (SLP) | Multi Layer Perceptron (MLP) |
| Hidden Layers | None β only output layer β | One or more hidden layers β |
| Non-linearity | Cannot learn non-linear patterns β | Can learn any non-linear mapping β |
| Decision Boundary | Linear only (hyperplane) | Non-linear (any shape) |
| XOR Problem | Cannot solve β | Easily solved β |
| Training | Perceptron learning rule | Backpropagation + Gradient Descent |
| Activation | Step function (usually) | Sigmoid, ReLU, tanh (non-linear) |
| Complexity | Simple, fast | Complex, computationally expensive |
| Application | Linearly separable only (AND, OR) | Any problem (XOR, image recognition, NLP) |
| Universal Approximator | No | Yes β |
π‘ Universal Approximation Theorem:
An MLP with at least ONE hidden layer and a non-linear activation function can approximate ANY continuous function to arbitrary accuracy, given enough neurons. This is why MLP/Deep Learning is so powerful!