Implement the episodic semi-gradient Sarsa algorithm with linear function approximation for estimating action-value functions from pre-collected episodes.
In this setting, instead of maintaining a table of Q-values, the action-value function is approximated as a linear combination of features:
Q(s, a) = w^T * x(s, a)
where w is a weight vector and x(s, a) is a feature vector for the state-action pair (s, a).
Given a list of episodes (each a list of (state, action, reward) tuples), a feature mapping from (state, action) pairs to feature vectors, a learning rate alpha, and a discount factor gamma, process each episode sequentially and update the weight vector using the Sarsa temporal-difference update rule with linear function approximation.
For each transition within an episode, the weight vector should be updated using the TD error computed from the current and next state-action pairs. At the terminal step of each episode (the last tuple), there is no next state-action pair, so the bootstrapped value is zero.
Args:
Returns: