-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrain_SAC_for_cartpole.py
More file actions
49 lines (46 loc) · 1.47 KB
/
train_SAC_for_cartpole.py
File metadata and controls
49 lines (46 loc) · 1.47 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
from agents import trainer, SAC
import gymnasium as gym
import torch.nn
from utilities.config import Config
from utilities.environments import BaseEnvironmentWrapper
config = Config(
hyperparameters={
"SAC": {
"discount_rate": 0.99,
"actor_parameters": {
"linear_layer_sizes": [128],
"linear_layer_activations": [
torch.nn.ReLU(),
torch.nn.Tanh(),
],
"learning_rate": 0.001,
},
"critic_parameters": {
"linear_layer_sizes": [128],
"linear_layer_activations": [
torch.nn.ReLU(),
torch.nn.Tanh(),
],
"learning_rate": 0.001,
},
"initial_temperature": 0.05,
"learn_temperature": False,
"temperature_learning_rate": 0.001,
"soft_update_interpolation_factor": 0.01,
"minibatch_size": 256,
"buffer_size": 40000,
},
},
episode_length=200,
training_steps_per_epoch=400,
epochs=5,
results_filename="SAC_cartpole_rewards2",
log_level="INFO",
log_filename="SAC_cartpole_debug2",
model_filename="SAC_test",
)
env = BaseEnvironmentWrapper(gym.make("CartPole-v1"))
if __name__ == "__main__":
sac_trainer = trainer.Trainer(config)
sac_trainer.train_agents([SAC.SAC], environment=env)
sac_trainer.save_results_to_csv()