visualize.py 1003 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import numpy as np
  2. from visdom import Visdom
  3. vis = None
  4. win = None
  5. avg_reward = 0
  6. X = []
  7. Y = []
  8. def visdom_plot(
  9. total_num_steps,
  10. mean_reward
  11. ):
  12. global vis
  13. global win
  14. global avg_reward
  15. if vis is None:
  16. vis = Visdom()
  17. assert vis.check_connection()
  18. # Close all existing plots
  19. vis.close()
  20. # Running average for curve smoothing
  21. avg_reward = avg_reward * 0.9 + 0.1 * mean_reward
  22. X.append(total_num_steps)
  23. Y.append(avg_reward)
  24. # The plot with the handle 'win' is updated each time this is called
  25. win = vis.line(
  26. X = np.array(X),
  27. Y = np.array(Y),
  28. opts = dict(
  29. #title = 'All Environments',
  30. xlabel='Total time steps',
  31. ylabel='Reward per episode',
  32. ytickmin=0,
  33. #ytickmax=1,
  34. #ytickstep=0.1,
  35. #legend=legend,
  36. #showlegend=True,
  37. width=900,
  38. height=500
  39. ),
  40. win = win
  41. )