Skip to content

Commit

Permalink
simulator notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
glatteis committed Nov 7, 2024
1 parent 7556ba5 commit 0d7c575
Showing 1 changed file with 116 additions and 13 deletions.
129 changes: 116 additions & 13 deletions docs/getting_started/simulator.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 13,
"id": "a8ddc37c-66d2-43e4-8162-6be19a1d70a1",
"metadata": {},
"outputs": [],
Expand All @@ -13,7 +13,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 14,
"id": "cab40f99-3460-4497-8b9f-3d669eee1e11",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -86,10 +86,31 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 15,
"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 ['target', '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",
"0.5 -> State 3 with labels ['goatrevealed'] and features {}\n",
"1.0 -> State 4 with labels ['target', '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 +130,33 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 16,
"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 +170,82 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 17,
"id": "22871288-755c-463f-9150-f207c2f5c211",
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "dedb21bb36f34f78926a65af349155a0",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Output()"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "a99224b532bf40dab9b7e7018bed689f",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Output()"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "28879179b6684e7789aefe922d77d759",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(Output(), Output()))"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"<stormvogel.visualization.Visualization at 0x118715370>"
]
},
"execution_count": 17,
"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": 18,
"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 All @@ -161,9 +264,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python (stormvogel)",
"display_name": ".venv",
"language": "python",
"name": "stormvogel-env"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -175,7 +278,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.7"
"version": "3.12.6"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 0d7c575

Please sign in to comment.