Implement a single update step of the Deterministic Policy Gradient (DPG) algorithm for continuous-action reinforcement learning.
In many RL problems the action space is continuous, making it impractical to enumerate all actions. The DPG approach maintains a deterministic policy that directly maps states to actions, and updates it by following the gradient of the Q-function through the policy.
Your implementation uses simple linear function approximators:
state_dim entries correspond to state features, and the last entry corresponds to the action).Given a batch of transitions (s, a, r, s', done), implement the following:
Both updates should use the original (pre-update) parameters for their respective gradient computations.
states: np.ndarray of shape (N, state_dim) - batch of state observationsactions: np.ndarray of shape (N,) - actions that were actually takenrewards: np.ndarray of shape (N,) - observed rewardsnext_states: np.ndarray of shape (N, state_dim) - next state observationsdones: np.ndarray of shape (N,) - terminal flags (1.0 if episode ended, 0.0 otherwise)theta: np.ndarray of shape (state_dim,) - policy parametersw: np.ndarray of shape (state_dim + 1,) - critic parametersgamma: float - discount factoralpha_theta: float - policy learning ratealpha_w: float - critic learning rateReturn a tuple (theta_new, w_new) where each is a list of floats rounded to 4 decimal places.