Sutton & Barto represent a state with numbers by the order- polynomial basis: one feature for every exponent vector with each ,
which gives features, including the constant feature 1 (all exponents zero).
Write two functions.
polynomial_basis(s, n) returns the feature vector for a state s (a 1-D array of length ) as a 1-D float array. Order the exponent vectors lexicographically with the last dimension varying fastest (like counting in base ), so for the order is . Treat as 1.
gradient_mc_poly(samples, n, alpha, n_passes) fits a linear value function with this basis by the gradient Monte Carlo update . samples is a list of (s, G) pairs (state array, observed return). Start from and apply the update to the samples in order, repeating the whole list n_passes times. Return .