Skip to content

Instantly share code, notes, and snippets.

@SolClover
Created October 16, 2022 07:31
Show Gist options
  • Save SolClover/d747393a31b23f220ebcc9a188dea279 to your computer and use it in GitHub Desktop.
Save SolClover/d747393a31b23f220ebcc9a188dea279 to your computer and use it in GitHub Desktop.
Evaluate agent by visualizing its actions
# Reset environment to initial state
state, info = env.reset()
# Cycle through 50 steps redering and displaying environment state each time
for _ in range(50):
# Render and display current state of the environment
plt.imshow(env.render()) # render current state and pass to pyplot
plt.axis('off')
display.display(plt.gcf()) # get current figure and display
display.clear_output(wait=True) # clear output before showing the next frame
# Use greedy policy to evaluate
action = eval_greedy(Qtable, state)
# Pass action into step function
state, reward, done, _, info = env.step(action)
# Reset environment when done=True, i.e. when the agent falls into a Hole (H) or reaches the Goal (G)
if done:
# Render and display final state of the environment
plt.imshow(env.render()) # render current state and pass to pyplot
plt.axis('off')
display.display(plt.gcf()) # get current figure and display
display.clear_output(wait=True) # clear output before showing the next frame
state, info = env.reset()
env.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment