Update README.md
Browse files
README.md
CHANGED
@@ -28,6 +28,41 @@ using the [stable-baselines3 library](https://github.com/DLR-RM/stable-baselines
|
|
28 |
## Usage (with Stable-baselines3)
|
29 |
TODO: Add your code
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
```python
|
33 |
from stable_baselines3 import ...
|
|
|
28 |
## Usage (with Stable-baselines3)
|
29 |
TODO: Add your code
|
30 |
|
31 |
+
# Create environment
|
32 |
+
env = gym.make('LunarLander-v2')
|
33 |
+
# Instantiate the agent
|
34 |
+
model = PPO('MlpPolicy', env, verbose=1)
|
35 |
+
# Train the agent
|
36 |
+
model.learn(total_timesteps=int(2e5))
|
37 |
+
|
38 |
+
# TODO: Define a PPO MlpPolicy architecture
|
39 |
+
# We use MultiLayerPerceptron (MLPPolicy) because the input is a vector,
|
40 |
+
# if we had frames as input we would use CnnPolicy
|
41 |
+
model = PPO(
|
42 |
+
policy = 'MlpPolicy',
|
43 |
+
env = env,
|
44 |
+
n_steps = 4096,
|
45 |
+
batch_size = 128,
|
46 |
+
n_epochs = 8,
|
47 |
+
gamma = 0.999,
|
48 |
+
gae_lambda = 0.98,
|
49 |
+
ent_coef = 0.01,
|
50 |
+
verbose=1)
|
51 |
+
|
52 |
+
# TODO: Train it for 1,000,000 timesteps
|
53 |
+
model.learn(total_timesteps=2000000)
|
54 |
+
# TODO: Specify file name for model and save the model to file
|
55 |
+
model_name = "ppo-LunarLander-v2"
|
56 |
+
model.save(model_name)
|
57 |
+
|
58 |
+
# TODO: Evaluate the agent
|
59 |
+
# Create a new environment for evaluation
|
60 |
+
eval_env = Monitor(gym.make("LunarLander-v2"))
|
61 |
+
# Evaluate the model with 10 evaluation episodes and deterministic=True
|
62 |
+
mean_reward, std_reward = evaluate_policy(model, eval_env, n_eval_episodes=10, deterministic=True)
|
63 |
+
# Print the results
|
64 |
+
print(f"mean_reward={mean_reward:.2f} +/- {std_reward}")
|
65 |
+
|
66 |
|
67 |
```python
|
68 |
from stable_baselines3 import ...
|