@ -347,6 +347,11 @@ MyANN = ann(inputNodes, hiddenNodes, outNodes)
```python
# Model Training and Loss Tracking
# Initialize a list to keep track of the loss for plotting
epoch_losses = []
# Iterative training loop
epochs = 5
for e in range(epochs):
@ -355,8 +360,8 @@ for e in range(epochs):
values = record.split(",")
# Input data normalization
data = np.asarray(values[1:], dtype=int)/255*0.99+ 0.01
index = np.asarray(values[0],dtype=int )
data = np.asarray(values[1:], dtype=float) / 255.0 * 0.99 + 0.01
index = int(values[0] )
# Target Vector construction
target = np.zeros(outNodes) + 0.01
@ -371,8 +376,22 @@ for e in range(epochs):
# Train
MyANN.backpropagation(data, target, learningRate)
# Calculate and store the average loss for this epoch
average_loss = total_loss / len(list)
epoch_losses.append(average_loss)
print(f"Epoch {e+1}/{epochs} - Average Loss: {average_loss:.4f}")
# --- Plotting the Learning Curve ---
plt.figure(figsize=(8, 5))
plt.plot(range(1, epochs + 1), epoch_losses, marker='o', color='red', linewidth=2)
plt.title("Training Loss Convergence")
plt.xlabel("Epoch")
plt.ylabel("Average Loss (SSE)")
plt.xticks(range(1, epochs + 1))
plt.grid(True, linestyle='--', alpha=0.7)
plt.show()
```
Epoch 1/5 - Average Loss: 0.0972
@ -382,6 +401,51 @@ for e in range(epochs):
Epoch 5/5 - Average Loss: 0.0361

### Final Trained Weights Extraction
After completing the training epochs, the optimal state of the network is fully captured within its weight matrices ($W_{ih}$ and $W_{ho}$). These resulting numerical arrays act as the permanent "memory" of the model.
```python
# Display the final trained weight matrices
# Displaying only a representative 3x3 slice to keep the notebook clean
print("FINAL WEIGHTS: HIDDEN TO OUTPUT LAYER (Who)")
print(f"Matrix Dimensions: {MyANN.who.shape}")
print("-" * 50)
print(MyANN.who[:3, :3])
print("\n" + "="*50 + "\n")
print("FINAL WEIGHTS: INPUT TO HIDDEN LAYER (Wih)")
print(f"Matrix Dimensions: {MyANN.wih.shape}")
print("-" * 50)
print(MyANN.wih[:3, :3])
```
FINAL WEIGHTS: HIDDEN TO OUTPUT LAYER (Who)
Matrix Dimensions: (10, 100)
--------------------------------------------------
[[-1.67078471 0.15194614 -1.7767362 ]
[ 1.62235502 -1.00391943 -0.37989541]
[-1.26930144 0.42418591 0.62579789]]
==================================================
FINAL WEIGHTS: INPUT TO HIDDEN LAYER (Wih)
Matrix Dimensions: (100, 784)
--------------------------------------------------
[[ 0.46048182 -0.69392989 0.22993549]
[-0.94519842 0.42366932 1.41797905]
[ 0.36351595 -0.27497497 1.32172583]]
## 5. Validation & Inference
Evaluating model performance using unseen test data. A new sample is normalized and processed to extract the final prediction vector, which is then visually compared to the ground truth image.
@ -467,7 +531,7 @@ plt.show()


@ -558,7 +622,7 @@ plt.show()


@ -645,7 +709,7 @@ plt.show()

