Add code
Browse files
README.md
CHANGED
@@ -24,5 +24,27 @@ model-index:
|
|
24 |
This is a trained model of a **PPO** agent playing **Pendulum-v1** using the [stable-baselines3 library](https://github.com/DLR-RM/stable-baselines3).
|
25 |
|
26 |
## Usage (with Stable-baselines3)
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
|
|
24 |
This is a trained model of a **PPO** agent playing **Pendulum-v1** using the [stable-baselines3 library](https://github.com/DLR-RM/stable-baselines3).
|
25 |
|
26 |
## Usage (with Stable-baselines3)
|
27 |
+
```python
|
28 |
+
from stable_baselines3 import PPO
|
29 |
+
from stable_baselines3.common.env_util import make_vec_env
|
30 |
+
|
31 |
+
# Create the environment
|
32 |
+
env_id = "Pendulum-v1"
|
33 |
+
env = make_vec_env(env_id, n_envs=1)
|
34 |
+
|
35 |
+
# Instantiate the agent
|
36 |
+
model = PPO(
|
37 |
+
"MlpPolicy",
|
38 |
+
env,
|
39 |
+
gamma=0.98,
|
40 |
+
use_sde=True,
|
41 |
+
sde_sample_freq=4,
|
42 |
+
learning_rate=1e-3,
|
43 |
+
verbose=1,
|
44 |
+
)
|
45 |
+
|
46 |
+
# Train the agent
|
47 |
+
model.learn(total_timesteps=int(1e5))
|
48 |
+
|
49 |
+
```
|
50 |
|