Implement episodic semi-gradient -step Sarsa with a linear action-value function . The -step return
(the plain return if ) is the target of the update , made at time (or at the end of the episode).
Write semi_gradient_nstep_sarsa(features, transitions, start_state, terminal_states, n, gamma, alpha, epsilon, n_episodes, seed=0, max_steps=10000):
features has shape (n_states, n_actions, d); transitions maps (s, a) to (next_state, reward) (deterministic).start_state; weights start at zero and carry over between episodes.rng = np.random.default_rng(seed) once; for every action choice draw u = rng.random(), and if u < epsilon take int(rng.integers(n_actions)), otherwise the greedy action (lowest index on ties). Choose right after observing , before the update made at time , as in the book's pseudocode.max_steps steps are taken first, treat the last step as terminal (no bootstrapping past it).Return (w, lengths): the final weights and the list of episode lengths in steps.