Skip to content

Commit bb744f9

Browse files
authored
🔄 resync wealth_dynamics.md (#193)
1 parent 1f6202a commit bb744f9

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
source-sha: 39b39c9bcb4363353b27e2180f12551fbd3a6e9f
2-
synced-at: "2026-07-18"
1+
source-sha: fccf5a9fd50129b3b03a4fd7b5d04976ac51e3a5
2+
synced-at: "2026-07-21"
33
model: claude-sonnet-5
44
mode: RESYNC
55
section-count: 6
6-
tool-version: 0.17.0
6+
tool-version: 0.20.0

lectures/wealth_dynamics.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,16 @@ from numba.experimental import jitclass
109109

110110
上面已经导入的[QuantEcon.py](https://github.com/QuantEcon/QuantEcon.py)包含了计算洛伦兹曲线的函数。
111111

112-
举例说明,假设以下数据代表了10,000个家庭的财富分布
112+
举例说明,假设
113113

114114
```{code-cell} ipython3
115+
rng = np.random.default_rng()
115116
n = 10_000 # 样本大小
116-
w = np.exp(np.random.randn(n)) # 生成对数正态分布的随机样本
117+
w = np.exp(rng.standard_normal(n)) # 生成对数正态分布的随机样本
117118
```
118119

120+
是代表10,000个家庭财富的数据。
121+
119122
我们可以按如下方式计算并绘制洛伦兹曲线:
120123

121124
```{code-cell} ipython3
@@ -147,7 +150,7 @@ a_vals = (1, 2, 5) # 帕累托分布的尾部指数
147150
n = 10_000 # 每个样本的大小
148151
fig, ax = plt.subplots()
149152
for a in a_vals:
150-
u = np.random.uniform(size=n)
153+
u = rng.uniform(size=n)
151154
y = u**(-1/a) # 服从尾部指数为a的帕累托分布
152155
f_vals, l_vals = qe.lorenz_curve(y)
153156
ax.plot(f_vals, l_vals, label=f'$a = {a}$')
@@ -184,7 +187,7 @@ n = 100
184187
185188
fig, ax = plt.subplots()
186189
for a in a_vals:
187-
y = np.random.weibull(a, size=n)
190+
y = rng.weibull(a, size=n)
188191
ginis.append(qe.gini_coefficient(y))
189192
ginis_theoretical.append(1 - 2**(-1/a))
190193
ax.plot(a_vals, ginis, label='基尼系数估值')
@@ -543,13 +546,14 @@ plt.show()
543546
这是一个解法,它在理论和模拟之间产生了很好的匹配。
544547

545548
```{code-cell} ipython3
549+
rng = np.random.default_rng()
546550
a_vals = np.linspace(1, 10, 25) # 帕累托尾部指数
547551
ginis = np.empty_like(a_vals)
548552
549553
n = 1000 # 每个样本的大小
550554
fig, ax = plt.subplots()
551555
for i, a in enumerate(a_vals):
552-
y = np.random.uniform(size=n)**(-1/a)
556+
y = rng.uniform(size=n)**(-1/a)
553557
ginis[i] = qe.gini_coefficient(y)
554558
ax.plot(a_vals, ginis, label='抽样值')
555559
ax.plot(a_vals, 1/(2*a_vals - 1), label='理论值')
@@ -630,4 +634,4 @@ plt.show()
630634
```
631635

632636
```{solution-end}
633-
```
637+
```

0 commit comments

Comments
 (0)