Casio991ms
commited on
Commit
•
527ed06
1
Parent(s):
c5e8aa0
Update README.md
Browse files
README.md
CHANGED
@@ -30,8 +30,32 @@ TODO: Add your code
|
|
30 |
|
31 |
|
32 |
```python
|
33 |
-
|
34 |
-
from huggingface_sb3 import load_from_hub
|
35 |
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
|
32 |
```python
|
33 |
+
import gymnasium as gym
|
|
|
34 |
|
35 |
+
from stable_baselines3 import PPO
|
36 |
+
from stable_baselines3.common.env_util import make_vec_env
|
37 |
+
from stable_baselines3.common.evaluation import evaluate_policy
|
38 |
+
from stable_baselines3.common.monitor import Monitor
|
39 |
+
|
40 |
+
env = make_vec_env('LunarLander-v2', n_envs=16)
|
41 |
+
|
42 |
+
model = PPO(
|
43 |
+
policy='MlpPolicy',
|
44 |
+
env=env,
|
45 |
+
n_steps=1024,
|
46 |
+
batch_size=64,
|
47 |
+
n_epochs=4,
|
48 |
+
gamma=0.999,
|
49 |
+
gae_lambda=0.98,
|
50 |
+
ent_coef=0.01,
|
51 |
+
verbose=1)
|
52 |
+
|
53 |
+
model.learn(total_timesteps=1000000)
|
54 |
+
model_name = "ppo-LunarLander-v2"
|
55 |
+
model.save(model_name)
|
56 |
+
|
57 |
+
|
58 |
+
eval_env = Monitor(gym.make("LunarLander-v2"))
|
59 |
+
mean_reward, std_reward = evaluate_policy(model, eval_env, n_eval_episodes=10, deterministic=True)
|
60 |
+
print(f"mean_reward={mean_reward:.2f} +/- {std_reward}")
|
61 |
+
```
|