Total Pageviews

Monday, August 31, 2026

🔢 ANN Example: Handwritten Digit Recognition

🔢 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 Classification

2. Input Handwritten Digit

5 × 7 Pixel Representation
1
1
1
1
1
0
0
0
1
0
0
0
0
1
0
0
0
1
0
0
0
0
1
0
0
0
0
1
0
0
0
1
1
0
0
Target Digit
7
Pixel idea:

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
Input Vector:

X = [1.0, 0.8, 0.6, 0.7]

4. ANN Architecture

INPUT LAYER
X₁ = 1.0
X₂ = 0.8
X₃ = 0.6
X₄ = 0.7
OUTPUT LAYER
Digit 7
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₁ = 1.0
X₂ = 0.8
X₃ = 0.6
X₄ = 0.7

Therefore:

X = [1.0, 0.8, 0.6, 0.7]

2 Assign Weights and Bias

Suppose the hidden neuron responsible for detecting the digit pattern has learned these values:

W₁ = 0.50
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:

Z = X₁W₁ + X₂W₂ + X₃W₃ + X₄W₄ + b

Substitute the values:

Z = (1.0 × 0.50) + (0.8 × 0.40) + (0.6 × 0.30) + (0.7 × 0.20) + 0.10

Calculate each multiplication:

1.0 × 0.50 = 0.500
0.8 × 0.40 = 0.320
0.6 × 0.30 = 0.180
0.7 × 0.20 = 0.140

Now add:

Z = 0.500 + 0.320 + 0.180 + 0.140 + 0.100

Z = 1.240

Therefore: Weighted Sum = 1.240

4 Apply Sigmoid Activation

The sigmoid activation function is:

Sigmoid(z) = 1 / (1 + e-z)

We calculated:

Z = 1.240

Substitute:

H₁ = 1 / (1 + e-1.240)

Approximately:

e-1.240 ≈ 0.289

H₁ = 1 / (1 + 0.289)

H₁ ≈ 0.776

Therefore: H₁ ≈ 0.776

5 Calculate Digit-7 Probability

Suppose the output neuron has:

Output Weight = 1.60
Output Bias = -0.60

First calculate the output weighted sum:

Zout = (H₁ × 1.60) - 0.60

Substitute:

Zout = (0.776 × 1.60) - 0.60

Calculate:

0.776 × 1.60 = 1.2416

Zout = 1.2416 - 0.60

Zout = 0.6416

Apply sigmoid:

P(Digit 7) = 1 / (1 + e-0.6416)

P(Digit 7) ≈ 0.655
Digit 7 Probability ≈ 65.5%

6 Final Digit Recognition

Suppose the classification threshold is:

Threshold = 50%

ANN prediction:

P(Digit 7) = 65.5%

Compare:

65.5% ≥ 50%
🔢 PREDICTION: DIGIT 7

Confidence ≈ 65.5%

Therefore, this simplified ANN recognizes the input pattern as the handwritten digit 7.

6. Complete Image → ANN → Digit Flow

HANDWRITTEN IMAGE

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.

28 × 28
= 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 Prediction

Key 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