def _update(self, state, action, reward, next_state, absorbing):
approximator_idx = 0 if np.random.uniform() < .5 else 1
q_current = self.Q[approximator_idx][state, action]
if not absorbing:
q_ss = self.Q[approximator_idx][next_state, :]
max_q = np.max(q_ss)
a_n = np.array(
[np.random.choice(np.argwhere(q_ss == max_q).ravel())])
q_next = self.Q[1 - approximator_idx][next_state, a_n]
else:
q_next = 0.
q = q_current + self.alpha[approximator_idx](state, action) * (
reward + self.mdp_info.gamma * q_next - q_current)
self.Q[approximator_idx][state, action] = q
评论列表
文章目录