Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions doc/pygambit.api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ Information about the game
Game.get_infosets
Game.get_events
Game.get_strategies
Game.get_sequences
Game.contingencies
Game.get_outcome
Game.get_outcomes
Expand All @@ -136,13 +135,6 @@ Information about the game
Node.action_probs
Node.player

.. autosummary::

:toctree: api/

Sequence.player
Sequence.parent
Sequence.actions

Player behavior
...............
Expand Down
74 changes: 9 additions & 65 deletions doc/tutorials/03_stripped_down_poker.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -370,24 +370,15 @@
"cell_type": "markdown",
"id": "9c1f6a2e",
"metadata": {},
"source": [
"`Game.get_infosets` returns each information set's canonical member as a `History` -- a plain tuple of action labels from the root. Indexing the profile directly by that tuple requires turning it into a `Selector` first, since `MixedBehaviorProfile.__getitem__` accepts only a player label or a `Selector`:"
]
"source": "`Game.get_infosets` returns each information set's canonical member as a `History`. Indexing the profile directly by it requires turning it into a `Selector` first, since `MixedBehaviorProfile.__getitem__` accepts only a player label or a `Selector`; `History.actions` projects it down to the plain tuple of action labels `H.path` expects:"
},
{
"cell_type": "code",
"execution_count": null,
"id": "83bbd3e5",
"metadata": {},
"outputs": [],
"source": [
"for number, node in enumerate(g.get_infosets(\"Alice\"), start=1):\n",
" for action in g.get_actions(gbt.H.path(*node)):\n",
" print(\n",
" f\"At information set {number}, \"\n",
" f\"Alice plays {action} with probability: {eqm[gbt.H.path(*node)][action]}\"\n",
" )"
]
"source": "for number, node in enumerate(g.get_infosets(\"Alice\"), start=1):\n for action in g.get_actions(gbt.H.path(*node.actions)):\n print(\n f\"At information set {number}, \"\n f\"Alice plays {action} with probability: {eqm[gbt.H.path(*node.actions)][action]}\"\n )"
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -424,10 +415,7 @@
"id": "2966e700",
"metadata": {},
"outputs": [],
"source": [
"(bob_node,) = g.get_infosets(\"Bob\")\n",
"eqm[gbt.H.path(*bob_node)][\"Call\"]"
]
"source": "(bob_node,) = g.get_infosets(\"Bob\")\neqm[gbt.H.path(*bob_node.actions)][\"Call\"]"
},
{
"cell_type": "markdown",
Expand All @@ -445,39 +433,21 @@
"id": "a7d3816d",
"metadata": {},
"outputs": [],
"source": [
"bob_action_values = eqm.action_values[gbt.H.path(*bob_node)]\n",
"for action in g.get_actions(gbt.H.path(*bob_node)):\n",
" print(\n",
" f\"When Bob plays {action} his expected payoff is {bob_action_values[action]}\"\n",
" )"
]
"source": "bob_action_values = eqm.action_values[gbt.H.path(*bob_node.actions)]\nfor action in g.get_actions(gbt.H.path(*bob_node.actions)):\n print(\n f\"When Bob plays {action} his expected payoff is {bob_action_values[action]}\"\n )"
},
{
"cell_type": "markdown",
"id": "6491fdda",
"metadata": {},
"source": [
"Bob's indifference between his actions arises because of his beliefs given Alice's strategy.\n",
"\n",
"`MixedBehaviorProfile.beliefs` returns the probability of reaching each node, conditional on its information set being reached.\n",
"\n",
"Recall that the two nodes in Bob's only information set are `(\"King\", \"Bet\")` and `(\"Queen\", \"Bet\")` (as Histories):"
]
"source": "Bob's indifference between his actions arises because of his beliefs given Alice's strategy.\n\n`MixedBehaviorProfile.beliefs` returns the probability of reaching each node, conditional on its information set being reached.\n\nRecall that the two nodes in Bob's only information set are identified by the action-label sequences `(\"King\", \"Bet\")` and `(\"Queen\", \"Bet\")`:"
},
{
"cell_type": "code",
"execution_count": null,
"id": "4a54b20c",
"metadata": {},
"outputs": [],
"source": [
"for node in g.get_members(gbt.H.path(*bob_node)):\n",
" print(\n",
" f\"Bob's belief in reaching the {node[-2]} -> \"\n",
" f\"{node[-1]} node is: {eqm.beliefs[node]}\"\n",
" )"
]
"source": "for node in g.get_members(gbt.H.path(*bob_node.actions)):\n print(\n f\"Bob's belief in reaching the {node[-2].action} -> \"\n f\"{node[-1].action} node is: {eqm.beliefs[node]}\"\n )"
},
{
"cell_type": "markdown",
Expand All @@ -495,9 +465,7 @@
"id": "b250c1cd",
"metadata": {},
"outputs": [],
"source": [
"eqm.infoset_probs[gbt.H.path(*bob_node)]"
]
"source": "eqm.infoset_probs[gbt.H.path(*bob_node.actions)]"
},
{
"cell_type": "markdown",
Expand All @@ -513,15 +481,7 @@
"id": "6f01846b",
"metadata": {},
"outputs": [],
"source": [
"bob_node_values = eqm.node_values[\"Bob\"]\n",
"for node in g.get_members(gbt.H.path(*bob_node)):\n",
" print(\n",
" f\"The probability that the node {node[-2]} -> \"\n",
" f\"{node[-1]} is reached is: {eqm.realiz_probs[node]}. \",\n",
" f\"Bob's expected payoff conditional on reaching this node is {bob_node_values[node]}\"\n",
" )"
]
"source": "bob_node_values = eqm.node_values[\"Bob\"]\nfor node in g.get_members(gbt.H.path(*bob_node.actions)):\n print(\n f\"The probability that the node {node[-2].action} -> \"\n f\"{node[-1].action} is reached is: {eqm.realiz_probs[node]}. \",\n f\"Bob's expected payoff conditional on reaching this node is {bob_node_values[node]}\"\n )"
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -653,23 +613,7 @@
"id": "d18a91f0",
"metadata": {},
"outputs": [],
"source": [
"for player in g.players:\n",
" print(\n",
" f\"{player}'s expected payoffs:\"\n",
" )\n",
" gnm_action_values = gnm_eqm.as_behavior().action_values\n",
" lcp_action_values = eqm.action_values\n",
" for number, node in enumerate(g.get_infosets(player), start=1):\n",
" for action in g.get_actions(gbt.H.path(*node)):\n",
" print(\n",
" f\"At information set {number}, \"\n",
" f\"when playing {action} - \"\n",
" f\"gnm: {gnm_action_values[gbt.H.path(*node)][action]:.4f}\"\n",
" f\", lcp: {str(lcp_action_values[gbt.H.path(*node)][action])}\"\n",
" )\n",
" print()"
]
"source": "for player in g.players:\n print(\n f\"{player}'s expected payoffs:\"\n )\n gnm_action_values = gnm_eqm.as_behavior().action_values\n lcp_action_values = eqm.action_values\n for number, node in enumerate(g.get_infosets(player), start=1):\n for action in g.get_actions(gbt.H.path(*node.actions)):\n print(\n f\"At information set {number}, \"\n f\"when playing {action} - \"\n f\"gnm: {gnm_action_values[gbt.H.path(*node.actions)][action]:.4f}\"\n f\", lcp: {str(lcp_action_values[gbt.H.path(*node.actions)][action])}\"\n )\n print()"
},
{
"cell_type": "markdown",
Expand Down
Loading
Loading