Rumelhart, Hinton and Williams (1986) show that a recurrent network run for synchronous iterations is the same as a layered network with layers of weights, one copy of the recurrent weights per layer. Back-propagation then works on the layered copy, with two provisos: the history of every unit's states must be stored for the backward pass, and the corresponding weights in the different layers must stay equal, so each set of corresponding weights is changed in proportion to the AVERAGE of their derivatives. Compute that average.
Implement iterative_net_gradients(W, b, y0, D).
Network. logistic units. W[j][i] is the weight from unit to unit (any pair, including ) and b[j] is unit 's bias. Starting from the states y0 at time 0, every unit updates at once:
Desired states. D has shape (T, n); D[t-1][j] is the desired state of unit at time , or NaN when there is none. is the number of rows of D (at least 1). The error is
Gradient. In the layered copy, layer holds its own copy of every weight and of every bias, used to compute the states at time . Return the averages over the copies:
Output: a dict {"E": float, "states": S, "dW": G, "db": H} where S is the (T + 1) x n nested list of states , G is the n x n nested list and H is the list .