PROJECT / 06C++ · Neural-network fundamentals

Building a neural network from scratch in C++

Building the forward and training path directly makes the mechanics behind a classifier inspectable rather than magical.

Role
C++ implementation
Context
Handwritten digit classification
Period
Foundational project
INTERACTIVE EVIDENCE

Trace one prediction.

A feed-forward handwritten-digit classifier implemented from scratch in C++, reconstructed for the browser from its verified architecture.

Explicit browser reconstruction
Input28 × 28
normalized to 0.01–1.00
Hidden100 sigmoid units
select a unit to inspect its weights
Output10 classes
  1. 098.3%
  2. 10.0%
  3. 20.5%
  4. 30.3%
  5. 40.0%
  6. 50.2%
  7. 60.0%
  8. 70.4%
  9. 80.3%
  10. 90.1%
HIDDEN UNIT / 038

What this unit learned to notice

Red weights raise the activation; navy weights suppress it. This view is derived from the separately trained reconstruction, not the lost original model.

prediction0label 0 · 92.6% held-out reconstruction accuracy
THE QUESTION

Parse labelled MNIST rows, normalize 784 input values, learn a hidden representation, and map it to ten class scores without relying on a neural-network framework.

HOW I APPROACHED IT
  1. 01

    Read labelled CSV rows and normalized each pixel into the 0.01–1.00 range used by the source entry point.

  2. 02

    Constructed the verified 784 → 100 → 10 feed-forward architecture.

  3. 03

    Encoded targets at 0.99 for the correct digit and 0.01 for the remaining outputs, then trained and queried the network.

Input28 × 28 pixels
Architecture784 → 100 → 10
Browser demoDeterministic reconstruction
BOUNDARY / LIMITATION

The original neural-network header and trained weights were not retained. The interactive model is a separately trained, explicitly labelled reconstruction matching the architecture visible in the C++ source.

TOOLS & METHODS
  • C++
  • Linear algebra
  • Backpropagation
  • MNIST
  • JavaScript
Inspect the source repository