Artificial Intelligence, Data Science, Machine Learning, Reinforcement Learning, Programming.
= np.zeros_like(rewards) running_total = 0 for i in reversed(range(len(rewards))): running_total = running_total * discount_factor + rewards[i] discounted_rewards[i] = running_total # Normalize the discounted rewards discounted_rewards -= np.mean(discounted_rewards) discounted_rewards /=