|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "id": "43b11347-069e-4c50-b093-4635361408fc", |
| 6 | + "metadata": {}, |
| 7 | + "source": [ |
| 8 | + "# Figures for Markov Chains I" |
| 9 | + ] |
| 10 | + }, |
| 11 | + { |
| 12 | + "cell_type": "code", |
| 13 | + "execution_count": 1, |
| 14 | + "id": "38b0e8a2-acab-4b27-95b3-96174c7d6863", |
| 15 | + "metadata": {}, |
| 16 | + "outputs": [ |
| 17 | + { |
| 18 | + "name": "stdout", |
| 19 | + "output_type": "stream", |
| 20 | + "text": [ |
| 21 | + "Requirement already satisfied: graphviz in /Users/mmcky/anaconda3/envs/quantecon/lib/python3.11/site-packages (0.20.3)\n" |
| 22 | + ] |
| 23 | + } |
| 24 | + ], |
| 25 | + "source": [ |
| 26 | + "!pip install graphviz" |
| 27 | + ] |
| 28 | + }, |
| 29 | + { |
| 30 | + "cell_type": "code", |
| 31 | + "execution_count": 2, |
| 32 | + "id": "606da6ac-e8b7-49c6-9d88-142e18e02bba", |
| 33 | + "metadata": {}, |
| 34 | + "outputs": [], |
| 35 | + "source": [ |
| 36 | + "from graphviz import Digraph" |
| 37 | + ] |
| 38 | + }, |
| 39 | + { |
| 40 | + "cell_type": "markdown", |
| 41 | + "id": "87430938-745b-45d3-9895-937bc357432d", |
| 42 | + "metadata": {}, |
| 43 | + "source": [ |
| 44 | + "## Example 1\n", |
| 45 | + "\n", |
| 46 | + "Hamilton on US unemployment data" |
| 47 | + ] |
| 48 | + }, |
| 49 | + { |
| 50 | + "cell_type": "code", |
| 51 | + "execution_count": 3, |
| 52 | + "id": "eff7a6b5-98d4-4f26-b72f-7100a911644e", |
| 53 | + "metadata": {}, |
| 54 | + "outputs": [ |
| 55 | + { |
| 56 | + "data": { |
| 57 | + "text/plain": [ |
| 58 | + "'Hamilton.png'" |
| 59 | + ] |
| 60 | + }, |
| 61 | + "execution_count": 3, |
| 62 | + "metadata": {}, |
| 63 | + "output_type": "execute_result" |
| 64 | + } |
| 65 | + ], |
| 66 | + "source": [ |
| 67 | + "dot = Digraph(format='png')\n", |
| 68 | + "dot.attr(rankdir='LR')\n", |
| 69 | + "dot.node(\"ng\")\n", |
| 70 | + "dot.node(\"mr\")\n", |
| 71 | + "dot.node(\"sr\")\n", |
| 72 | + "\n", |
| 73 | + "dot.edge(\"ng\", \"ng\", label=\"0.971\")\n", |
| 74 | + "dot.edge(\"ng\", \"mr\", label=\"0.029\")\n", |
| 75 | + "dot.edge(\"mr\", \"ng\", label=\"0.145\")\n", |
| 76 | + "\n", |
| 77 | + "dot.edge(\"mr\", \"mr\", label=\"0.778\")\n", |
| 78 | + "dot.edge(\"mr\", \"sr\", label=\"0.077\")\n", |
| 79 | + "dot.edge(\"sr\", \"mr\", label=\"0.508\")\n", |
| 80 | + "\n", |
| 81 | + "dot.edge(\"sr\", \"sr\", label=\"0.492\")\n", |
| 82 | + "dot\n", |
| 83 | + "\n", |
| 84 | + "dot.render(filename='Hamilton')" |
| 85 | + ] |
| 86 | + }, |
| 87 | + { |
| 88 | + "cell_type": "markdown", |
| 89 | + "id": "7effdaa6-ee97-4634-811c-1b90d7e95543", |
| 90 | + "metadata": {}, |
| 91 | + "source": [ |
| 92 | + "## Exercise 1\n", |
| 93 | + "\n", |
| 94 | + "Solution 2:" |
| 95 | + ] |
| 96 | + }, |
| 97 | + { |
| 98 | + "cell_type": "code", |
| 99 | + "execution_count": 4, |
| 100 | + "id": "bb57212a-c0f2-4922-a549-0edea60ec590", |
| 101 | + "metadata": {}, |
| 102 | + "outputs": [ |
| 103 | + { |
| 104 | + "data": { |
| 105 | + "text/plain": [ |
| 106 | + "'Temple.png'" |
| 107 | + ] |
| 108 | + }, |
| 109 | + "execution_count": 4, |
| 110 | + "metadata": {}, |
| 111 | + "output_type": "execute_result" |
| 112 | + } |
| 113 | + ], |
| 114 | + "source": [ |
| 115 | + "dot = Digraph(format='png')\n", |
| 116 | + "dot.attr(rankdir='LR')\n", |
| 117 | + "dot.node(\"Growth\")\n", |
| 118 | + "dot.node(\"Stagnation\")\n", |
| 119 | + "dot.node(\"Collapse\")\n", |
| 120 | + "\n", |
| 121 | + "dot.edge(\"Growth\", \"Growth\", label=\"0.68\")\n", |
| 122 | + "dot.edge(\"Growth\", \"Stagnation\", label=\"0.12\")\n", |
| 123 | + "dot.edge(\"Growth\", \"Collapse\", label=\"0.20\")\n", |
| 124 | + "\n", |
| 125 | + "dot.edge(\"Stagnation\", \"Stagnation\", label=\"0.24\")\n", |
| 126 | + "dot.edge(\"Stagnation\", \"Growth\", label=\"0.50\")\n", |
| 127 | + "dot.edge(\"Stagnation\", \"Collapse\", label=\"0.26\")\n", |
| 128 | + "\n", |
| 129 | + "dot.edge(\"Collapse\", \"Collapse\", label=\"0.46\")\n", |
| 130 | + "dot.edge(\"Collapse\", \"Stagnation\", label=\"0.18\")\n", |
| 131 | + "dot.edge(\"Collapse\", \"Growth\", label=\"0.36\")\n", |
| 132 | + "\n", |
| 133 | + "dot\n", |
| 134 | + "\n", |
| 135 | + "dot.render(filename='Temple')" |
| 136 | + ] |
| 137 | + }, |
| 138 | + { |
| 139 | + "cell_type": "code", |
| 140 | + "execution_count": null, |
| 141 | + "id": "7aca758c-e819-4d01-a2aa-c5fd36f0e2ad", |
| 142 | + "metadata": {}, |
| 143 | + "outputs": [], |
| 144 | + "source": [] |
| 145 | + } |
| 146 | + ], |
| 147 | + "metadata": { |
| 148 | + "kernelspec": { |
| 149 | + "display_name": "Python 3 (ipykernel)", |
| 150 | + "language": "python", |
| 151 | + "name": "python3" |
| 152 | + }, |
| 153 | + "language_info": { |
| 154 | + "codemirror_mode": { |
| 155 | + "name": "ipython", |
| 156 | + "version": 3 |
| 157 | + }, |
| 158 | + "file_extension": ".py", |
| 159 | + "mimetype": "text/x-python", |
| 160 | + "name": "python", |
| 161 | + "nbconvert_exporter": "python", |
| 162 | + "pygments_lexer": "ipython3", |
| 163 | + "version": "3.11.7" |
| 164 | + } |
| 165 | + }, |
| 166 | + "nbformat": 4, |
| 167 | + "nbformat_minor": 5 |
| 168 | +} |
0 commit comments