In a continuing task there are no episodes, so performance is the average reward r(π)=∑sμ(s)∑aπ(a∣s)∑s′,rp(s′,r∣s,a)r, where μ is the steady-state distribution under π. Implement the book's actor–critic with eligibility traces for this setting, in tabular form, on a small deterministic MDP.
continuing_actor_critic(next_state, reward, s0, uniforms, alpha_w, alpha_theta, alpha_rbar, lam_w, lam_theta)
next_state[s, a] (int) and reward[s, a] (float), both of shape (n_states, n_actions), define the MDP. Start in state s0.
- Policy: softmax over preferences θ[s,⋅]. Critic: a table w[s]. Initialise θ, w, Rˉ and both traces to zero.
- One time step per entry of
uniforms. Choose the action by inverse-CDF sampling: A is the smallest a with ∑b≤aπ(b∣S)>u.
- Each step, after observing S′ and R: δ=R−Rˉ+w[S′]−w[S]; Rˉ←Rˉ+αRˉδ; zw←λwzw+∇w[S]; zθ←λθzθ+∇lnπ(A∣S,θ); w←w+αwδzw; θ←θ+αθδzθ; S←S′. Gradients are taken with θ before this step's update.
After the last step, compute the exact average reward r(πθ) of the final policy from its steady-state distribution (assume the chain is ergodic).
Return (theta, w, rbar, r_pi).