-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrain_PPO_for_cartpole.py
More file actions
52 lines (48 loc) · 1.48 KB
/
train_PPO_for_cartpole.py
File metadata and controls
52 lines (48 loc) · 1.48 KB
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
from agents import trainer, PPO
import gymnasium as gym
import torch.nn
from utilities.config import Config
from utilities.environments import BaseEnvironmentWrapper
NUMBER_OF_ACTIONS: int = 2
ACTION_DIM: int = 1
OBSERVATION_DIM: int = 4
config = Config(
hyperparameters={
"policy_gradient": {
"episodes_per_training_step": 30,
"value_updates_per_training_step": 20,
"discount_rate": 0.99,
"gae_exp_mean_discount_rate": 0.92,
"policy_net_parameters": {
"linear_layer_sizes": [128],
"linear_layer_activations": [
torch.nn.ReLU(),
torch.nn.Tanh(),
],
"learning_rate": 0.001,
},
"value_net_parameters": {
"linear_layer_sizes": [128],
"linear_layer_activations": [
torch.nn.ReLU(),
torch.nn.Tanh(),
],
"learning_rate": 0.001,
},
},
"PPO": {
"clip_range": 0.1
}
},
episode_length=200,
training_steps_per_epoch=400,
epochs=5,
results_filename="PPO_cartpole_rewards",
log_level="INFO",
log_filename="PPO_cartpole_debug",
)
env = BaseEnvironmentWrapper(gym.make("CartPole-v1"))
if __name__ == "__main__":
ppo_trainer = trainer.Trainer(config)
ppo_trainer.train_agents([PPO.PPO], environment=env)
ppo_trainer.save_results_to_csv()