Skip to content

Commit 6fe8969

Browse files
mmckyHumphreyYang
andauthored
FIX: syntax for strings python>=3.12 (#439)
* FIX: syntax for strings python>=3.12 * update cases with `r` * fix issues with mix_model * fixes for mix_model * remove double \ from lecture * add install for package --------- Co-authored-by: Humphrey Yang <[email protected]>
1 parent a83e53c commit 6fe8969

12 files changed

+73
-73
lines changed

lectures/ak2.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -760,26 +760,26 @@ fig, axs = plt.subplots(3, 3, figsize=(14, 10))
760760
# quantities
761761
for i, name in enumerate(['K', 'Y', 'Cy', 'Co']):
762762
ax = axs[i//3, i%3]
763-
ax.plot(range(T+1), quant_seq1[:T+1, i], label=name+', 1/3')
764-
ax.plot(range(T+1), quant_seq2[:T+1, i], label=name+', 0.2')
763+
ax.plot(range(T+1), quant_seq1[:T+1, i], label=f'{name}, 1/3')
764+
ax.plot(range(T+1), quant_seq2[:T+1, i], label=f'{name}, 0.2')
765765
ax.hlines(init_ss[i], 0, T+1, color='r', linestyle='--')
766766
ax.legend()
767767
ax.set_xlabel('t')
768768
769769
# prices
770770
for i, name in enumerate(['W', 'r']):
771771
ax = axs[(i+4)//3, (i+4)%3]
772-
ax.plot(range(T+1), price_seq1[:T+1, i], label=name+', 1/3')
773-
ax.plot(range(T+1), price_seq2[:T+1, i], label=name+', 0.2')
772+
ax.plot(range(T+1), price_seq1[:T+1, i], label=f'{name}, 1/3')
773+
ax.plot(range(T+1), price_seq2[:T+1, i], label=f'{name}, 0.2')
774774
ax.hlines(init_ss[i+4], 0, T+1, color='r', linestyle='--')
775775
ax.legend()
776776
ax.set_xlabel('t')
777777
778778
# policies
779779
for i, name in enumerate(['τ', 'D', 'G']):
780780
ax = axs[(i+6)//3, (i+6)%3]
781-
ax.plot(range(T+1), policy_seq1[:T+1, i], label=name+', 1/3')
782-
ax.plot(range(T+1), policy_seq2[:T+1, i], label=name+', 0.2')
781+
ax.plot(range(T+1), policy_seq1[:T+1, i], label=f'{name}, 1/3')
782+
ax.plot(range(T+1), policy_seq2[:T+1, i], label=f'{name}, 0.2')
783783
ax.hlines(init_ss[i+6], 0, T+1, color='r', linestyle='--')
784784
ax.legend()
785785
ax.set_xlabel('t')
@@ -1179,26 +1179,26 @@ fig, axs = plt.subplots(3, 3, figsize=(14, 10))
11791179
# quantities
11801180
for i, name in enumerate(['K', 'Y', 'Cy', 'Co']):
11811181
ax = axs[i//3, i%3]
1182-
ax.plot(range(T+1), quant_seq3[:T+1, i], label=name+', $\delta$s=0')
1183-
ax.plot(range(T+1), quant_seq4[:T+1, i], label=name+', $\delta$s=0.005')
1182+
ax.plot(range(T+1), quant_seq3[:T+1, i], label=rf'{name}, $\delta$s=0')
1183+
ax.plot(range(T+1), quant_seq4[:T+1, i], label=rf'{name}, $\delta$s=0.005')
11841184
ax.hlines(init_ss[i], 0, T+1, color='r', linestyle='--')
11851185
ax.legend()
11861186
ax.set_xlabel('t')
11871187
11881188
# prices
11891189
for i, name in enumerate(['W', 'r']):
11901190
ax = axs[(i+4)//3, (i+4)%3]
1191-
ax.plot(range(T+1), price_seq3[:T+1, i], label=name+', $\delta$s=0')
1192-
ax.plot(range(T+1), price_seq4[:T+1, i], label=name+', $\delta$s=0.005')
1191+
ax.plot(range(T+1), price_seq3[:T+1, i], label=rf'{name}, $\delta$s=0')
1192+
ax.plot(range(T+1), price_seq4[:T+1, i], label=rf'{name}, $\delta$s=0.005')
11931193
ax.hlines(init_ss[i+4], 0, T+1, color='r', linestyle='--')
11941194
ax.legend()
11951195
ax.set_xlabel('t')
11961196
11971197
# policies
11981198
for i, name in enumerate(['τ', 'D', 'G']):
11991199
ax = axs[(i+6)//3, (i+6)%3]
1200-
ax.plot(range(T+1), policy_seq3[:T+1, i], label=name+', $\delta$s=0')
1201-
ax.plot(range(T+1), policy_seq4[:T+1, i], label=name+', $\delta$s=0.005')
1200+
ax.plot(range(T+1), policy_seq3[:T+1, i], label=rf'{name}, $\delta$s=0')
1201+
ax.plot(range(T+1), policy_seq4[:T+1, i], label=rf'{name}, $\delta$s=0.005')
12021202
ax.hlines(init_ss[i+6], 0, T+1, color='r', linestyle='--')
12031203
ax.legend()
12041204
ax.set_xlabel('t')
@@ -1244,26 +1244,26 @@ fig, axs = plt.subplots(3, 3, figsize=(14, 10))
12441244
# quantities
12451245
for i, name in enumerate(['K', 'Y', 'Cy', 'Co']):
12461246
ax = axs[i//3, i%3]
1247-
ax.plot(range(T+1), quant_seq3[:T+1, i], label=name+', tax cut')
1248-
ax.plot(range(T+1), quant_seq5[:T+1, i], label=name+', transfer')
1247+
ax.plot(range(T+1), quant_seq3[:T+1, i], label=f'{name}, tax cut')
1248+
ax.plot(range(T+1), quant_seq5[:T+1, i], label=f'{name}, transfer')
12491249
ax.hlines(init_ss[i], 0, T+1, color='r', linestyle='--')
12501250
ax.legend()
12511251
ax.set_xlabel('t')
12521252
12531253
# prices
12541254
for i, name in enumerate(['W', 'r']):
12551255
ax = axs[(i+4)//3, (i+4)%3]
1256-
ax.plot(range(T+1), price_seq3[:T+1, i], label=name+', tax cut')
1257-
ax.plot(range(T+1), price_seq5[:T+1, i], label=name+', transfer')
1256+
ax.plot(range(T+1), price_seq3[:T+1, i], label=f'{name}, tax cut')
1257+
ax.plot(range(T+1), price_seq5[:T+1, i], label=f'{name}, transfer')
12581258
ax.hlines(init_ss[i+4], 0, T+1, color='r', linestyle='--')
12591259
ax.legend()
12601260
ax.set_xlabel('t')
12611261
12621262
# policies
12631263
for i, name in enumerate(['τ', 'D', 'G']):
12641264
ax = axs[(i+6)//3, (i+6)%3]
1265-
ax.plot(range(T+1), policy_seq3[:T+1, i], label=name+', tax cut')
1266-
ax.plot(range(T+1), policy_seq5[:T+1, i], label=name+', transfer')
1265+
ax.plot(range(T+1), policy_seq3[:T+1, i], label=f'{name}, tax cut')
1266+
ax.plot(range(T+1), policy_seq5[:T+1, i], label=f'{name}, transfer')
12671267
ax.hlines(init_ss[i+6], 0, T+1, color='r', linestyle='--')
12681268
ax.legend()
12691269
ax.set_xlabel('t')

lectures/back_prop.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ kernelspec:
1616
```{code-cell} ipython3
1717
:tags: [hide-output]
1818
19-
!pip install --upgrade jax jaxlib
19+
!pip install --upgrade jax jaxlib kaleido
2020
!conda install -y -c plotly plotly plotly-orca retrying
2121
```
2222

lectures/finite_markov.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,11 +1242,11 @@ The following code snippet provides a hint as to how you can go about this
12421242
12431243
```{code-cell} python3
12441244
import re
1245-
re.findall('\w', 'x +++ y ****** z') # \w matches alphanumerics
1245+
re.findall(r'\w', 'x +++ y ****** z') # \w matches alphanumerics
12461246
```
12471247
12481248
```{code-cell} python3
1249-
re.findall('\w', 'a ^^ b &&& $$ c')
1249+
re.findall(r'\w', 'a ^^ b &&& $$ c')
12501250
```
12511251
12521252
When you solve for the ranking, you will find that the highest ranked node is in fact `g`, while the lowest is `a`.

lectures/likelihood_bayes.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ for t in range(T):
314314
fig, ax1 = plt.subplots()
315315
316316
for i in range(2):
317-
ax1.plot(range(T+1), π_seq_f[i, :], label=f"$\pi_0$={π_seq_f[i, 0]}")
317+
ax1.plot(range(T+1), π_seq_f[i, :], label=fr"$\pi_0$={π_seq_f[i, 0]}")
318318
319319
ax1.set_ylabel("$\pi_t$")
320320
ax1.set_xlabel("t")
@@ -348,7 +348,7 @@ for t in range(T):
348348
fig, ax1 = plt.subplots()
349349
350350
for i in range(2):
351-
ax1.plot(range(T+1), π_seq_g[i, :], label=f"$\pi_0$={π_seq_g[i, 0]}")
351+
ax1.plot(range(T+1), π_seq_g[i, :], label=fr"$\pi_0$={π_seq_g[i, 0]}")
352352
353353
ax1.set_ylabel("$\pi_t$")
354354
ax1.set_xlabel("t")
@@ -646,7 +646,7 @@ for i in range(100):
646646
ax.plot(range(T+1), π_path[i, :])
647647
648648
ax.set_xlabel('$t$')
649-
ax.set_ylabel('$\pi_t$')
649+
ax.set_ylabel(r'$\pi_t$')
650650
plt.show()
651651
```
652652
@@ -672,7 +672,7 @@ for t in [1, 10, T-1]:
672672
ax.hist(π_path[:,t], bins=20, alpha=0.4, label=f'T={t}')
673673
674674
ax.set_ylabel('count')
675-
ax.set_xlabel('$\pi_T$')
675+
ax.set_xlabel(r'$\pi_T$')
676676
ax.legend(loc='lower right')
677677
plt.show()
678678
```
@@ -705,7 +705,7 @@ for t in [1, 10, T-1]:
705705
ax.hist(π_path3[:,t], bins=20, alpha=0.4, label=f'T={t}')
706706
707707
ax.set_ylabel('count')
708-
ax.set_xlabel('$\pi_T$')
708+
ax.set_xlabel(r'$\pi_T$')
709709
ax.legend(loc='upper right')
710710
plt.show()
711711
```
@@ -726,12 +726,12 @@ $F$ more frequently along a sample path, and this pushes $\pi_t$ toward $0$.
726726
```{code-cell} ipython3
727727
fig, ax = plt.subplots()
728728
for i, j in enumerate([10, 100]):
729-
ax.plot(range(T+1), π_path[j,:], color=colors[i], label=f'$\pi$_path, {j}-th simulation')
730-
ax.plot(range(1,T+1), w_path[j,:], color=colors[i], label=f'$w$_path, {j}-th simulation', alpha=0.3)
729+
ax.plot(range(T+1), π_path[j,:], color=colors[i], label=fr'$\pi$_path, {j}-th simulation')
730+
ax.plot(range(1,T+1), w_path[j,:], color=colors[i], label=fr'$w$_path, {j}-th simulation', alpha=0.3)
731731
732732
ax.legend(loc='upper right')
733733
ax.set_xlabel('$t$')
734-
ax.set_ylabel('$\pi_t$')
734+
ax.set_ylabel(r'$\pi_t$')
735735
ax2 = ax.twinx()
736736
ax2.set_ylabel("$w_t$")
737737
plt.show()
@@ -800,8 +800,8 @@ for pi in pi_array:
800800
801801
fig, ax = plt.subplots()
802802
ax.plot(pi_array, cond_var_array)
803-
ax.set_xlabel('$\pi_{t-1}$')
804-
ax.set_ylabel('$\sigma^{2}(\pi_{t}\\vert \pi_{t-1})$')
803+
ax.set_xlabel(r'$\pi_{t-1}$')
804+
ax.set_ylabel(r'$\sigma^{2}(\pi_{t}\vert \pi_{t-1})$')
805805
plt.show()
806806
```
807807

lectures/linear_models.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ y = y.flatten()
738738
ygrid = np.linspace(ymin, ymax, 150)
739739
740740
ax.hist(y, bins=50, density=True, alpha=0.4)
741-
ax.plot(ygrid, f_y.pdf(ygrid), 'k-', lw=2, alpha=0.8, label=r'true density')
741+
ax.plot(ygrid, f_y.pdf(ygrid), 'k-', lw=2, alpha=0.8, label='true density')
742742
ax.set_xlim(ymin, ymax)
743743
ax.set_xlabel('$y_t$', fontsize=12)
744744
ax.set_ylabel('relative frequency', fontsize=12)
@@ -802,7 +802,7 @@ for t in range(T):
802802
μ_x, μ_y, Σ_x, Σ_y = next(m)
803803
population_means.append(float(μ_y))
804804
805-
ax.plot(population_means, color='g', lw=2, alpha=0.8, label='$G\mu_t$')
805+
ax.plot(population_means, color='g', lw=2, alpha=0.8, label=r'$G\mu_t$')
806806
ax.set_ylim(ymin, ymax)
807807
ax.set_xlabel('time', fontsize=12)
808808
ax.set_ylabel('$y_t$', fontsize=12)

lectures/lln_clt.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ for ax in axes:
265265
axlabel = '$\\bar{X}_n$ for $X_i \sim$' + name
266266
ax.plot(list(range(n)), sample_mean, 'g-', lw=3, alpha=0.6, label=axlabel)
267267
m = distribution.mean()
268-
ax.plot(list(range(n)), [m] * n, 'k--', lw=1.5, label='$\mu$')
268+
ax.plot(list(range(n)), [m] * n, 'k--', lw=1.5, label=r'$\mu$')
269269
ax.vlines(list(range(n)), m, data, lw=0.2)
270270
ax.legend(**legend_args, fontsize=12)
271271
@@ -408,7 +408,7 @@ xmin, xmax = -3 * s, 3 * s
408408
ax.set_xlim(xmin, xmax)
409409
ax.hist(Y, bins=60, alpha=0.5, density=True)
410410
xgrid = np.linspace(xmin, xmax, 200)
411-
ax.plot(xgrid, norm.pdf(xgrid, scale=s), 'k-', lw=2, label='$N(0, \sigma^2)$')
411+
ax.plot(xgrid, norm.pdf(xgrid, scale=s), 'k-', lw=2, label=r'$N(0, \sigma^2)$')
412412
ax.legend()
413413
414414
plt.show()

lectures/mix_model.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ def plot_π_seq(α, π1=0.2, π2=0.8, T=200):
455455
# plot
456456
fig, ax1 = plt.subplots()
457457
for i in range(2):
458-
ax1.plot(range(T+1), π_seq_mixed[i, :], label=f"$\pi_0$={π_seq_mixed[i, 0]}")
458+
ax1.plot(range(T+1), π_seq_mixed[i, :], label=rf"$\pi_0$={π_seq_mixed[i, 0]}")
459459
460460
ax1.plot(np.nan, np.nan, '--', color='b', label='Log likelihood ratio process')
461461
ax1.set_ylabel("$\pi_t$")
@@ -630,7 +630,7 @@ ax.set_xlabel(r'$\alpha$')
630630
# plot KL
631631
ax2 = ax.twinx()
632632
# plot limit point
633-
ax2.scatter(α_arr_x, π_lim_arr, facecolors='none', edgecolors='tab:blue', label='$\pi$ lim')
633+
ax2.scatter(α_arr_x, π_lim_arr, facecolors='none', edgecolors='tab:blue', label=r'$\pi$ lim')
634634
ax2.set_ylabel('π lim')
635635
636636
ax.legend(loc=[0.85, 0.8])
@@ -718,9 +718,9 @@ for i in range(len(sizes)):
718718
data=sample, kde=True, stat='density', alpha=0.2, ax=ax,
719719
color=colors[i], binwidth=0.02, linewidth=0.05, label=f't={sizes[i]}'
720720
)
721-
ax.set_title('$\pi_t(\\alpha)$ as $t$ increases')
721+
ax.set_title(r'$\pi_t(\alpha)$ as $t$ increases')
722722
ax.legend()
723-
ax.set_xlabel('$\\alpha$')
723+
ax.set_xlabel(r'$\alpha$')
724724
plt.show()
725725
```
726726

lectures/multivariate_normal.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ for i in range(1, n+1):
773773
μθ_hat_higher = μθ_hat_arr + 1.96 * σθ_hat_arr
774774
775775
plt.hlines(θ, 1, n+1, ls='--', label='true $θ$')
776-
plt.plot(range(1, n+1), μθ_hat_arr, color='b', label='$\hat{μ}_{θ}$')
776+
plt.plot(range(1, n+1), μθ_hat_arr, color='b', label=r'$\hat{μ}_{θ}$')
777777
plt.plot(range(1, n+1), μθ_hat_lower, color='b', ls='--')
778778
plt.plot(range(1, n+1), μθ_hat_higher, color='b', ls='--')
779779
plt.fill_between(range(1, n+1), μθ_hat_lower, μθ_hat_higher,
@@ -2277,7 +2277,7 @@ coordinate axis versus $y$ on the ordinate axis.
22772277

22782278
```{code-cell} python3
22792279
plt.scatter(range(N), Λ @ f, label='$Ey|f$')
2280-
plt.scatter(range(N), y_hat, label='$\hat{y}$')
2280+
plt.scatter(range(N), y_hat, label=r'$\hat{y}$')
22812281
plt.hlines(f[0], 0, N//2-1, ls='--', label='$f_{1}$')
22822282
plt.hlines(f[1], N//2, N-1, ls='-.', label='$f_{2}$')
22832283

0 commit comments

Comments
 (0)