Linear gradient Monte Carlo (LMS) applies one update per step of an episode, but every update needs the final return , so the feature vectors must be stored until the episode ends:
Sutton and Barto show that the same final weights can be produced with two running vectors and work per step, without storing any feature vectors. Define the fading matrix and
so that . The vector is a dutch trace.
Implement dutch_mc(w0, X, G, alpha):
w0: initial weights, shape (d,).X: the feature vectors as an array of shape (T, d), .G: the return, a single number observed at the end of the episode (no discounting).Process the steps in order, maintaining and incrementally (never forming a matrix), and return the tuple (w_T, z_{T-1}, a_{T-1}) as float arrays.