Pygame visualization of a neural network while it trains on MNIST.
The window shows the graph on the left (nodes, edges, live weights) and a sidebar on the right with the current prediction, the actual digit, and training accuracy. The trainer is a small fully connected network written in NumPy; a separate PyTorch MNIST classifier lives in the same repo for comparison.
- Layered graph of nodes and edges (
784 → 10 → 10) - Weights drawn inside nodes and updated as training runs
- Output node highlighted for the model's current prediction
- Sidebar: predicted digit, actual digit, and accuracy
- Pan and zoom the graph (mouse-centered zoom)
- One gradient-descent step about once per second
Visualizer (package/sim): Network owns Layers of Nodes connected by Edges. Camera pan/zoom maps world coordinates to the screen.
From-scratch trainer (package/mnist): two-layer network (784 → 10 ReLU → 10 softmax), forward pass, backprop, and gradient descent in NumPy. Simulation copies averaged weights onto the graph and runs one training step per second.
PyTorch (package/pytorch): a 784 → 128 → 64 → 10 MLP trained with Adam, plus a short tensor tutorial.
- Python 3.10+
- Windows for the main sim (
pywinstylesis used for the window title bar) - MNIST
train.csvfrom Kaggle Digit Recognizer
Place the CSV at:
package/data/train.csv
From the repository root:
python -m venv .venv
.venv\Scripts\activate
pip install pygame pywinstyles numpy pandas matplotlibOptional, for the PyTorch scripts:
pip install torch torchvisionAlways run from the repository root so package/ imports and package/data/train.csv resolve.
Simulation (NumPy trainer + Pygame):
python -m package.sim.mainPyTorch MNIST classifier:
python -m package.pytorch.mnist_classifierCamera pan/zoom sandbox (no network):
python -m package.sim.test_camera| Input | Action |
|---|---|
| Left-drag on the graph | Pan |
| Mouse wheel | Zoom toward the cursor (1×–10×) |
R |
Reset pan |
0 |
Reset zoom to 1× |
package/
sim/ Pygame graph, camera, and main loop
mnist/ NumPy MNIST trainer (forward, backprop, GD)
pytorch/ PyTorch classifier and tensor notes
data/ train.csv (not committed; download from Kaggle)