Implement a function actor_critic_traces that processes a single episode using the episodic actor-critic algorithm with eligibility traces for both the actor (policy parameters) and the critic (value function parameters).
The environment is tabular with num_states states and num_actions actions.
Critic: The value function is tabular, so v(s, w) = w[s] where w is a 1D array of length num_states.
Actor: The policy uses a softmax over per-state action preferences, so pi(a|s, theta) = softmax(theta[s, :]) where theta is a 2D array of shape (num_states, num_actions).
Inputs:
num_states: Integer, number of statesnum_actions: Integer, number of actionsepisode: List of (state, action, reward, next_state, done) tuplesgamma: Discount factorlambda_w: Trace decay parameter for the criticlambda_theta: Trace decay parameter for the actoralpha_w: Learning rate for the criticalpha_theta: Learning rate for the actorw_init: Initial critic weights, 1D numpy array of shape (num_states,)theta_init: Initial actor parameters, 2D numpy array of shape (num_states, num_actions)Algorithm Details:
I (initialized to 1, multiplied by gamma each step) that weights the policy gradient contributionOutput:
Return a tuple (w, theta) where w is the updated critic weight array and theta is the updated actor parameter array, both as numpy arrays.