Skip to content

Commit 3d3289b

Browse files
mmckyclaude
andauthored
kalman_2: drop usetex, render CJK+math via font-manager + mathtext (#181)
Standardises kalman_2 on the zh edition's font-manager approach (the convention on ~38 other lectures), removing the fragile usetex+CJKutf8+ cjk() machinery that caused a cascade of failures during the resync (dropped cjk() def -> NameError; missing amsfonts -> LaTeX Undefined control sequence). Chinese now renders via Source Han Serif; the \mathbb{E}[...] plot titles render via matplotlib mathtext. Implements the #22 decision to move away from usetex (see issue discussion). two_auctions is the only other usetex lecture and is handled the same way. Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
1 parent ef4f43f commit 3d3289b

1 file changed

Lines changed: 13 additions & 28 deletions

File tree

lectures/kalman_2.md

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,6 @@ import numpy as np
7171
from quantecon import Kalman, LinearStateSpace
7272
from collections import namedtuple
7373
from scipy.stats import multivariate_normal
74-
import matplotlib as mpl
75-
76-
# Configure Matplotlib to use pdfLaTeX and CJKutf8
77-
mpl.rcParams.update({
78-
'text.usetex': True,
79-
'text.latex.preamble': r'''
80-
\usepackage{{CJKutf8}}
81-
\usepackage{{amsmath}}
82-
\usepackage{{amsfonts}}
83-
'''
84-
})
85-
86-
# Function to wrap Chinese text in CJK environment
87-
def cjk(text):
88-
return rf'\begin{{CJK}}{{UTF8}}{{gbsn}}{text}\end{{CJK}}'
8974
```
9075

9176
## 劳动者的产出
@@ -299,17 +284,17 @@ mystnb:
299284
fig, ax = plt.subplots(1, 2)
300285
301286
ax[0].plot(y_hat_t, label=r'$\mathbb{E}[y_t| y^{t-1}]$')
302-
ax[0].set_xlabel(cjk('时间'))
287+
ax[0].set_xlabel('时间')
303288
ax[0].set_ylabel(r'$\mathbb{E}[y_t| y^{t-1}]$')
304-
ax[0].set_title(cjk('$\mathbb{E}[y_t| y^{t-1}]$ 随时间变化'))
289+
ax[0].set_title(r'$\mathbb{E}[y_t| y^{t-1}]$ 随时间变化')
305290
ax[0].legend()
306291
307292
ax[1].plot(u_hat_t, label=r'$\mathbb{E}[u_0|y^{t-1}]$')
308293
ax[1].axhline(y=u_0, color='grey',
309294
linestyle='dashed', label=fr'$u_0={u_0:.2f}$')
310-
ax[1].set_xlabel(cjk('时间'))
295+
ax[1].set_xlabel('时间')
311296
ax[1].set_ylabel(r'$\mathbb{E}[u_0|y^{t-1}]$')
312-
ax[1].set_title(cjk('推断的工作伦理随时间变化'))
297+
ax[1].set_title('推断的工作伦理随时间变化')
313298
ax[1].legend()
314299
315300
fig.tight_layout()
@@ -362,7 +347,7 @@ for i, t in enumerate(np.linspace(0, T-1, 3, dtype=int)):
362347
# 创建 PDF 的等高线图
363348
con = axs[i].contour(h, u, pdf_values, cmap='viridis')
364349
axs[i].clabel(con, inline=1, fontsize=10)
365-
axs[i].set_title(cjk('时间步')+f' {t}')
350+
axs[i].set_title('时间步'+f' {t}')
366351
axs[i].set_xlabel(r'$h_{{{}}}$'.format(str(t)))
367352
axs[i].set_ylabel(r'$u_{{{}}}$'.format(str(t)))
368353
@@ -463,17 +448,17 @@ for t in range(T):
463448
fig, ax = plt.subplots(1, 2)
464449
465450
ax[0].plot(y_hat_t, label=r'$\mathbb{E}[y_t| y^{t-1}]$')
466-
ax[0].set_xlabel(cjk('时间'))
451+
ax[0].set_xlabel('时间')
467452
ax[0].set_ylabel(r'$\mathbb{E}[y_t| y^{t-1}]$')
468-
ax[0].set_title(cjk('$\mathbb{E}[y_t| y^{t-1}]$ 随时间变化'))
453+
ax[0].set_title(r'$\mathbb{E}[y_t| y^{t-1}]$ 随时间变化')
469454
ax[0].legend()
470455
471456
ax[1].plot(u_hat_t, label=r'$\mathbb{E}[u_0|y^{t-1}]$')
472457
ax[1].axhline(y=u_0, color='grey',
473458
linestyle='dashed', label=fr'$u_0={u_0:.2f}$')
474-
ax[1].set_xlabel(cjk('时间'))
459+
ax[1].set_xlabel('时间')
475460
ax[1].set_ylabel(r'$\mathbb{E}[u_0|y^{t-1}]$')
476-
ax[1].set_title(cjk('推断的工作伦理随时间变化'))
461+
ax[1].set_title('推断的工作伦理随时间变化')
477462
ax[1].legend()
478463
479464
fig.tight_layout()
@@ -543,7 +528,7 @@ def simulate_workers(worker, T, ax, μ_sim_0=None, Σ_sim_0=None,
543528
if diff :
544529
ax.plot(u_hat_t - u_0, alpha=.5, label=name)
545530
ax.axhline(y=0, color='grey', linestyle='dashed')
546-
ax.set_xlabel(cjk('时间'))
531+
ax.set_xlabel('时间')
547532
ax.set_ylabel(r'$\mathbb{E}[u_0|y^{t-1}] - u_0$')
548533
549534
else:
@@ -553,7 +538,7 @@ def simulate_workers(worker, T, ax, μ_sim_0=None, Σ_sim_0=None,
553538
u_hat_plot = ax.plot(u_hat_t, label=label_line)
554539
ax.axhline(y=u_0, color=u_hat_plot[0].get_color(),
555540
linestyle='dashed', alpha=0.5)
556-
ax.set_xlabel(cjk('时间'))
541+
ax.set_xlabel('时间')
557542
ax.set_ylabel(r'$\mathbb{E}[u_0|y^{t-1}]$')
558543
```
559544

@@ -668,9 +653,9 @@ fig, ax = plt.subplots(figsize=(7, 7))
668653
669654
worker = create_worker(uhat_0=1, α=0.5, β=0.3)
670655
simulate_workers(worker, T, ax, μ_sim_0=μ_sim_0_1, Σ_sim_0=Σ_sim_0,
671-
diff=False, name=cjk('勤奋的劳动者'))
656+
diff=False, name='勤奋的劳动者')
672657
simulate_workers(worker, T, ax, μ_sim_0=μ_sim_0_2, Σ_sim_0=Σ_sim_0,
673-
diff=False, name=cjk('普通劳动者'))
658+
diff=False, name='普通劳动者')
674659
ax.legend(bbox_to_anchor=(1, 0.5))
675660
plt.show()
676661
```

0 commit comments

Comments
 (0)