-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
In the seminar of week 1, there is a problem: optimization goes up to around -50. You propose the next workaround:
To mitigate that problem, you can either reduce the threshold for elite sessions (duct tape way) or change the way you evaluate strategy (theoretically correct way). For each starting state, you can sample an action randomly, and then evaluate this action by running several games starting from it and averaging the total reward. Choosing elite sessions with this kind of sampling (where each session's reward is counted as the average of the rewards of all sessions with the same starting state and action) should improve the performance of your policy.
I think this will not work. In the video, you compare this problem with a "bandit" that gives you a reward randomly. It is not the Taxi task case, because, despite the random start state, your reward is defined by state and action. So I do not see the point to fix action for a starting point.
I propose a different solution. I agree that in case CEM failed to learn how to win from one distinct starting point, it will simply discard it because no sessions from that starting point will make it into the "elites". So let's take samples from each point into elite samples. To do this, we just calculate the percentile for each state independently instead of a single total percentile.
So, select_elites will look like this:
import pandas as pd
def select_elites(states_batch, actions_batch, rewards_batch, percentile):
df = pd.DataFrame({
'state': np.concatenate(states_batch),
'action': np.concatenate(actions_batch),
'reward': np.concatenate(
[[rewards_batch[i]] * len(states_batch[i])
for i in range(len(rewards_batch))]) # repeat reward len(states) times
})
reward_threshold = df.groupby('state').reward.quantile(percentile / 100)
elite = df.apply(lambda row: row['reward'] > reward_threshold[row['state']], axis=1)
return df[elite].state, df[elite].actionI have also increased n_sessions to 500 to have more samples per state.
As a result, the task converges to a positive score of around 5.