Skip to content

Commit

Permalink
MAINT: Refactor graphviz figures to be lecture_specific figures.ipynb…
Browse files Browse the repository at this point in the history
… assets (#424)

* MAINT: refactor graphviz assets to lecture locations

* update markov_chains_I

* update markov_chain_II

* update networks

* clean up

* manage merge conflict and ensure black edges
  • Loading branch information
mmcky authored Apr 22, 2024
1 parent 079d9c1 commit c879389
Show file tree
Hide file tree
Showing 26 changed files with 889 additions and 565 deletions.
565 changes: 0 additions & 565 deletions lectures/_static/lecture_specific/graphviz/graphviz_generation.ipynb

This file was deleted.

108 changes: 108 additions & 0 deletions lectures/_static/lecture_specific/lake_model/figures.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "3c1ab515-e765-48f5-bfaf-35d4f95581fd",
"metadata": {},
"source": [
"# Figures for Lake Model Lecture"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "45727b3e-f531-4a31-b838-840ccf9d3c02",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requirement already satisfied: graphviz in /Users/mmcky/anaconda3/envs/quantecon/lib/python3.11/site-packages (0.20.3)\n"
]
}
],
"source": [
"!pip install graphviz"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "68e95ec8-877e-416a-a8ff-665715dfe222",
"metadata": {},
"outputs": [],
"source": [
"from graphviz import Digraph"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "92a57207-4d79-4d7b-98c2-aea1a1e35f57",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'lake_model_worker.png'"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Create Digraph object\n",
"G = Digraph(format='png')\n",
"G.attr(rankdir='LR')\n",
"\n",
"# Add nodes\n",
"G.attr('node', shape='circle')\n",
"G.node('1', 'New entrants', color='blue')\n",
"G.node('2', 'Unemployed')\n",
"G.node('3', 'Employed')\n",
"\n",
"# Add edges\n",
"G.edge('1', '2', label='b')\n",
"G.edge('2', '3', label='λ(1-d)')\n",
"G.edge('3', '2', label='α(1-d)')\n",
"G.edge('2', '2', label='(1-λ)(1-d)')\n",
"G.edge('3', '3', label='(1-α)(1-d)')\n",
"\n",
"# Save Plot\n",
"G.render(filename='lake_model_worker')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f6c2af58-4d38-44c3-adb0-d1a92a344e51",
"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.11.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
12 changes: 12 additions & 0 deletions lectures/_static/lecture_specific/lake_model/lake_model_worker
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
digraph {
rankdir=LR
node [shape=circle]
1 [label="New entrants" color=blue]
2 [label=Unemployed]
3 [label=Employed]
1 -> 2 [label=b]
2 -> 3 [label="λ(1-d)"]
3 -> 2 [label="α(1-d)"]
2 -> 2 [label="(1-λ)(1-d)"]
3 -> 3 [label="(1-α)(1-d)"]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions lectures/_static/lecture_specific/markov_chains_I/Hamilton
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]
}
Binary file modified lectures/_static/lecture_specific/markov_chains_I/Hamilton.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions lectures/_static/lecture_specific/markov_chains_I/Temple
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
digraph {
rankdir=LR
Growth
Stagnation
Collapse
Growth -> Growth [label=0.68]
Growth -> Stagnation [label=0.12]
Growth -> Collapse [label=0.20]
Stagnation -> Stagnation [label=0.24]
Stagnation -> Growth [label=0.50]
Stagnation -> Collapse [label=0.26]
Collapse -> Collapse [label=0.46]
Collapse -> Stagnation [label=0.18]
Collapse -> Growth [label=0.36]
}
Binary file modified lectures/_static/lecture_specific/markov_chains_I/Temple.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
168 changes: 168 additions & 0 deletions lectures/_static/lecture_specific/markov_chains_I/figures.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "43b11347-069e-4c50-b093-4635361408fc",
"metadata": {},
"source": [
"# Figures for Markov Chains I"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "38b0e8a2-acab-4b27-95b3-96174c7d6863",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requirement already satisfied: graphviz in /Users/mmcky/anaconda3/envs/quantecon/lib/python3.11/site-packages (0.20.3)\n"
]
}
],
"source": [
"!pip install graphviz"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "606da6ac-e8b7-49c6-9d88-142e18e02bba",
"metadata": {},
"outputs": [],
"source": [
"from graphviz import Digraph"
]
},
{
"cell_type": "markdown",
"id": "87430938-745b-45d3-9895-937bc357432d",
"metadata": {},
"source": [
"## Example 1\n",
"\n",
"Hamilton on US unemployment data"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "eff7a6b5-98d4-4f26-b72f-7100a911644e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Hamilton.png'"
]
},
"execution_count": 3,
"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')"
]
},
{
"cell_type": "markdown",
"id": "7effdaa6-ee97-4634-811c-1b90d7e95543",
"metadata": {},
"source": [
"## Exercise 1\n",
"\n",
"Solution 2:"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "bb57212a-c0f2-4922-a549-0edea60ec590",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Temple.png'"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dot = Digraph(format='png')\n",
"dot.attr(rankdir='LR')\n",
"dot.node(\"Growth\")\n",
"dot.node(\"Stagnation\")\n",
"dot.node(\"Collapse\")\n",
"\n",
"dot.edge(\"Growth\", \"Growth\", label=\"0.68\")\n",
"dot.edge(\"Growth\", \"Stagnation\", label=\"0.12\")\n",
"dot.edge(\"Growth\", \"Collapse\", label=\"0.20\")\n",
"\n",
"dot.edge(\"Stagnation\", \"Stagnation\", label=\"0.24\")\n",
"dot.edge(\"Stagnation\", \"Growth\", label=\"0.50\")\n",
"dot.edge(\"Stagnation\", \"Collapse\", label=\"0.26\")\n",
"\n",
"dot.edge(\"Collapse\", \"Collapse\", label=\"0.46\")\n",
"dot.edge(\"Collapse\", \"Stagnation\", label=\"0.18\")\n",
"dot.edge(\"Collapse\", \"Growth\", label=\"0.36\")\n",
"\n",
"dot\n",
"\n",
"dot.render(filename='Temple')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7aca758c-e819-4d01-a2aa-c5fd36f0e2ad",
"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.11.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
14 changes: 14 additions & 0 deletions lectures/_static/lecture_specific/markov_chains_II/Irre_1
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
digraph {
rankdir=LR
poor
"middle class"
rich
poor -> poor [label=0.9]
poor -> "middle class" [label=0.1]
"middle class" -> poor [label=0.4]
"middle class" -> "middle class" [label=0.4]
"middle class" -> rich [label=0.2]
rich -> poor [label=0.1]
rich -> "middle class" [label=0.1]
rich -> rich [label=0.8]
}
Binary file modified lectures/_static/lecture_specific/markov_chains_II/Irre_1.png
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/markov_chains_II/Irre_2
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
digraph {
rankdir=LR
poor
"middle class"
rich
poor -> poor [label=1.0]
"middle class" -> poor [label=0.1]
"middle class" -> "middle class" [label=0.8]
"middle class" -> rich [label=0.1]
rich -> "middle class" [label=0.2]
rich -> rich [label=0.8]
}
Binary file modified lectures/_static/lecture_specific/markov_chains_II/Irre_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions lectures/_static/lecture_specific/markov_chains_II/example4
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
digraph {
rankdir=LR
0
1
0 -> 1 [label=1.0]
1 -> 0 [label=1.0]
}
Loading

0 comments on commit c879389

Please sign in to comment.