|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "id": "b5a640be-e2e4-4841-bcda-95f6660fd9fe", |
| 6 | + "metadata": {}, |
| 7 | + "source": [ |
| 8 | + "# Figures for Markov Chain II" |
| 9 | + ] |
| 10 | + }, |
| 11 | + { |
| 12 | + "cell_type": "code", |
| 13 | + "execution_count": 1, |
| 14 | + "id": "f8a64d7b-2ffd-4974-a1dd-ec14d8e44102", |
| 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": "43d55bea-fd00-4583-8d89-830151b6c36c", |
| 33 | + "metadata": {}, |
| 34 | + "outputs": [], |
| 35 | + "source": [ |
| 36 | + "from graphviz import Digraph" |
| 37 | + ] |
| 38 | + }, |
| 39 | + { |
| 40 | + "cell_type": "markdown", |
| 41 | + "id": "4185ae75-3a1c-4f89-ad74-1950d344ba56", |
| 42 | + "metadata": {}, |
| 43 | + "source": [ |
| 44 | + "## Irreducibility" |
| 45 | + ] |
| 46 | + }, |
| 47 | + { |
| 48 | + "cell_type": "code", |
| 49 | + "execution_count": 3, |
| 50 | + "id": "53a8bb26-a6e8-421c-abcc-535031d5a69b", |
| 51 | + "metadata": {}, |
| 52 | + "outputs": [ |
| 53 | + { |
| 54 | + "data": { |
| 55 | + "text/plain": [ |
| 56 | + "'Irre_1.png'" |
| 57 | + ] |
| 58 | + }, |
| 59 | + "execution_count": 3, |
| 60 | + "metadata": {}, |
| 61 | + "output_type": "execute_result" |
| 62 | + } |
| 63 | + ], |
| 64 | + "source": [ |
| 65 | + "dot = Digraph(format='png')\n", |
| 66 | + "dot.attr(rankdir='LR')\n", |
| 67 | + "dot.node(\"poor\")\n", |
| 68 | + "dot.node(\"middle class\")\n", |
| 69 | + "dot.node(\"rich\")\n", |
| 70 | + "\n", |
| 71 | + "dot.edge(\"poor\", \"poor\", label=\"0.9\")\n", |
| 72 | + "dot.edge(\"poor\", \"middle class\", label=\"0.1\")\n", |
| 73 | + "dot.edge(\"middle class\", \"poor\", label=\"0.4\")\n", |
| 74 | + "dot.edge(\"middle class\", \"middle class\", label=\"0.4\")\n", |
| 75 | + "dot.edge(\"middle class\", \"rich\", label=\"0.2\")\n", |
| 76 | + "dot.edge(\"rich\", \"poor\", label=\"0.1\")\n", |
| 77 | + "dot.edge(\"rich\", \"middle class\", label=\"0.1\")\n", |
| 78 | + "dot.edge(\"rich\", \"rich\", label=\"0.8\")\n", |
| 79 | + "\n", |
| 80 | + "dot\n", |
| 81 | + "dot.render(filename='Irre_1')" |
| 82 | + ] |
| 83 | + }, |
| 84 | + { |
| 85 | + "cell_type": "code", |
| 86 | + "execution_count": 4, |
| 87 | + "id": "4e96fd64-a1ab-4a6e-a5d6-a64767f6181e", |
| 88 | + "metadata": {}, |
| 89 | + "outputs": [ |
| 90 | + { |
| 91 | + "data": { |
| 92 | + "text/plain": [ |
| 93 | + "'Irre_2.png'" |
| 94 | + ] |
| 95 | + }, |
| 96 | + "execution_count": 4, |
| 97 | + "metadata": {}, |
| 98 | + "output_type": "execute_result" |
| 99 | + } |
| 100 | + ], |
| 101 | + "source": [ |
| 102 | + "dot = Digraph(format='png')\n", |
| 103 | + "dot.attr(rankdir='LR')\n", |
| 104 | + "dot.node(\"poor\")\n", |
| 105 | + "dot.node(\"middle class\")\n", |
| 106 | + "dot.node(\"rich\")\n", |
| 107 | + "\n", |
| 108 | + "dot.edge(\"poor\", \"poor\", label=\"1.0\")\n", |
| 109 | + "dot.edge(\"middle class\", \"poor\", label=\"0.1\")\n", |
| 110 | + "dot.edge(\"middle class\", \"middle class\", label=\"0.8\")\n", |
| 111 | + "dot.edge(\"middle class\", \"rich\", label=\"0.1\")\n", |
| 112 | + "dot.edge(\"rich\", \"middle class\", label=\"0.2\")\n", |
| 113 | + "dot.edge(\"rich\", \"rich\", label=\"0.8\")\n", |
| 114 | + "\n", |
| 115 | + "dot\n", |
| 116 | + "dot.render(filename='Irre_2')" |
| 117 | + ] |
| 118 | + }, |
| 119 | + { |
| 120 | + "cell_type": "markdown", |
| 121 | + "id": "1d7441a9-7753-4922-8276-3d26a26798cf", |
| 122 | + "metadata": {}, |
| 123 | + "source": [ |
| 124 | + "## Example 4" |
| 125 | + ] |
| 126 | + }, |
| 127 | + { |
| 128 | + "cell_type": "code", |
| 129 | + "execution_count": 5, |
| 130 | + "id": "850376db-6922-4440-af89-c50b0e6b5050", |
| 131 | + "metadata": {}, |
| 132 | + "outputs": [ |
| 133 | + { |
| 134 | + "data": { |
| 135 | + "text/plain": [ |
| 136 | + "'example4.png'" |
| 137 | + ] |
| 138 | + }, |
| 139 | + "execution_count": 5, |
| 140 | + "metadata": {}, |
| 141 | + "output_type": "execute_result" |
| 142 | + } |
| 143 | + ], |
| 144 | + "source": [ |
| 145 | + "dot = Digraph(format='png')\n", |
| 146 | + "dot.attr(rankdir='LR')\n", |
| 147 | + "dot.node(\"0\")\n", |
| 148 | + "dot.node(\"1\")\n", |
| 149 | + "\n", |
| 150 | + "dot.edge(\"0\", \"1\", label=\"1.0\", color='red')\n", |
| 151 | + "dot.edge(\"1\", \"0\", label=\"1.0\", color='red')\n", |
| 152 | + "\n", |
| 153 | + "dot\n", |
| 154 | + "dot.render(filename='example4')" |
| 155 | + ] |
| 156 | + }, |
| 157 | + { |
| 158 | + "cell_type": "code", |
| 159 | + "execution_count": null, |
| 160 | + "id": "5f9c4db0-812a-4131-803f-024ae5b61772", |
| 161 | + "metadata": {}, |
| 162 | + "outputs": [], |
| 163 | + "source": [] |
| 164 | + } |
| 165 | + ], |
| 166 | + "metadata": { |
| 167 | + "kernelspec": { |
| 168 | + "display_name": "Python 3 (ipykernel)", |
| 169 | + "language": "python", |
| 170 | + "name": "python3" |
| 171 | + }, |
| 172 | + "language_info": { |
| 173 | + "codemirror_mode": { |
| 174 | + "name": "ipython", |
| 175 | + "version": 3 |
| 176 | + }, |
| 177 | + "file_extension": ".py", |
| 178 | + "mimetype": "text/x-python", |
| 179 | + "name": "python", |
| 180 | + "nbconvert_exporter": "python", |
| 181 | + "pygments_lexer": "ipython3", |
| 182 | + "version": "3.11.7" |
| 183 | + } |
| 184 | + }, |
| 185 | + "nbformat": 4, |
| 186 | + "nbformat_minor": 5 |
| 187 | +} |
0 commit comments