@@ -4,7 +4,7 @@ jupytext:
4
4
extension : .md
5
5
format_name : myst
6
6
format_version : 0.13
7
- jupytext_version : 1.14.4
7
+ jupytext_version : 1.16.1
8
8
kernelspec :
9
9
display_name : Python 3 (ipykernel)
10
10
language : python
@@ -63,8 +63,18 @@ from quantecon import Kalman, LinearStateSpace
63
63
from collections import namedtuple
64
64
from scipy.stats import multivariate_normal
65
65
import matplotlib as mpl
66
- mpl.rcParams['text.usetex'] = True
67
- mpl.rcParams['text.latex.preamble'] = r'\usepackage{{amsmath}}'
66
+ # Configure Matplotlib to use pdfLaTeX and CJKutf8
67
+ mpl.rcParams.update({
68
+ 'text.usetex': True,
69
+ 'text.latex.preamble': r'''
70
+ \usepackage{{CJKutf8}}
71
+ \usepackage{{amsmath}}
72
+ '''
73
+ })
74
+
75
+ # Function to wrap Chinese text in CJK environment
76
+ def cjk(text):
77
+ return rf'\begin{{CJK}}{{UTF8}}{{gbsn}}{text}\end{{CJK}}'
68
78
```
69
79
70
80
## 工人的产出
@@ -252,21 +262,20 @@ u_hat_t = x_hat_t[1, :]
252
262
我们可以观察公司对工人工作伦理的推断 $E [ u_0 | y^{t-1}] $ 如何逐渐收敛于隐藏的 $u_0$,而 $u_0$ 是公司无法直接观察到的。
253
263
254
264
``` {code-cell} ipython3
255
-
256
265
fig, ax = plt.subplots(1, 2)
257
266
258
267
ax[0].plot(y_hat_t, label=r'$E[y_t| y^{t-1}]$')
259
- ax[0].set_xlabel('时间')
268
+ ax[0].set_xlabel(cjk( '时间') )
260
269
ax[0].set_ylabel(r'$E[y_t]$')
261
- ax[0].set_title(r '$E[y_t]$ 随时间变化')
270
+ ax[0].set_title(cjk( '$E[y_t]$ 随时间变化') )
262
271
ax[0].legend()
263
272
264
273
ax[1].plot(u_hat_t, label=r'$E[u_t|y^{t-1}]$')
265
274
ax[1].axhline(y=u_0, color='grey',
266
275
linestyle='dashed', label=fr'$u_0={u_0:.2f}$')
267
- ax[1].set_xlabel('时间')
276
+ ax[1].set_xlabel(cjk( '时间') )
268
277
ax[1].set_ylabel(r'$E[u_t|y^{t-1}]$')
269
- ax[1].set_title('推断的工作伦理随时间变化')
278
+ ax[1].set_title(cjk( '推断的工作伦理随时间变化') )
270
279
ax[1].legend()
271
280
272
281
fig.tight_layout()
@@ -290,7 +299,6 @@ print(Σ_t[:, :, -1])
290
299
通过在不同时间 $t$ 绘制 $E [ x_t |y^{t-1}] $ 周围的置信椭圆,我们可以生动地展示条件协方差矩阵 $\Sigma_t$ 如何演化。
291
300
292
301
``` {code-cell} ipython3
293
-
294
302
# 创建用于等高线绘制的点网格
295
303
h_range = np.linspace(x_hat_t[0, :].min()-0.5*Σ_t[0, 0, 1],
296
304
x_hat_t[0, :].max()+0.5*Σ_t[0, 0, 1], 100)
@@ -314,7 +322,7 @@ for i, t in enumerate(np.linspace(0, T-1, 3, dtype=int)):
314
322
# 创建 PDF 的等高线图
315
323
con = axs[i].contour(h, u, pdf_values, cmap='viridis')
316
324
axs[i].clabel(con, inline=1, fontsize=10)
317
- axs[i].set_title(f '时间步 {t+1}')
325
+ axs[i].set_title(cjk( '时间步')+f' {t+1}')
318
326
axs[i].set_xlabel(r'$h_{{{}}}$'.format(str(t+1)))
319
327
axs[i].set_ylabel(r'$u_{{{}}}$'.format(str(t+1)))
320
328
@@ -337,7 +345,6 @@ plt.show()
337
345
这是实现这个目标的一种方式:
338
346
339
347
``` {code-cell} ipython3
340
-
341
348
# 例如,我们可能想要 h_0 = 0 和 u_0 = 4
342
349
mu_0 = np.array([0.0, 4.0])
343
350
@@ -360,7 +367,6 @@ print('u_0 =', u_0)
360
367
实现相同目标的另一种方式是使用以下代码:
361
368
362
369
``` {code-cell} ipython3
363
-
364
370
# 如果我们想要设置初始
365
371
# h_0 = hhat_0 = 0 和 u_0 = uhhat_0 = 4.0:
366
372
worker = create_worker(hhat_0=0.0, uhat_0=4.0)
@@ -405,17 +411,17 @@ for t in range(1, T):
405
411
fig, ax = plt.subplots(1, 2)
406
412
407
413
ax[0].plot(y_hat_t, label=r'$E[y_t| y^{t-1}]$')
408
- ax[0].set_xlabel('时间')
414
+ ax[0].set_xlabel(cjk( '时间') )
409
415
ax[0].set_ylabel(r'$E[y_t]$')
410
- ax[0].set_title(r '$E[y_t]$ 随时间变化')
416
+ ax[0].set_title(cjk( '$E[y_t]$ 随时间变化') )
411
417
ax[0].legend()
412
418
413
419
ax[1].plot(u_hat_t, label=r'$E[u_t|y^{t-1}]$')
414
420
ax[1].axhline(y=u_0, color='grey',
415
421
linestyle='dashed', label=fr'$u_0={u_0:.2f}$')
416
- ax[1].set_xlabel('时间')
422
+ ax[1].set_xlabel(cjk( '时间') )
417
423
ax[1].set_ylabel(r'$E[u_t|y^{t-1}]$')
418
- ax[1].set_title('推断的工作伦理随时间变化')
424
+ ax[1].set_title(cjk( '推断的工作伦理随时间变化') )
419
425
ax[1].legend()
420
426
421
427
fig.tight_layout()
@@ -427,7 +433,6 @@ plt.show()
427
433
这是一个例子:
428
434
429
435
``` {code-cell} ipython3
430
-
431
436
# 我们可以在创建工人时设置这些参数 -- 就像类一样!
432
437
hard_working_worker = create_worker(α=.4, β=.8,
433
438
hhat_0=7.0, uhat_0=100, σ_h=2.5, σ_u=3.2)
@@ -477,31 +482,30 @@ def simulate_workers(worker, T, ax, mu_0=None, Sigma_0=None,
477
482
u_hat_t[i] = x_hat[1]
478
483
479
484
if diff == True:
480
- title = ('推断的工作伦理与真实工作伦理的差异随时间变化'
485
+ title = (cjk( '推断的工作伦理与真实工作伦理的差异随时间变化')
481
486
if title == None else title)
482
487
483
488
ax.plot(u_hat_t - u_0, alpha=.5)
484
489
ax.axhline(y=0, color='grey', linestyle='dashed')
485
- ax.set_xlabel('时间')
490
+ ax.set_xlabel(cjk( '时间') )
486
491
ax.set_ylabel(r'$E[u_t|y^{t-1}] - u_0$')
487
492
ax.set_title(title)
488
493
489
494
else:
490
495
label_line = (r'$E[u_t|y^{t-1}]$' if name == None
491
496
else name)
492
- title = ('推断的工作伦理随时间变化'
497
+ title = (cjk( '推断的工作伦理随时间变化')
493
498
if title == None else title)
494
499
495
500
u_hat_plot = ax.plot(u_hat_t, label=label_line)
496
501
ax.axhline(y=u_0, color=u_hat_plot[0].get_color(),
497
502
linestyle='dashed', alpha=0.5)
498
- ax.set_xlabel('时间')
503
+ ax.set_xlabel(cjk( '时间') )
499
504
ax.set_ylabel(r'$E[u_t|y^{t-1}]$')
500
505
ax.set_title(title)
501
506
```
502
507
503
508
``` {code-cell} ipython3
504
-
505
509
num_workers = 3
506
510
T = 50
507
511
fig, ax = plt.subplots(figsize=(7, 7))
@@ -514,7 +518,6 @@ plt.show()
514
518
```
515
519
516
520
``` {code-cell} ipython3
517
-
518
521
# 我们还可以生成 u_t 的图:
519
522
520
523
T = 50
@@ -537,7 +540,6 @@ plt.show()
537
540
```
538
541
539
542
``` {code-cell} ipython3
540
-
541
543
# 我们还可以为所有工人使用精确的 u_0=1 和 h_0=2
542
544
543
545
T = 50
@@ -566,7 +568,6 @@ plt.show()
566
568
```
567
569
568
570
``` {code-cell} ipython3
569
-
570
571
# 我们可以只为其中一个工人生成图:
571
572
572
573
T = 50
@@ -584,11 +585,11 @@ uhat_0s = 100
584
585
585
586
worker = create_worker(uhat_0=uhat_0, α=α, β=β)
586
587
simulate_workers(worker, T, ax, mu_0=mu_0_1, Sigma_0=Sigma_0,
587
- diff=False, name=r '勤奋的工人')
588
+ diff=False, name=cjk( '勤奋的工人') )
588
589
simulate_workers(worker, T, ax, mu_0=mu_0_2, Sigma_0=Sigma_0,
589
590
diff=False,
590
- title='一个勤奋的工人和一个不太勤奋的工人',
591
- name=r '普通工人')
591
+ title=cjk( '一个勤奋的工人和一个不太勤奋的工人') ,
592
+ name=cjk( '普通工人') )
592
593
ax.axhline(y=u_0, xmin=0, xmax=0, color='grey',
593
594
linestyle='dashed', label=r'$u_{i, 0}$')
594
595
ax.legend(bbox_to_anchor=(1, 0.5))
@@ -597,4 +598,4 @@ plt.show()
597
598
598
599
## 未来扩展
599
600
600
- 我们可以通过创建新类型的工人,并让公司仅通过观察他们的产出历史来了解他们的隐藏(对公司来说)状态,来进行许多富有启发性的实验。
601
+ 我们可以通过创建新类型的工人,并让公司仅通过观察他们的产出历史来了解他们的隐藏(对公司来说)状态,来进行许多富有启发性的实验。
0 commit comments