Module 7 · Recurrent Neural Networks for Time Series Forecasting

Inside the Recurrent Cell

A recurrent network reads a series one step at a time and carries a state: a short list of numbers, its memory. Follow that state through 12 months of the airline data, check one slot's arithmetic by hand, and see why the same network is stuck on raw passenger counts and works once the data is prepared.

Explained in Part 1: dense network vs RNNPart 2: the RNN

What the network reads

One month ahead, every month

Actual passengers The RNN's forecast The 12 months it reads Test year, never seen in training

Click a month to forecast it. The network reads the 12 months before it, one at a time, and the grid below shows what happens inside.

The state, one step at a time 16 slots of memory, 12 steps

One slot, by hand

The new input-
Input partits weight × the input-
State part16 weights × the 16 slots of the previous state, added up-
Bias-
Together-
tanh of that: the slot's new value-

Test year error-average miss, 12 months of 1960
Naive forecast-next month = this month
Slots stuck-at 1 or −1, at every step
Forecast-
-

You have used a recurrent cell before

Simple exponential smoothing keeps one number, the level. The new level is a fraction α of the new observation, plus the rest of the old level. That is a weight times the input, plus a weight times the previous state: the recurrent cell with one slot, no tanh, and the two weights tied together.

Exponential smoothing as a cell

Error on the test year-
Actual passengers The level: its forecast for next month

The same formula, with the limits taken off

Exponential smoothingRecurrent cell
Memory1 number: the levelMany slots (16 here)
Weight on the inputαW, free to learn
Weight on the old state1 − αU, free to learn
SquashingNonetanh, keeps every slot between −1 and 1
Trained toSmooth the seriesDo whatever helps the forecast

Slide α and you are changing both weights at once. An RNN learns its weights separately for every slot, which is why it needs far more data than smoothing does. To explore smoothing on its own, open the simple exponential smoothing tool.

1 · The state is a short list of numbers

Think of each number as a slot of memory. One slot might follow the recent level, one the trend, one the season. Nobody assigns those jobs. Training does.

2 · One formula, used at every step

New state = tanh(W × input + U × old state + bias). The same weights are used for month 1 and month 12. That is why an RNN can read a short window or a long one with the same number of weights.

3 · Big numbers freeze the state

tanh is flat beyond about 3. A raw count like 112, times an ordinary weight, lands far out on the flat part, so every slot answers 1 or −1 whatever the month. Rescale the data, always, with the mean and standard deviation of the training data only.

4 · A trend is a second problem

A state made of numbers between −1 and 1 does not reach far beyond what it saw in training, and the test year is higher than every training year. Taking logs and differences removes the trend, and the same network becomes a good forecaster. Next: how a dense network sees the same data.