Skip to content

Commit

Permalink
simulator notebook title
Browse files Browse the repository at this point in the history
  • Loading branch information
glatteis committed Nov 7, 2024
1 parent 9401bb3 commit eeed265
Showing 1 changed file with 121 additions and 10 deletions.
131 changes: 121 additions & 10 deletions docs/getting_started/simulator.ipynb
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "8fe92ec7",
"metadata": {},
"source": [
"# The simulator"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 32,
"id": "a8ddc37c-66d2-43e4-8162-6be19a1d70a1",
"metadata": {},
"outputs": [],
Expand All @@ -13,7 +21,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 33,
"id": "cab40f99-3460-4497-8b9f-3d669eee1e11",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -86,10 +94,31 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 34,
"id": "eb0fadc0-7bb6-4c1d-ae3e-9e16527726ab",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ModelType.MDP with name None\n",
"\n",
"States:\n",
"State 0 with labels ['init'] and features {}\n",
"State 1 with labels ['carchosen'] and features {}\n",
"State 2 with labels ['open'] and features {}\n",
"State 3 with labels ['goatrevealed'] and features {}\n",
"State 4 with labels ['done'] and features {}\n",
"\n",
"Transitions:\n",
"0.3333333333333333 -> State 1 with labels ['carchosen'] and features {}\n",
"1.0 -> State 2 with labels ['open'] and features {}\n",
"1.0 -> State 3 with labels ['goatrevealed'] and features {}\n",
"1.0 -> State 4 with labels ['done'] and features {}\n"
]
}
],
"source": [
"#we want to simulate this model. That is, we start at the initial state and then\n",
"#we walk through the model according to transition probabilities.\n",
Expand All @@ -109,12 +138,33 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 35,
"id": "59ac1e34-866c-42c4-b19b-c2a15c830e2e",
"metadata": {
"scrolled": true
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ModelType.MDP with name None\n",
"\n",
"States:\n",
"State 0 with labels ['init'] and features {}\n",
"State 1 with labels ['carchosen'] and features {}\n",
"State 2 with labels ['open'] and features {}\n",
"State 3 with labels ['goatrevealed'] and features {}\n",
"State 4 with labels ['done'] and features {}\n",
"\n",
"Transitions:\n",
"0.3333333333333333 -> State 1 with labels ['carchosen'] and features {}\n",
"1.0 -> State 2 with labels ['open'] and features {}\n",
"1.0 -> State 3 with labels ['goatrevealed'] and features {}\n",
"1.0 -> State 4 with labels ['done'] and features {}\n"
]
}
],
"source": [
"#it still chooses random actions but we can prevent this by providing a scheduler:\n",
"taken_actions = {}\n",
Expand All @@ -128,21 +178,82 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 36,
"id": "22871288-755c-463f-9150-f207c2f5c211",
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "0ad7293a022e4a848f6c2495654b8151",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Output()"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "9fdf09b8fabd407fa97bf7259246cc91",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Output()"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "8c7ab3e5bef84205968f7bd178c127de",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(Output(), Output()))"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"<stormvogel.visualization.Visualization at 0x119aa5880>"
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#we can also visualize the partial model that we get from the simulator:\n",
"show.show(partial_model)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 37,
"id": "34d0c293-d090-4e3d-9e80-4351f5fcba62",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"initial state --(action: empty)--> state: 2 --(action: open0)--> state: 7 --(action: empty)--> state: 17 --(action: stay)--> state: 33\n"
]
}
],
"source": [
"#we can also use another simulator function that returns a path instead of a partial model:\n",
"path = stormvogel.simulator.simulate_path(mdp, steps=4, scheduler=scheduler, seed=123456)\n",
Expand Down

0 comments on commit eeed265

Please sign in to comment.