Paul's Python CoursePPC

Project 8 of 14, for Aaesha

Tide Predictor

A tide forecast from a network with a memory: it reads the river gauge an hour at a time, remembers the hours before, guesses the next, and beats the same-as-last-hour forecast. Then a gate on its memory.

About 2 hours, 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

  • AaeshaThe river path floods at high tide and half the class walks it, which is why we need an hour's warning.
  • NeilI trained a network that reads one hour at a time and remembers, and the weights are in the file.
  • PaulRemembers what, exactly?
  • AaeshaSome of the hours before, and how many is what I want to find out.

In rnn.py, run Neil's recurrent network over the river gauge. load_tides and load_weights are written; readings go in scaled, as (height - MEAN) / SCALE, and guesses come out the same way.

  1. step(x, h, params): one hour. The new hidden state is tanh(x * Wx + h @ Wh + b), and the guess at the next reading is h @ Wy + by, as a plain float. Returns (h, guess).
  2. run(xs, params): every reading in order, starting from a hidden state of zeros. Returns the hidden states, one row per reading, and the guesses, one per reading, as arrays.
  3. forecast(xs, params, hours): run through every reading, then carry on alone, feeding each guess back in as the next reading. Returns hours guesses as an array, the first being the guess after the last reading.
  4. Run as a program, it reports how far out the network is an hour ahead, against "same as last hour", and forecasts the next six hours in metres.
  5. In lstm.py, lstm_step(x, h, c, params): one hour of an LSTM, with a forget gate on its memory.
What it prints
One hour ahead, over 287 hours:
  the network is out by 5.8 cm on average
  "same as last hour" is out by 46.7 cm
Next six hours: 4.01 4.27 4.16 3.72 2.99 2.16

What you learn

What's in it

  1. A network with a memory
  2. What it remembers
  3. One step of the tide network
  4. How Paul would do it
  5. Fix Caitlin's version
  6. Running on its own
  7. An hour ahead
  8. Blame back through time
  9. Blame from twenty hours back
  10. A gate on the memory
  11. A gate on the memory
  12. Neil's sluice
  13. Ship it