🔢 ANN Example: Handwritten Digit Recognition
Understand how an Artificial Neural Network can recognize a handwritten digit using pixel values and step-by-step mathematics.
1. Problem Definition
A computer sees a handwritten digit as an image made up of many pixels. An ANN learns the relationship between these pixel values and the corresponding digit.
For this simple classroom example, we use a small 5 × 7 pixel image instead of a large real dataset.
Image Pixels Input Layer Hidden Layer Output Layer Classification2. Input Handwritten Digit
A pixel can be represented numerically. In this simplified example, 1 means the pixel is active and 0 means the pixel is inactive.
3. Convert Image into Input Values
Instead of using all 35 pixels for the mathematical demonstration, we select four representative pixel features.
| Feature | Pixel Value | Description |
|---|---|---|
| X₁ | 1.0 | Top horizontal stroke |
| X₂ | 0.8 | Upper-right stroke |
| X₃ | 0.6 | Middle diagonal stroke |
| X₄ | 0.7 | Lower diagonal stroke |
X = [1.0, 0.8, 0.6, 0.7]
4. ANN Architecture
Probability
5. Step-by-Step ANN Mathematics
Click each button to understand how the ANN calculates the prediction.
1 Convert Image into Numerical Inputs
The image is represented using numerical pixel features:
X₂ = 0.8
X₃ = 0.6
X₄ = 0.7
Therefore:
2 Assign Weights and Bias
Suppose the hidden neuron responsible for detecting the digit pattern has learned these values:
W₂ = 0.40
W₃ = 0.30
W₄ = 0.20
Bias = 0.10
During actual ANN training, these weights are learned from many labeled training images.
3 Calculate Weighted Sum
The neuron calculates:
Substitute the values:
Calculate each multiplication:
0.8 × 0.40 = 0.320
0.6 × 0.30 = 0.180
0.7 × 0.20 = 0.140
Now add:
Z = 1.240
Therefore: Weighted Sum = 1.240
4 Apply Sigmoid Activation
The sigmoid activation function is:
We calculated:
Substitute:
Approximately:
H₁ = 1 / (1 + 0.289)
H₁ ≈ 0.776
Therefore: H₁ ≈ 0.776
5 Calculate Digit-7 Probability
Suppose the output neuron has:
Output Bias = -0.60
First calculate the output weighted sum:
Substitute:
Calculate:
Zout = 1.2416 - 0.60
Zout = 0.6416
Apply sigmoid:
P(Digit 7) ≈ 0.655
6 Final Digit Recognition
Suppose the classification threshold is:
ANN prediction:
Compare:
Confidence ≈ 65.5%
Therefore, this simplified ANN recognizes the input pattern as the handwritten digit 7.
6. Complete Image → ANN → Digit Flow
↓
5 × 7 PIXEL GRID
↓
PIXEL FEATURE EXTRACTION
X₁ = 1.0
X₂ = 0.8
X₃ = 0.6
X₄ = 0.7
↓
ANN INPUT LAYER
↓
WEIGHTED SUM
Z = (1.0 × 0.50) + (0.8 × 0.40) + (0.6 × 0.30) + (0.7 × 0.20) + 0.10
Z = 1.240
↓
SIGMOID
H₁ ≈ 0.776
↓
OUTPUT NEURON
Zout = (0.776 × 1.60) - 0.60
Zout = 0.6416
↓
FINAL PROBABILITY
P(7) ≈ 0.655
↓
65.5% → DIGIT 7 🔢
7. How Real Digit Recognition Works
In a real handwritten-digit recognition system, the image may contain many more pixels. For example, the popular MNIST dataset uses 28 × 28 = 784 pixels per image.
= 784 input features
Input Layer
↓
Hidden Layer(s)
↓
Output Layer
Output Classes:
0 1 2 3 4 5 6 7 8 9
The output with the highest probability is normally selected as the predicted digit. For a 10-class digit classifier, a softmax output is commonly used rather than a single sigmoid output.
8. Important ANN Terms
Image Pixel Input Feature Input Layer Neuron Weight Bias Weighted Sum Hidden Layer Activation Function Sigmoid Probability Classification PredictionKey idea: An image is converted into numerical pixel values. The ANN multiplies these values by learned weights, adds biases, applies activation functions, and finally produces a prediction.
No comments:
Post a Comment