AND Gate (Linearly Separable):
Teach a neural network to mimic an AND gate:
A single neuron with sigmoid activation creates a linear decision boundary.
y = Ï(wâxâ + wâxâ + b)
This creates a straight line that separates the input space into two regions.
Input: [0,0] â Output: 0
Input: [0,1] â Output: 0
Input: [1,0] â Output: 0
Input: [1,1] â Output: 1
xâ
1 | 0 1
|-------
0 | 0 1
+--------
0 1 xâ
XOR Gate (NOT Linearly Separable)
Input: [0,0] â Output: 0
Input: [0,1] â Output: 1
Input: [1,0] â Output: 1
Input: [1,1] â Output: 0
Try to draw ONE line that separates:
- (0,0) and (1,1) â class 0
- (0,1) and (1,0) â class 1
It's impossible! â
xâ
1 | 1 0
|-------
0 | 0 1
+--------
0 1 xâ
Why XOR requires a hidden layer?
How Hidden Layer Solves XOR
The hidden layer creates non-linear transformations that make XOR linearly separable in a higher-dimensional space.
Hidden Neuron 1: hâ = Ï(wââxâ + wââxâ + bâ) # Detects "at least one is 1"
Hidden Neuron 2: hâ = Ï(wââxâ + wââxâ + bâ) # Detects "both are 1"
The Magic:
- hâ learns to fire when either input is 1
- hâ learns to fire when both inputs are 1
- Output combines these to create XOR logic
Why This Matters for Deep Learning
This is the fundamental principle of deep learning:
- Shallow networks can only learn linear patterns
- Hidden layers create non-linear feature transformations
- Each layer learns increasingly complex patterns
Think of it like feature engineering:
- Single neuron: Can only use raw inputs
- Hidden layer: Creates new âfeaturesâ (hâ, hâ) from raw inputs
- Output layer: Uses these engineered features to make decisions
The hidden layer is like having a smart assistant who transforms the problem into something easier to solve!