Skip to content

Instantly share code, notes, and snippets.

@pyliaorachel
Created June 3, 2018 09:03
Show Gist options
  • Select an option

  • Save pyliaorachel/d0827a23828f925c49cea0100bcd4cf6 to your computer and use it in GitHub Desktop.

Select an option

Save pyliaorachel/d0827a23828f925c49cea0100bcd4cf6 to your computer and use it in GitHub Desktop.
OpenAI Gym CartPole - Q table (choose action)
def choose_action(state, q_table, action_space, epsilon):
if np.random.random_sample() < epsilon: # 有 ε 的機率會選擇隨機 action
return action_space.sample()
else: # 其他時間根據現有 policy 選擇 action,也就是在 Q table 裡目前 state 中,選擇擁有最大 Q value 的 action
return np.argmax(q_table[state])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment