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
193 changes: 193 additions & 0 deletions lectures/_static/lecture_specific/finite_markov/figures.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "b5a640be-e2e4-4841-bcda-95f6660fd9fe",
"metadata": {},
"source": [
"# Figures for Markov Chain II"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "f8a64d7b-2ffd-4974-a1dd-ec14d8e44102",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Collecting graphviz\n",
" Obtaining dependency information for graphviz from https://files.pythonhosted.org/packages/00/be/d59db2d1d52697c6adc9eacaf50e8965b6345cc143f671e1ed068818d5cf/graphviz-0.20.3-py3-none-any.whl.metadata\n",
" Downloading graphviz-0.20.3-py3-none-any.whl.metadata (12 kB)\n",
"Downloading graphviz-0.20.3-py3-none-any.whl (47 kB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m47.1/47.1 kB\u001b[0m \u001b[31m1.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hInstalling collected packages: graphviz\n",
"Successfully installed graphviz-0.20.3\n"
]
}
],
"source": [
"!pip install graphviz"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "43d55bea-fd00-4583-8d89-830151b6c36c",
"metadata": {},
"outputs": [],
"source": [
"from graphviz import Digraph"
]
},
{
"cell_type": "markdown",
"id": "4185ae75-3a1c-4f89-ad74-1950d344ba56",
"metadata": {},
"source": [
"## Irreducibility"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "53a8bb26-a6e8-421c-abcc-535031d5a69b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'mc_irreducibility1.png'"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dot = Digraph(format='png')\n",
"dot.attr(rankdir='LR')\n",
"dot.node(\"贫穷\")\n",
"dot.node(\"中产\")\n",
"dot.node(\"富裕\")\n",
"\n",
"dot.edge(\"贫穷\", \"贫穷\", label=\"0.9\")\n",
"dot.edge(\"贫穷\", \"中产\", label=\"0.1\")\n",
"dot.edge(\"中产\", \"贫穷\", label=\"0.4\")\n",
"dot.edge(\"中产\", \"中产\", label=\"0.4\")\n",
"dot.edge(\"中产\", \"富裕\", label=\"0.2\")\n",
"dot.edge(\"富裕\", \"贫穷\", label=\"0.1\")\n",
"dot.edge(\"富裕\", \"中产\", label=\"0.1\")\n",
"dot.edge(\"富裕\", \"富裕\", label=\"0.8\")\n",
"\n",
"dot\n",
"dot.render(filename='mc_irreducibility1')"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "4e96fd64-a1ab-4a6e-a5d6-a64767f6181e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'mc_irreducibility2.png'"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dot = Digraph(format='png')\n",
"dot.attr(rankdir='LR')\n",
"dot.node(\"贫穷\")\n",
"dot.node(\"中产\")\n",
"dot.node(\"富裕\")\n",
"\n",
"dot.edge(\"贫穷\", \"贫穷\", label=\"1.0\")\n",
"dot.edge(\"中产\", \"贫穷\", label=\"0.1\")\n",
"dot.edge(\"中产\", \"中产\", label=\"0.8\")\n",
"dot.edge(\"中产\", \"富裕\", label=\"0.1\")\n",
"dot.edge(\"富裕\", \"中产\", label=\"0.2\")\n",
"dot.edge(\"富裕\", \"富裕\", label=\"0.8\")\n",
"\n",
"dot\n",
"dot.render(filename='mc_irreducibility2')"
]
},
{
"cell_type": "markdown",
"id": "1d7441a9-7753-4922-8276-3d26a26798cf",
"metadata": {},
"source": [
"## Example 4"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "5f9c4db0-812a-4131-803f-024ae5b61772",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'hamilton_graph.png'"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dot = Digraph(format='png')\n",
"dot.attr(rankdir='LR')\n",
"dot.node(\"ng\")\n",
"dot.node(\"mr\")\n",
"dot.node(\"sr\")\n",
"\n",
"dot.edge(\"ng\", \"ng\", label=\"0.971\")\n",
"dot.edge(\"ng\", \"mr\", label=\"0.029\")\n",
"dot.edge(\"mr\", \"ng\", label=\"0.145\")\n",
"\n",
"dot.edge(\"mr\", \"mr\", label=\"0.778\")\n",
"dot.edge(\"mr\", \"sr\", label=\"0.077\")\n",
"dot.edge(\"sr\", \"mr\", label=\"0.508\")\n",
"\n",
"dot.edge(\"sr\", \"sr\", label=\"0.492\")\n",
"dot\n",
"\n",
"dot.render(filename='hamilton_graph')"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "quantecon",
"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.11.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
13 changes: 13 additions & 0 deletions lectures/_static/lecture_specific/finite_markov/hamilton_grah
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
digraph {
rankdir=LR
ng
mr
sr
ng -> ng [label=0.971]
ng -> mr [label=0.029]
mr -> ng [label=0.145]
mr -> mr [label=0.778]
mr -> sr [label=0.077]
sr -> mr [label=0.508]
sr -> sr [label=0.492]
}
13 changes: 13 additions & 0 deletions lectures/_static/lecture_specific/finite_markov/hamilton_graph
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
digraph {
rankdir=LR
ng
mr
sr
ng -> ng [label=0.971]
ng -> mr [label=0.029]
mr -> ng [label=0.145]
mr -> mr [label=0.778]
mr -> sr [label=0.077]
sr -> mr [label=0.508]
sr -> sr [label=0.492]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions lectures/_static/lecture_specific/finite_markov/mc_irreducibility1
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
digraph {
rankdir=LR
"贫穷"
"中产"
"富裕"
"贫穷" -> "贫穷" [label=0.9]
"贫穷" -> "中产" [label=0.1]
"中产" -> "贫穷" [label=0.4]
"中产" -> "中产" [label=0.4]
"中产" -> "富裕" [label=0.2]
"富裕" -> "贫穷" [label=0.1]
"富裕" -> "中产" [label=0.1]
"富裕" -> "富裕" [label=0.8]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions lectures/_static/lecture_specific/finite_markov/mc_irreducibility2
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
digraph {
rankdir=LR
"贫穷"
"中产"
"富裕"
"贫穷" -> "贫穷" [label=1.0]
"中产" -> "贫穷" [label=0.1]
"中产" -> "中产" [label=0.8]
"中产" -> "富裕" [label=0.1]
"富裕" -> "中产" [label=0.2]
"富裕" -> "富裕" [label=0.8]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading