RNN backprop thru time(BPTT)

Notes on the math for RNN back propagation through time(BPTT).


\(\hat{y}\) is the prediction.

\(U\) is the weight matrix after the hidden layer.

\[\hat{y} = f_y (U h_t + b_y)\]

\(h_{t}\) is the hidden layer at time t.

\(f_{h}\) is the non linear function in the hidden layer.

\(V\) is the weight matrix before the hidden layer.

\(W_{h_{t-1}}\) is the weight matrix in the hidden layer at the previous time step.

\(b_{h}\) is the bias at the hidden layer.

\[h_{t} = f_{h} (Vx_t + Wh_{t-1} + b_{h})\]

No need to BPTT for this:

\[\frac{\delta L_{t}} {\delta U} = \sum_{i=0}^{T} \frac{\delta L_i} {\delta U} = \frac{\delta L_t} {\delta \hat{y}_t} \frac{\delta \hat{y}_t} {\delta U}\]

BPTT

The loss at time t with respect to the weights in the hidden layer.

The terms in square brackets \([]\) are written in such a way that the leftmost term is the most recent term while the rightmost is the oldest term.

When k = t, the product sequence (or factor) on the left of \(\frac{\delta h_{t}} {\delta W}\), equals 1.

\[\frac{\delta L_{t}} {\delta W} = \frac{\delta L_{t}} {\delta \hat{y}_{t}} \frac{\delta \hat{y}_{t}} {\delta L_{t}} [ (1) \frac{\delta h_{t}} {\delta W} + ( \frac{\delta h_{t}} {\delta h_{t-1}} \frac{\delta h_{t-1}} {\delta W} ) + ( \frac{\delta h_{t}} {\delta h_{t-1}} \frac{\delta h_{t-1}} {\delta h_{t-2}} \frac{\delta h_{t-2}} {\delta W} ) + ... ]\] \[= \frac{\delta L_t} {\delta \hat{y}_t} \frac{\delta \hat{y}_t} {\delta h_t} \sum_{k=0}^{t} [ \frac{\delta h_{t}} {\delta h_{t-1}} \frac{\delta h_{t-1}} {\delta h_{t-2}} ... \frac{\delta h_{k+2}} {\delta h_{k+1}} \frac{\delta h_{k+1}} {\delta h_k} \frac{\delta h_k} {\delta W} ]\] \[= \frac{\delta L_t} {\delta \hat{y}_t} \frac{\delta \hat{y}_t} {\delta h_t} [ \sum_{k=0}^{t} ( \prod_{i=k+1}^{t} \frac{\delta h_{i}} {\delta h_{i-1}} ) \frac{\delta h_k} {\delta W} ]\]
\[\frac{\delta L_{t}} {\delta V}\]

BPTT also needs to be done for calculating the loss with respect to weight matrix V. The dependence between hidden units and weight matrix V is not only in one place. Hidden units from all the previous time steps also depend on V so we need to go backwards in time to calculate this gradient.



2020

PBT for MARL

46 minute read

My attempt to implement a water down version of PBT (Population based training) for MARL (Multi-agent reinforcement learning).

Back to top ↑

2019

.bash_profile for Mac

13 minute read

This post demonstrates how to create customized functions to bundle commands in a .bash_profile file on Mac.

DPPO distributed tensorflow

68 minute read

This post documents my implementation of the Distributed Proximal Policy Optimization (Distributed PPO or DPPO) algorithm. (Distributed continuous version)

A3C distributed tensorflow

26 minute read

This post documents my implementation of the A3C (Asynchronous Advantage Actor Critic) algorithm (Distributed discrete version).

Distributed Tensorflow

76 minute read

This post demonstrates a simple usage example of distributed Tensorflow with Python multiprocessing package.

N-step targets

76 minute read

This post documents my implementation of the N-step Q-values estimation algorithm.

Dueling DDQN with PER

49 minute read

This post documents my implementation of the Dueling Double Deep Q Network with Priority Experience Replay (Duel DDQN with PER) algorithm.

Dueling DDQN

24 minute read

This post documents my implementation of the Dueling Double Deep Q Network (Dueling DDQN) algorithm.

DDQN

29 minute read

This post documents my implementation of the Double Deep Q Network (DDQN) algorithm.

DQN

24 minute read

This post documents my implementation of the Deep Q Network (DQN) algorithm.

Back to top ↑