add actions to enable/disable ports in routers/firewalls, improve notebook for training PPO agents

This commit is contained in:
Cristian-VM2
2024-03-22 16:35:53 +00:00
parent cb9c14c87e
commit bef2bd8084
4 changed files with 140 additions and 6 deletions

View File

@@ -45,7 +45,13 @@
"metadata": {},
"outputs": [],
"source": [
"from stable_baselines3 import PPO"
"from stable_baselines3 import PPO\n",
"\n",
"EPISODE_LEN = 128\n",
"NO_STEPS = EPISODE_LEN * 10\n",
"BATCH_SIZE = EPISODE_LEN * 10\n",
"TOTAL_TIMESTEPS = 5e3 * EPISODE_LEN\n",
"LEARNING_RATE = 3e-4"
]
},
{
@@ -54,7 +60,7 @@
"metadata": {},
"outputs": [],
"source": [
"model = PPO('MlpPolicy', gym)\n"
"model = PPO('MlpPolicy', gym, learning_rate=LEARNING_RATE, n_steps=NO_STEPS, batch_size=BATCH_SIZE, verbose=0, tensorboard_log=\"./PPO_UC2/\")\n"
]
},
{
@@ -63,7 +69,7 @@
"metadata": {},
"outputs": [],
"source": [
"model.learn(total_timesteps=10)\n"
"model.learn(total_timesteps=TOTAL_TIMESTEPS)\n"
]
},
{
@@ -72,7 +78,7 @@
"metadata": {},
"outputs": [],
"source": [
"model.save(\"deleteme\")"
"model.save(\"PrimAITE-v3.0.0b7-PPO\")"
]
},
{
@@ -80,7 +86,21 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"eval_model = PPO(\"MlpPolicy\", gym)\n",
"eval_model = PPO.load(\"PrimAITE-v3.0.0b7-PPO\", gym)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from stable_baselines3.common.evaluation import evaluate_policy\n",
"\n",
"evaluate_policy(eval_model, gym, n_eval_episodes=10)"
]
}
],
"metadata": {
@@ -99,7 +119,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
"version": "3.9.18"
}
},
"nbformat": 4,