Skip to content

Capstone 1: gradient checker + PCA compressor

ready≈ 10.5 hoursNeeds: 1.2, 1.3

Part 1 ends by turning two of its ideas into tools you will keep using.

1. A gradient checker for real models. From Part 2 on, a model’s parameters are a dictionary of arrays ({"W1": ..., "b1": ..., ...}). check_gradients(loss, grads, params) returns the relative error for each named parameter, so you can see exactly which gradient is wrong. Every backward pass you write in Parts 2–3 is verified with it, starting with Capstone 2.

2. An SVD image compressor. Compress each colour channel to rank k, rebuild the image, and report the compression ratio and PSNR (peak signal-to-noise ratio, in dB). Find the smallest k that keeps 99% of the energy. The tests check your reconstruction against the Eckart–Young bound from 1.2.

Capstone 1 stubs/cap1_compressor.py

Loading starter file…

Prefer your own editor? Edit exercises/stubs/cap1_compressor.py and run mlc check cap1. The tests are identical; import the results on the progress page.

Hints · check_gradients 0/3 revealed
Hints · reconstruct 0/3 revealed

Then compress your own photo (locally, needs pip install pillow):

Terminal window
cd exercises && python projects/compress_image.py path/to/photo.jpg --energy 0.99

It prints k, the compression ratio and the PSNR, and writes photo_rank{k}.png next to the original.

  • not yet: All tests pass (0/?)
Finish the items above first.
Learner log: time spent and points of confusion

Every confusion you note becomes a fix before the module is marked stable. Export it from the progress page and attach it to an issue.