Skip to content

Commit 061bb98

Browse files
committed
updates
1 parent d4b0bf9 commit 061bb98

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

lectures/kalman_2.md

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ kernelspec:
2020
</div>
2121
```
2222

23-
# 卡尔曼滤波器的另一个视角
23+
# 卡尔曼滤波器进阶
2424

2525
```{index} single: Kalman Filter 2
2626
```
@@ -63,6 +63,7 @@ from quantecon import Kalman, LinearStateSpace
6363
from collections import namedtuple
6464
from scipy.stats import multivariate_normal
6565
import matplotlib as mpl
66+
6667
# Configure Matplotlib to use pdfLaTeX and CJKutf8
6768
mpl.rcParams.update({
6869
'text.usetex': True,
@@ -115,27 +116,27 @@ y_t & = g h_t + v_t , \quad v_t \sim {\mathcal N} (0, R)
115116

116117
这意味着从公司的角度来看,工人的努力程度实际上是一个未知的固定"参数"。
117118

118-
在时间 $t\geq 1$,对于特定工人,公司观察到 $y^{t-1} = [y_{t-1}, y_{t-2}, \ldots, y_0]$(用上式左侧符号表示右侧集合)。
119-
120-
公司无法观察到工人的"类型" $(h_0, u_0)$。
119+
在任意时间点 $t\geq 1$,公司能观察到该工人从雇佣开始到当前时刻的所有历史产出记录,记为 $y^{t-1} = [y_{t-1}, y_{t-2}, \ldots, y_0]$。
121120

122-
但公司确实观察到工人在时间 $t$ 的产出 $y_t$,并记得工人的过去产出 $y^{t-1}$。
121+
虽然公司无法直接观察工人的真实"类型"(即初始人力资本 $h_0$ 和固有努力水平 $u_0$),但可以通过观察工人当前的产出 $y_t$ 以及回顾其历史产出记录 $y^{t-1}$ 来进行推断
123122

124123
## 公司的工资设定政策
125124

126-
基于公司在时间 $t \geq 1$ 获得的关于工人的信息,公司支付工人的对数工资为:
125+
公司根据掌握的工人信息来确定工资。具体来说:
126+
127+
对于 $t \geq 1$ 时期,公司基于截至 $t-1$ 时期的产出历史 $y^{t-1}$ 来预测工人当前的人力资本水平 $h_t$。工人的对数工资设定为:
127128

128129
$$
129130
w_t = g E [ h_t | y^{t-1} ], \quad t \geq 1
130131
$$
131132

132-
在时间 $0$,支付工人的对数工资等于 $y_0$ 的无条件均值
133+
而在初始时期 $t=0$,由于还没有任何历史信息,公司只能基于先验均值来设定工资
133134

134135
$$
135136
w_0 = g \hat h_0
136137
$$
137138

138-
在使用这个支付规则时,公司考虑到工人今天的对数产出部分来自完全由运气决定的随机成分 $v_t$,并且假设 $v_t$ 与 $h_t$ $u_t$ 独立
139+
这种工资设定方式考虑到了一个事实:工人的实际产出中包含一个纯随机的成分 $v_t$。这个随机成分与工人的人力资本 $h_t$ 和努力水平 $u_t$ 都是相互独立的
139140

140141
## 状态空间表示
141142

@@ -194,9 +195,9 @@ def create_worker(α=.8, β=.2, c=.2,
194195
return WorkerModel(A=A, C=C, G=G, R=R, xhat_0=xhat_0, Σ_0=Σ_0)
195196
```
196197

197-
请注意 `WorkerModel` namedtuple 如何创建计算相关状态空间表示 {eq}`ssrepresent` 所需的所有对象
198+
`WorkerModel` namedtuple 为我们创建了所有需要的对象,以便构建状态空间表示 {eq}`ssrepresent`
198199

199-
这很方便,因为为了模拟工人的历史 $\{y_t, h_t\}$,我们需要使用 [`LinearStateSpace`](https://quanteconpy.readthedocs.io/en/latest/tools/lss.html) 类为他/她形成状态空间系统
200+
这使得我们能够方便地使用 [`LinearStateSpace`](https://quanteconpy.readthedocs.io/en/latest/tools/lss.html) 类来模拟工人的历史 $\{y_t, h_t\}$
200201

201202
```{code-cell} ipython3
202203
# 定义 A, C, G, R, xhat_0, Σ_0
@@ -246,7 +247,7 @@ for t in range(1, T):
246247
x_hat, Σ = kalman.x_hat, kalman.Sigma
247248
Σ_t[:, :, t-1] = Σ
248249
x_hat_t[:, t-1] = x_hat.reshape(-1)
249-
y_hat_t[t-1] = worker.G @ x_hat
250+
[y_hat_t[t-1]] = worker.G @ x_hat
250251
251252
x_hat_t = np.concatenate((x[:, 1][:, np.newaxis],
252253
x_hat_t), axis=1)
@@ -403,8 +404,8 @@ for t in range(1, T):
403404
kalman.update(y[t])
404405
x_hat, Σ = kalman.x_hat, kalman.Sigma
405406
Σ_t.append(Σ)
406-
y_hat_t[t-1] = worker.G @ x_hat
407-
u_hat_t[t-1] = x_hat[1]
407+
[y_hat_t[t-1]] = worker.G @ x_hat
408+
[u_hat_t[t-1]] = x_hat[1]
408409
409410
410411
# 生成 y_hat_t 和 u_hat_t 的图
@@ -440,11 +441,11 @@ hard_working_worker = create_worker(α=.4, β=.8,
440441
print(hard_working_worker)
441442
```
442443

443-
我们还可以为不同的工人模拟 $T = 50$ 期的系统
444+
让我们通过模拟不同工人在50个时期内的表现来进一步理解这个系统
444445

445-
推断的工作努力程度和真实工作努力程度之间的差异随时间收敛到 $0$
446+
有趣的是,我们会发现随着时间推移,公司对工人真实努力程度的估计会越来越准确 - 估计值和实际值之间的差异会逐渐趋近于零
446447

447-
这表明滤波器正在逐渐向工人和公司传递关于工人努力程度的信息
448+
这说明卡尔曼滤波器在帮助公司和工人之间建立信息沟通的桥梁,使公司对工人真实努力程度的估计越来越准确
448449

449450
```{code-cell} ipython3
450451
:tags: [hide-input]
@@ -478,8 +479,8 @@ def simulate_workers(worker, T, ax, mu_0=None, Sigma_0=None,
478479
kalman.update(y[i])
479480
x_hat, Σ = kalman.x_hat, kalman.Sigma
480481
Σ_t.append(Σ)
481-
y_hat_t[i] = worker.G @ x_hat
482-
u_hat_t[i] = x_hat[1]
482+
[y_hat_t[i]] = worker.G @ x_hat
483+
[u_hat_t[i]] = x_hat[1]
483484
484485
if diff == True:
485486
title = (cjk('推断的工作努力程度与真实工作努力程度的差异随时间变化')

0 commit comments

Comments
 (0)