Paul's Python CoursePPC

Project 7 of 14, for Neil

Seeing Forecaster

A network that forecasts the seeing for Neil's stargazing nights from the weather, taught not to memorise: Riya's fits 24 nights perfectly and the rest badly, until weight decay, dropout, early stopping and batch norm teach it to hold back.

About an hour and a half, in 14 steps.

Sign up free to open itLog in

Act 7 needs a free account, so your work is saved as you go. Act 1 is open to everyone.

The brief

  • NeilBefore every stargazing night I rate the seeing, which is how much the stars shimmer, in arcseconds.
  • RiyaI've trained a network on it and the training loss is zero.
  • NeilOkay, and on the nights it hasn't seen?

In regular.py, add three regularisers to the seeing network in net.py, and compare them on the nights it never learnt from.

  1. dropout_mask(shape, rate, rng): an array of that shape in which each entry is 0 with chance rate, and otherwise 1 / (1 - rate).
  2. with_weight_decay(grads, params, decay): a new dict of gradients, with decay times each weight matrix added to its gradient. The biases, b1 and b2, are left alone.
  3. train(X, T, X_val, T_val, params, rate, epochs, decay=0.0, drop=0.0, patience=None, seed=0): gradient descent that changes params in place. Each epoch: a fresh dropout mask for the hidden layer if drop is above 0, one step with weight decay, then the training and validation losses with no mask. With patience, stop once the validation loss hasn't improved for patience epochs, and put the best epoch's weights back. It returns the training losses, the validation losses and the best epoch.
  4. Run as a program, it compares Riya's network with each regulariser.
  5. In batchnorm.py, batch_norm for training and for evaluation.
What it prints
                      training  validation
Riya's                  0.0000      0.2455
weight decay 0.02       0.0451      0.1340
dropout 0.5             0.0106      0.1890
early stopping          0.0603      0.1842
Guessing the average                0.4213

What you learn

What's in it

  1. Perfect, on paper
  2. Stop while it's best
  3. How Paul would do it
  4. Fix Riya's version
  5. Rent on every weight
  6. A weight nobody needs
  7. Half asleep, on purpose
  8. Half asleep
  9. Three ways to hold back
  10. Every neuron on one scale
  11. An average evening
  12. Batch norm, properly
  13. Ship it