-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrain_square_lander.py
More file actions
39 lines (31 loc) · 1.01 KB
/
train_square_lander.py
File metadata and controls
39 lines (31 loc) · 1.01 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
import gymnasium as gym
from stable_baselines3 import PPO
from square_lunar_lander import SquareLunarLander
from gymnasium.wrappers import RecordVideo
# Create environment
env = gym.make("LunarLander-v3", render_mode="rgb_array") # Disable rendering during training
env = RecordVideo(
env,
video_folder="./videos", # Where to save videos
episode_trigger=lambda x: x % 10 == 0, # Record every 10 episodes
disable_logger=True
)
# Initialize PPO model
model = PPO(
"MlpPolicy",
env,
learning_rate=1e-4, # Slower for stability
n_steps=4096, # More steps for complex strategies
clip_range=0.1, # Tighter clipping for competition
ent_coef=0.02, # Boost exploration
verbose=1
)
# Train the model
model.learn(
total_timesteps=500_000, # Train for 500k steps (~250 episodes)
progress_bar=True # Shows nice progress bar
)
# Save the trained model
model.save("square_lander_basic")
print("Training complete! Model saved.")
env.close()