Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

ram.py 1.7 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
  1. import gym
  2. import torch.optim as optim
  3. from dqn_model import DQN_RAM
  4. from dqn_learn import OptimizerSpec, dqn_learing
  5. from utils.gym import get_ram_env, get_wrapper_by_name
  6. from utils.schedule import LinearSchedule
  7. from utils.saved_state import try_to_find_saved_state
  8. BATCH_SIZE = 32
  9. GAMMA = 0.99
  10. REPLAY_BUFFER_SIZE=1000000
  11. LEARNING_STARTS=50000
  12. LEARNING_FREQ=4
  13. FRAME_HISTORY_LEN=1
  14. TARGER_UPDATE_FREQ=10000
  15. LEARNING_RATE = 0.00025
  16. ALPHA = 0.95
  17. EPS = 0.01
  18. def main(env, num_timesteps=int(4e7)):
  19. def stopping_criterion(env):
  20. # notice that here t is the number of steps of the wrapped env,
  21. # which is different from the number of steps in the underlying env
  22. return get_wrapper_by_name(env, "Monitor").get_total_steps() >= num_timesteps
  23. optimizer_spec = OptimizerSpec(
  24. constructor=optim.RMSprop,
  25. kwargs=dict(lr=LEARNING_RATE, alpha=ALPHA, eps=EPS),
  26. )
  27. exploration_schedule = LinearSchedule(1000000, 0.1)
  28. dqn_learing(
  29. env=env,
  30. q_func=DQN_RAM,
  31. optimizer_spec=optimizer_spec,
  32. exploration=exploration_schedule,
  33. stopping_criterion=stopping_criterion,
  34. replay_buffer_size=REPLAY_BUFFER_SIZE,
  35. batch_size=BATCH_SIZE,
  36. gamma=GAMMA,
  37. learning_starts=LEARNING_STARTS,
  38. learning_freq=LEARNING_FREQ,
  39. frame_history_len=FRAME_HISTORY_LEN,
  40. target_update_freq=TARGER_UPDATE_FREQ,
  41. save_path=try_to_find_saved_state()
  42. )
  43. if __name__ == '__main__':
  44. # Get Atari games.
  45. env = gym.make('Pong-ram-v0')
  46. # Run training
  47. seed = 0 # Use a seed of zero (you may want to randomize the seed!)
  48. env = get_ram_env(env, seed)
  49. main(env)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...