Skip to content

Commit

Permalink
pomdp observations in visualization
Browse files Browse the repository at this point in the history
  • Loading branch information
YouGuessedMyName committed Nov 10, 2024
1 parent 7e25dc8 commit a982dd1
Show file tree
Hide file tree
Showing 10 changed files with 301 additions and 61 deletions.
38 changes: 28 additions & 10 deletions docs/getting_started/model.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

<iframe
id="modellPtmSPREUD"
id="modelMWfHVKBFQh"
width="820"
height="620"
frameborder="0"
Expand All @@ -27,16 +27,34 @@
&lt;div id=&quot;mynetwork&quot;&gt;&lt;/div&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
var nodes = new vis.DataSet([{ id: 0, label: `init`, group: &quot;states&quot; },
{ id: 1, label: `carchosen`, group: &quot;states&quot; },
{ id: 2, label: `open`, group: &quot;states&quot; },
{ id: 3, label: `goatrevealed`, group: &quot;states&quot; },
{ id: 4, label: `done`, group: &quot;states&quot; },
var nodes = new vis.DataSet([{ id: 0, label: `nijmegen`, group: &quot;states&quot; },
{ id: 1, label: `eindhoven`, group: &quot;states&quot; },
{ id: 2, label: `aachen`, group: &quot;states&quot; },
{ id: 3, label: `saw nijmegen`, group: &quot;states&quot; },
{ id: 4, label: `saw eindhoven`, group: &quot;states&quot; },
{ id: 5, label: `saw aachen`, group: &quot;states&quot; },
{ id: 10000000000, label: `walk`, group: &quot;actions&quot; },
{ id: 10000000001, label: `stay put`, group: &quot;actions&quot; },
{ id: 10000000002, label: `walk`, group: &quot;actions&quot; },
{ id: 10000000003, label: `stay put`, group: &quot;actions&quot; },
{ id: 10000000004, label: `walk`, group: &quot;actions&quot; },
{ id: 10000000005, label: `stay put`, group: &quot;actions&quot; },
]);
var edges = new vis.DataSet([{ from: 0, to: 1, label: &quot;1/3&quot; },
{ from: 1, to: 2, label: &quot;1&quot; },
{ from: 2, to: 3, label: &quot;1&quot; },
{ from: 3, to: 4, label: &quot;1&quot; },
var edges = new vis.DataSet([{ from: 0, to: 10000000000 },
{ from: 10000000000, to: 3, label: &quot;1&quot; },
{ from: 0, to: 10000000001 },
{ from: 10000000001, to: 0, label: &quot;1&quot; },
{ from: 3, to: 0, label: &quot;1&quot; },
{ from: 1, to: 10000000002 },
{ from: 10000000002, to: 4, label: &quot;1&quot; },
{ from: 1, to: 10000000003 },
{ from: 10000000003, to: 1, label: &quot;1&quot; },
{ from: 4, to: 1, label: &quot;1&quot; },
{ from: 2, to: 10000000004 },
{ from: 10000000004, to: 5, label: &quot;1&quot; },
{ from: 2, to: 10000000005 },
{ from: 10000000005, to: 2, label: &quot;1&quot; },
{ from: 5, to: 2, label: &quot;1&quot; },
]);
var options = {
&quot;__fake_macros&quot;: {
Expand Down
156 changes: 156 additions & 0 deletions docs/getting_started/pomdp.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "8013f1f2-f771-43b4-ba2a-c584d05d21b2",
"metadata": {},
"outputs": [],
"source": [
"import stormvogel.model\n",
"from stormvogel.layout import Layout\n",
"from stormvogel.show import show"
]
},
{
"cell_type": "markdown",
"id": "dbc502e0-a2f6-49c8-b9b1-638666906e27",
"metadata": {},
"source": [
"The scenario is as follows. You are dropped in some city, but you are not sure which city. By walking and seeing landmarks, you learn where you are."
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "887c917f-6df3-4379-b1e0-9471d76b0180",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "76eca30fd0d2467ca33df54cf6c1dbb9",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Output()"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<script>fetch('http://127.0.0.1:8890/kWbJuvBmZs/MESSAGE/' + 'test message')</script>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<script>fetch('http://127.0.0.1:8890/kWbJuvBmZs/MESSAGE/' + 'test message')</script>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "5091be68b3b748299cb3b6e3eaf58ff4",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Output()"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "4619d769b6fa4739aa6bb8400100ff2e",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(Output(), Output()))"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"pomdp = stormvogel.model.new_pomdp(create_initial_state=False)\n",
"\n",
"nijmegen = pomdp.new_state(\"nijmegen\")\n",
"eindhoven = pomdp.new_state(\"eindhoven\")\n",
"aachen = pomdp.new_state(\"aachen\")\n",
"cities = [nijmegen, eindhoven, aachen]\n",
"\n",
"saw_nijmegen = pomdp.new_state(\"saw nijmegen\")\n",
"saw_eindhoven = pomdp.new_state(\"saw eindhoven\")\n",
"saw_aachen = pomdp.new_state(\"saw aachen\")\n",
"saw_cities = [saw_nijmegen, saw_eindhoven, saw_aachen]\n",
"\n",
"walk = pomdp.new_action(\"walk\")\n",
"stay_put = pomdp.new_action(\"stay put\")\n",
"\n",
"for city, saw_city in zip(cities, saw_cities):\n",
" city.set_transitions([\n",
" (walk, saw_city),\n",
" (stay_put, city)\n",
" ])\n",
" saw_city.set_transitions([(1, city)])\n",
"\n",
"# We add an observation to the saw states.\n",
"for saw_city in saw_cities:\n",
" saw_city.set_observation(saw_city.id)\n",
"\n",
"vis = show(pomdp, show_editor=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b76ee6e4-156e-4a02-81b9-e150f5903df4",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
24 changes: 16 additions & 8 deletions docs/getting_started/study.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

<iframe
id="studyhIHuBBbPjQ"
id="studyfhiOLrpNPp"
width="820"
height="620"
frameborder="0"
Expand Down Expand Up @@ -30,11 +30,11 @@
var nodes = new vis.DataSet([{ id: 0, label: `init`, group: &quot;states&quot;, x: 5, y: -186 },
{ id: 1, label: `studied`, group: &quot;states&quot;, x: 98, y: 11 },
{ id: 2, label: `didn&#x27;t study
R: 15`, group: &quot;states&quot;, x: -120, y: -7 },
R: 15`, group: &quot;states&quot;, x: -120, y: -7 },
{ id: 3, label: `pass test
R: 100`, group: &quot;states&quot;, x: 0, y: 99 },
R: 100`, group: &quot;states&quot;, x: 0, y: 99 },
{ id: 4, label: `fail test
R: 0`, group: &quot;states&quot;, x: -24, y: 37 },
R: 0`, group: &quot;states&quot;, x: -24, y: 37 },
{ id: 5, label: `end`, group: &quot;states&quot;, x: -62, y: 182 },
{ id: 10000000000, label: `study`, group: &quot;actions&quot;, x: 119, y: -118 },
{ id: 10000000001, label: `don&#x27;t study`, group: &quot;actions&quot;, x: -122, y: -141 },
Expand Down Expand Up @@ -139,10 +139,13 @@
&quot;fractions&quot;: true,
&quot;digits&quot;: 5
},
&quot;results_and_rewards&quot;: {
&quot;state_properties&quot;: {
&quot;show_results&quot;: true,
&quot;resultSymbol&quot;: &quot;\u2606&quot;,
&quot;show_rewards&quot;: true
&quot;result_symbol&quot;: &quot;\u2606&quot;,
&quot;show_rewards&quot;: true,
&quot;rewards_symbol&quot;: &quot;\u20ac&quot;,
&quot;show_observations&quot;: true,
&quot;observations_symbol&quot;: &quot;\u0298&quot;
},
&quot;layout&quot;: {
&quot;randomSeed&quot;: 5
Expand Down Expand Up @@ -195,7 +198,12 @@
},
&quot;width&quot;: 800,
&quot;height&quot;: 600,
&quot;physics&quot;: true
&quot;physics&quot;: true,
&quot;results_and_rewards&quot;: {
&quot;show_results&quot;: true,
&quot;resultSymbol&quot;: &quot;\u2606&quot;,
&quot;show_rewards&quot;: true
}
};
//js
var container = document.getElementById(&quot;mynetwork&quot;);
Expand Down
35 changes: 25 additions & 10 deletions docs/getting_started/study.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"outputs": [],
"source": [
"import stormvogel.model\n",
"import stormvogel.visualization\n",
"from stormvogel.layout import Layout\n",
"from stormvogel.show import show"
]
Expand Down Expand Up @@ -154,7 +153,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 10,
"id": "0df1511e-565d-45d0-93a8-adafbfaaaefa",
"metadata": {
"scrolled": true
Expand All @@ -165,7 +164,7 @@
"text/html": [
"\n",
" <iframe\n",
" id=\"studyhIHuBBbPjQ\"\n",
" id=\"studyfhiOLrpNPp\"\n",
" width=\"820\"\n",
" height=\"620\"\n",
" frameborder=\"0\"\n",
Expand Down Expand Up @@ -195,11 +194,11 @@
" var nodes = new vis.DataSet([{ id: 0, label: `init`, group: &quot;states&quot;, x: 5, y: -186 },\n",
"{ id: 1, label: `studied`, group: &quot;states&quot;, x: 98, y: 11 },\n",
"{ id: 2, label: `didn&#x27;t study\n",
"R: 15`, group: &quot;states&quot;, x: -120, y: -7 },\n",
"\u20ac\tR: 15`, group: &quot;states&quot;, x: -120, y: -7 },\n",
"{ id: 3, label: `pass test\n",
"R: 100`, group: &quot;states&quot;, x: 0, y: 99 },\n",
"\u20ac\tR: 100`, group: &quot;states&quot;, x: 0, y: 99 },\n",
"{ id: 4, label: `fail test\n",
"R: 0`, group: &quot;states&quot;, x: -24, y: 37 },\n",
"\u20ac\tR: 0`, group: &quot;states&quot;, x: -24, y: 37 },\n",
"{ id: 5, label: `end`, group: &quot;states&quot;, x: -62, y: 182 },\n",
"{ id: 10000000000, label: `study`, group: &quot;actions&quot;, x: 119, y: -118 },\n",
"{ id: 10000000001, label: `don&#x27;t study`, group: &quot;actions&quot;, x: -122, y: -141 },\n",
Expand Down Expand Up @@ -304,10 +303,13 @@
" &quot;fractions&quot;: true,\n",
" &quot;digits&quot;: 5\n",
" },\n",
" &quot;results_and_rewards&quot;: {\n",
" &quot;state_properties&quot;: {\n",
" &quot;show_results&quot;: true,\n",
" &quot;resultSymbol&quot;: &quot;\\u2606&quot;,\n",
" &quot;show_rewards&quot;: true\n",
" &quot;result_symbol&quot;: &quot;\\u2606&quot;,\n",
" &quot;show_rewards&quot;: true,\n",
" &quot;rewards_symbol&quot;: &quot;\\u20ac&quot;,\n",
" &quot;show_observations&quot;: true,\n",
" &quot;observations_symbol&quot;: &quot;\\u0298&quot;\n",
" },\n",
" &quot;layout&quot;: {\n",
" &quot;randomSeed&quot;: 5\n",
Expand Down Expand Up @@ -360,7 +362,12 @@
" },\n",
" &quot;width&quot;: 800,\n",
" &quot;height&quot;: 600,\n",
" &quot;physics&quot;: true\n",
" &quot;physics&quot;: true,\n",
" &quot;results_and_rewards&quot;: {\n",
" &quot;show_results&quot;: true,\n",
" &quot;resultSymbol&quot;: &quot;\\u2606&quot;,\n",
" &quot;show_rewards&quot;: true\n",
" }\n",
"};\n",
" //js\n",
"var container = document.getElementById(&quot;mynetwork&quot;);\n",
Expand Down Expand Up @@ -416,6 +423,14 @@
"source": [
"vis = show(mdp, layout=Layout(\"layouts/pinkgreen.json\"), name=\"study\", save_and_embed=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "393f4c6e-8204-42fc-8e0d-b2b8f232294a",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
9 changes: 6 additions & 3 deletions stormvogel/layouts/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,13 @@
"fractions": true,
"digits": 5
},
"results_and_rewards": {
"state_properties": {
"show_results": true,
"resultSymbol": "\u2606",
"show_rewards": true
"result_symbol": "\u2606",
"show_rewards": true,
"reward_symbol": "\u20ac",
"show_observations": true,
"observation_symbol": "\u0298"
},
"layout": {
"randomSeed": 5
Expand Down
9 changes: 6 additions & 3 deletions stormvogel/layouts/explore.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,13 @@
"fractions": true,
"digits": 5
},
"results_and_rewards": {
"state_properties": {
"show_results": true,
"resultSymbol": "\u2606",
"show_rewards": true
"result_symbol": "\u2606",
"show_rewards": true,
"reward_symbol": "\u20ac",
"show_observations": true,
"observation_symbol": "\u0298"
},
"layout": {
"randomSeed": 5
Expand Down
Loading

0 comments on commit a982dd1

Please sign in to comment.