Skip to content

Commit 3693d8f

Browse files
committed
Merge branch 'main' into kalman_2
2 parents 061bb98 + a469893 commit 3693d8f

26 files changed

+1105
-894
lines changed
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
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+
"Collecting graphviz\n",
22+
" Obtaining dependency information for graphviz from https://files.pythonhosted.org/packages/00/be/d59db2d1d52697c6adc9eacaf50e8965b6345cc143f671e1ed068818d5cf/graphviz-0.20.3-py3-none-any.whl.metadata\n",
23+
" Downloading graphviz-0.20.3-py3-none-any.whl.metadata (12 kB)\n",
24+
"Downloading graphviz-0.20.3-py3-none-any.whl (47 kB)\n",
25+
"\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",
26+
"\u001b[?25hInstalling collected packages: graphviz\n",
27+
"Successfully installed graphviz-0.20.3\n"
28+
]
29+
}
30+
],
31+
"source": [
32+
"!pip install graphviz"
33+
]
34+
},
35+
{
36+
"cell_type": "code",
37+
"execution_count": 2,
38+
"id": "43d55bea-fd00-4583-8d89-830151b6c36c",
39+
"metadata": {},
40+
"outputs": [],
41+
"source": [
42+
"from graphviz import Digraph"
43+
]
44+
},
45+
{
46+
"cell_type": "markdown",
47+
"id": "4185ae75-3a1c-4f89-ad74-1950d344ba56",
48+
"metadata": {},
49+
"source": [
50+
"## Irreducibility"
51+
]
52+
},
53+
{
54+
"cell_type": "code",
55+
"execution_count": 3,
56+
"id": "53a8bb26-a6e8-421c-abcc-535031d5a69b",
57+
"metadata": {},
58+
"outputs": [
59+
{
60+
"data": {
61+
"text/plain": [
62+
"'mc_irreducibility1.png'"
63+
]
64+
},
65+
"execution_count": 3,
66+
"metadata": {},
67+
"output_type": "execute_result"
68+
}
69+
],
70+
"source": [
71+
"dot = Digraph(format='png')\n",
72+
"dot.attr(rankdir='LR')\n",
73+
"dot.node(\"贫穷\")\n",
74+
"dot.node(\"中产\")\n",
75+
"dot.node(\"富裕\")\n",
76+
"\n",
77+
"dot.edge(\"贫穷\", \"贫穷\", label=\"0.9\")\n",
78+
"dot.edge(\"贫穷\", \"中产\", label=\"0.1\")\n",
79+
"dot.edge(\"中产\", \"贫穷\", label=\"0.4\")\n",
80+
"dot.edge(\"中产\", \"中产\", label=\"0.4\")\n",
81+
"dot.edge(\"中产\", \"富裕\", label=\"0.2\")\n",
82+
"dot.edge(\"富裕\", \"贫穷\", label=\"0.1\")\n",
83+
"dot.edge(\"富裕\", \"中产\", label=\"0.1\")\n",
84+
"dot.edge(\"富裕\", \"富裕\", label=\"0.8\")\n",
85+
"\n",
86+
"dot\n",
87+
"dot.render(filename='mc_irreducibility1')"
88+
]
89+
},
90+
{
91+
"cell_type": "code",
92+
"execution_count": 4,
93+
"id": "4e96fd64-a1ab-4a6e-a5d6-a64767f6181e",
94+
"metadata": {},
95+
"outputs": [
96+
{
97+
"data": {
98+
"text/plain": [
99+
"'mc_irreducibility2.png'"
100+
]
101+
},
102+
"execution_count": 4,
103+
"metadata": {},
104+
"output_type": "execute_result"
105+
}
106+
],
107+
"source": [
108+
"dot = Digraph(format='png')\n",
109+
"dot.attr(rankdir='LR')\n",
110+
"dot.node(\"贫穷\")\n",
111+
"dot.node(\"中产\")\n",
112+
"dot.node(\"富裕\")\n",
113+
"\n",
114+
"dot.edge(\"贫穷\", \"贫穷\", label=\"1.0\")\n",
115+
"dot.edge(\"中产\", \"贫穷\", label=\"0.1\")\n",
116+
"dot.edge(\"中产\", \"中产\", label=\"0.8\")\n",
117+
"dot.edge(\"中产\", \"富裕\", label=\"0.1\")\n",
118+
"dot.edge(\"富裕\", \"中产\", label=\"0.2\")\n",
119+
"dot.edge(\"富裕\", \"富裕\", label=\"0.8\")\n",
120+
"\n",
121+
"dot\n",
122+
"dot.render(filename='mc_irreducibility2')"
123+
]
124+
},
125+
{
126+
"cell_type": "markdown",
127+
"id": "1d7441a9-7753-4922-8276-3d26a26798cf",
128+
"metadata": {},
129+
"source": [
130+
"## Example 4"
131+
]
132+
},
133+
{
134+
"cell_type": "code",
135+
"execution_count": 6,
136+
"id": "5f9c4db0-812a-4131-803f-024ae5b61772",
137+
"metadata": {},
138+
"outputs": [
139+
{
140+
"data": {
141+
"text/plain": [
142+
"'hamilton_graph.png'"
143+
]
144+
},
145+
"execution_count": 6,
146+
"metadata": {},
147+
"output_type": "execute_result"
148+
}
149+
],
150+
"source": [
151+
"dot = Digraph(format='png')\n",
152+
"dot.attr(rankdir='LR')\n",
153+
"dot.node(\"ng\")\n",
154+
"dot.node(\"mr\")\n",
155+
"dot.node(\"sr\")\n",
156+
"\n",
157+
"dot.edge(\"ng\", \"ng\", label=\"0.971\")\n",
158+
"dot.edge(\"ng\", \"mr\", label=\"0.029\")\n",
159+
"dot.edge(\"mr\", \"ng\", label=\"0.145\")\n",
160+
"\n",
161+
"dot.edge(\"mr\", \"mr\", label=\"0.778\")\n",
162+
"dot.edge(\"mr\", \"sr\", label=\"0.077\")\n",
163+
"dot.edge(\"sr\", \"mr\", label=\"0.508\")\n",
164+
"\n",
165+
"dot.edge(\"sr\", \"sr\", label=\"0.492\")\n",
166+
"dot\n",
167+
"\n",
168+
"dot.render(filename='hamilton_graph')"
169+
]
170+
}
171+
],
172+
"metadata": {
173+
"kernelspec": {
174+
"display_name": "quantecon",
175+
"language": "python",
176+
"name": "python3"
177+
},
178+
"language_info": {
179+
"codemirror_mode": {
180+
"name": "ipython",
181+
"version": 3
182+
},
183+
"file_extension": ".py",
184+
"mimetype": "text/x-python",
185+
"name": "python",
186+
"nbconvert_exporter": "python",
187+
"pygments_lexer": "ipython3",
188+
"version": "3.11.5"
189+
}
190+
},
191+
"nbformat": 4,
192+
"nbformat_minor": 5
193+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
digraph {
2+
rankdir=LR
3+
ng
4+
mr
5+
sr
6+
ng -> ng [label=0.971]
7+
ng -> mr [label=0.029]
8+
mr -> ng [label=0.145]
9+
mr -> mr [label=0.778]
10+
mr -> sr [label=0.077]
11+
sr -> mr [label=0.508]
12+
sr -> sr [label=0.492]
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
digraph {
2+
rankdir=LR
3+
ng
4+
mr
5+
sr
6+
ng -> ng [label=0.971]
7+
ng -> mr [label=0.029]
8+
mr -> ng [label=0.145]
9+
mr -> mr [label=0.778]
10+
mr -> sr [label=0.077]
11+
sr -> mr [label=0.508]
12+
sr -> sr [label=0.492]
13+
}
Loading
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
digraph {
2+
rankdir=LR
3+
"贫穷"
4+
"中产"
5+
"富裕"
6+
"贫穷" -> "贫穷" [label=0.9]
7+
"贫穷" -> "中产" [label=0.1]
8+
"中产" -> "贫穷" [label=0.4]
9+
"中产" -> "中产" [label=0.4]
10+
"中产" -> "富裕" [label=0.2]
11+
"富裕" -> "贫穷" [label=0.1]
12+
"富裕" -> "中产" [label=0.1]
13+
"富裕" -> "富裕" [label=0.8]
14+
}
Loading
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
digraph {
2+
rankdir=LR
3+
"贫穷"
4+
"中产"
5+
"富裕"
6+
"贫穷" -> "贫穷" [label=1.0]
7+
"中产" -> "贫穷" [label=0.1]
8+
"中产" -> "中产" [label=0.8]
9+
"中产" -> "富裕" [label=0.1]
10+
"富裕" -> "中产" [label=0.2]
11+
"富裕" -> "富裕" [label=0.8]
12+
}
Loading

lectures/aiyagari.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,9 @@ w(r) = A (1 - \alpha) (A \alpha / (r + \delta))^{\alpha / (1 - \alpha)}
169169
* 价格诱导的行为产生的总量与价格一致
170170
* 总量和价格随时间保持不变
171171

172-
更详细地说,SREE列出了价格、储蓄和生产政策的集合,使得:
172+
更详细地说,SREE列出了价格、储蓄和生产策略的集合,使得:
173173

174-
* 家庭在给定价格下选择指定的储蓄政策
174+
* 家庭在给定价格下选择指定的储蓄策略
175175
* 企业在相同价格下最大化利润
176176
* 产生的总量与价格一致;特别是,资本需求等于供给
177177
* 总量(定义为横截面平均值)保持不变
@@ -180,8 +180,8 @@ w(r) = A (1 - \alpha) (A \alpha / (r + \delta))^{\alpha / (1 - \alpha)}
180180

181181
1. 选择一个提议的总资本量 $K$
182182
2. 确定相应的价格,其中利率 $r$ 由 {eq}`aiy_rgk` 决定,工资率 $w(r)$ 由 {eq}`aiy_wgr` 给出
183-
3. 确定给定这些价格下家庭的共同最优储蓄政策
184-
4. 计算给定这个储蓄政策下的稳态资本平均值
183+
3. 确定给定这些价格下家庭的共同最优储蓄策略
184+
4. 计算给定这个储蓄策略下的稳态资本平均值
185185

186186
如果最终数量与 $K$ 一致,那么我们就得到了一个SREE。
187187

@@ -214,7 +214,7 @@ w(r) = A (1 - \alpha) (A \alpha / (r + \delta))^{\alpha / (1 - \alpha)}
214214
class Household:
215215
"""
216216
这个类接收定义家庭资产积累问题的参数,并计算相应的回报和转移矩阵R
217-
和Q,这些矩阵是生成DiscreteDP实例所必需的,从而求解最优政策
217+
和Q,这些矩阵是生成DiscreteDP实例所必需的,从而求解最优策略
218218
219219
关于索引的说明:我们需要将状态空间S枚举为序列S = {0, ..., n}。
220220
为此,(a_i, z_i)索引对根据以下规则映射到s_i索引:
@@ -313,7 +313,7 @@ def asset_marginal(s_probs, a_size, z_size):
313313
return a_probs
314314
```
315315

316-
作为第一个例子,让我们计算并绘制在固定价格下的最优积累政策
316+
作为第一个例子,让我们计算并绘制在固定价格下的最优积累策略
317317

318318
```{code-cell} python3
319319
# 示例价格
@@ -353,7 +353,7 @@ ax.legend(loc='upper left')
353353
plt.show()
354354
```
355355

356-
该图显示了在不同外生状态值下的资产积累政策
356+
该图显示了在不同外生状态值下的资产积累策略
357357

358358
现在我们要计算均衡。
359359

@@ -399,7 +399,7 @@ def prices_to_capital_stock(am, r):
399399
w = r_to_w(r)
400400
am.set_prices(r, w)
401401
aiyagari_ddp = DiscreteDP(am.R, am.Q, β)
402-
# 计算最优政策
402+
# 计算最优策略
403403
results = aiyagari_ddp.solve(method='policy_iteration')
404404
# 计算稳态分布
405405
stationary_probs = results.mc.stationary_distributions[0]

0 commit comments

Comments
 (0)