Skip to content

FIX: syntax for strings python>=3.12 #439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions lectures/ak2.md
Original file line number Diff line number Diff line change
Expand Up @@ -760,26 +760,26 @@ fig, axs = plt.subplots(3, 3, figsize=(14, 10))
# quantities
for i, name in enumerate(['K', 'Y', 'Cy', 'Co']):
ax = axs[i//3, i%3]
ax.plot(range(T+1), quant_seq1[:T+1, i], label=name+', 1/3')
ax.plot(range(T+1), quant_seq2[:T+1, i], label=name+', 0.2')
ax.plot(range(T+1), quant_seq1[:T+1, i], label=f'{name}, 1/3')
ax.plot(range(T+1), quant_seq2[:T+1, i], label=f'{name}, 0.2')
ax.hlines(init_ss[i], 0, T+1, color='r', linestyle='--')
ax.legend()
ax.set_xlabel('t')

# prices
for i, name in enumerate(['W', 'r']):
ax = axs[(i+4)//3, (i+4)%3]
ax.plot(range(T+1), price_seq1[:T+1, i], label=name+', 1/3')
ax.plot(range(T+1), price_seq2[:T+1, i], label=name+', 0.2')
ax.plot(range(T+1), price_seq1[:T+1, i], label=f'{name}, 1/3')
ax.plot(range(T+1), price_seq2[:T+1, i], label=f'{name}, 0.2')
ax.hlines(init_ss[i+4], 0, T+1, color='r', linestyle='--')
ax.legend()
ax.set_xlabel('t')

# policies
for i, name in enumerate(['τ', 'D', 'G']):
ax = axs[(i+6)//3, (i+6)%3]
ax.plot(range(T+1), policy_seq1[:T+1, i], label=name+', 1/3')
ax.plot(range(T+1), policy_seq2[:T+1, i], label=name+', 0.2')
ax.plot(range(T+1), policy_seq1[:T+1, i], label=f'{name}, 1/3')
ax.plot(range(T+1), policy_seq2[:T+1, i], label=f'{name}, 0.2')
ax.hlines(init_ss[i+6], 0, T+1, color='r', linestyle='--')
ax.legend()
ax.set_xlabel('t')
Expand Down Expand Up @@ -1179,26 +1179,26 @@ fig, axs = plt.subplots(3, 3, figsize=(14, 10))
# quantities
for i, name in enumerate(['K', 'Y', 'Cy', 'Co']):
ax = axs[i//3, i%3]
ax.plot(range(T+1), quant_seq3[:T+1, i], label=name+', $\delta$s=0')
ax.plot(range(T+1), quant_seq4[:T+1, i], label=name+', $\delta$s=0.005')
ax.plot(range(T+1), quant_seq3[:T+1, i], label=rf'{name}, $\delta$s=0')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @HumphreyYang good catch.

ax.plot(range(T+1), quant_seq4[:T+1, i], label=rf'{name}, $\delta$s=0.005')
ax.hlines(init_ss[i], 0, T+1, color='r', linestyle='--')
ax.legend()
ax.set_xlabel('t')

# prices
for i, name in enumerate(['W', 'r']):
ax = axs[(i+4)//3, (i+4)%3]
ax.plot(range(T+1), price_seq3[:T+1, i], label=name+', $\delta$s=0')
ax.plot(range(T+1), price_seq4[:T+1, i], label=name+', $\delta$s=0.005')
ax.plot(range(T+1), price_seq3[:T+1, i], label=rf'{name}, $\delta$s=0')
ax.plot(range(T+1), price_seq4[:T+1, i], label=rf'{name}, $\delta$s=0.005')
ax.hlines(init_ss[i+4], 0, T+1, color='r', linestyle='--')
ax.legend()
ax.set_xlabel('t')

# policies
for i, name in enumerate(['τ', 'D', 'G']):
ax = axs[(i+6)//3, (i+6)%3]
ax.plot(range(T+1), policy_seq3[:T+1, i], label=name+', $\delta$s=0')
ax.plot(range(T+1), policy_seq4[:T+1, i], label=name+', $\delta$s=0.005')
ax.plot(range(T+1), policy_seq3[:T+1, i], label=rf'{name}, $\delta$s=0')
ax.plot(range(T+1), policy_seq4[:T+1, i], label=rf'{name}, $\delta$s=0.005')
ax.hlines(init_ss[i+6], 0, T+1, color='r', linestyle='--')
ax.legend()
ax.set_xlabel('t')
Expand Down Expand Up @@ -1244,26 +1244,26 @@ fig, axs = plt.subplots(3, 3, figsize=(14, 10))
# quantities
for i, name in enumerate(['K', 'Y', 'Cy', 'Co']):
ax = axs[i//3, i%3]
ax.plot(range(T+1), quant_seq3[:T+1, i], label=name+', tax cut')
ax.plot(range(T+1), quant_seq5[:T+1, i], label=name+', transfer')
ax.plot(range(T+1), quant_seq3[:T+1, i], label=f'{name}, tax cut')
ax.plot(range(T+1), quant_seq5[:T+1, i], label=f'{name}, transfer')
ax.hlines(init_ss[i], 0, T+1, color='r', linestyle='--')
ax.legend()
ax.set_xlabel('t')

# prices
for i, name in enumerate(['W', 'r']):
ax = axs[(i+4)//3, (i+4)%3]
ax.plot(range(T+1), price_seq3[:T+1, i], label=name+', tax cut')
ax.plot(range(T+1), price_seq5[:T+1, i], label=name+', transfer')
ax.plot(range(T+1), price_seq3[:T+1, i], label=f'{name}, tax cut')
ax.plot(range(T+1), price_seq5[:T+1, i], label=f'{name}, transfer')
ax.hlines(init_ss[i+4], 0, T+1, color='r', linestyle='--')
ax.legend()
ax.set_xlabel('t')

# policies
for i, name in enumerate(['τ', 'D', 'G']):
ax = axs[(i+6)//3, (i+6)%3]
ax.plot(range(T+1), policy_seq3[:T+1, i], label=name+', tax cut')
ax.plot(range(T+1), policy_seq5[:T+1, i], label=name+', transfer')
ax.plot(range(T+1), policy_seq3[:T+1, i], label=f'{name}, tax cut')
ax.plot(range(T+1), policy_seq5[:T+1, i], label=f'{name}, transfer')
ax.hlines(init_ss[i+6], 0, T+1, color='r', linestyle='--')
ax.legend()
ax.set_xlabel('t')
Expand Down
4 changes: 2 additions & 2 deletions lectures/finite_markov.md
Original file line number Diff line number Diff line change
Expand Up @@ -1242,11 +1242,11 @@ The following code snippet provides a hint as to how you can go about this

```{code-cell} python3
import re
re.findall('\w', 'x +++ y ****** z') # \w matches alphanumerics
re.findall(r'\w', 'x +++ y ****** z') # \w matches alphanumerics
```

```{code-cell} python3
re.findall('\w', 'a ^^ b &&& $$ c')
re.findall(r'\w', 'a ^^ b &&& $$ c')
```

When you solve for the ranking, you will find that the highest ranked node is in fact `g`, while the lowest is `a`.
Expand Down
20 changes: 10 additions & 10 deletions lectures/likelihood_bayes.md
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ for t in range(T):
fig, ax1 = plt.subplots()

for i in range(2):
ax1.plot(range(T+1), π_seq_f[i, :], label=f"$\pi_0$={π_seq_f[i, 0]}")
ax1.plot(range(T+1), π_seq_f[i, :], label=fr"$\pi_0$={π_seq_f[i, 0]}")

ax1.set_ylabel("$\pi_t$")
ax1.set_xlabel("t")
Expand Down Expand Up @@ -348,7 +348,7 @@ for t in range(T):
fig, ax1 = plt.subplots()

for i in range(2):
ax1.plot(range(T+1), π_seq_g[i, :], label=f"$\pi_0$={π_seq_g[i, 0]}")
ax1.plot(range(T+1), π_seq_g[i, :], label=fr"$\pi_0$={π_seq_g[i, 0]}")

ax1.set_ylabel("$\pi_t$")
ax1.set_xlabel("t")
Expand Down Expand Up @@ -646,7 +646,7 @@ for i in range(100):
ax.plot(range(T+1), π_path[i, :])

ax.set_xlabel('$t$')
ax.set_ylabel('$\pi_t$')
ax.set_ylabel(r'$\pi_t$')
plt.show()
```

Expand All @@ -672,7 +672,7 @@ for t in [1, 10, T-1]:
ax.hist(π_path[:,t], bins=20, alpha=0.4, label=f'T={t}')

ax.set_ylabel('count')
ax.set_xlabel('$\pi_T$')
ax.set_xlabel(r'$\pi_T$')
ax.legend(loc='lower right')
plt.show()
```
Expand Down Expand Up @@ -705,7 +705,7 @@ for t in [1, 10, T-1]:
ax.hist(π_path3[:,t], bins=20, alpha=0.4, label=f'T={t}')

ax.set_ylabel('count')
ax.set_xlabel('$\pi_T$')
ax.set_xlabel(r'$\pi_T$')
ax.legend(loc='upper right')
plt.show()
```
Expand All @@ -726,12 +726,12 @@ $F$ more frequently along a sample path, and this pushes $\pi_t$ toward $0$.
```{code-cell} ipython3
fig, ax = plt.subplots()
for i, j in enumerate([10, 100]):
ax.plot(range(T+1), π_path[j,:], color=colors[i], label=f'$\pi$_path, {j}-th simulation')
ax.plot(range(1,T+1), w_path[j,:], color=colors[i], label=f'$w$_path, {j}-th simulation', alpha=0.3)
ax.plot(range(T+1), π_path[j,:], color=colors[i], label=fr'$\pi$_path, {j}-th simulation')
ax.plot(range(1,T+1), w_path[j,:], color=colors[i], label=fr'$w$_path, {j}-th simulation', alpha=0.3)

ax.legend(loc='upper right')
ax.set_xlabel('$t$')
ax.set_ylabel('$\pi_t$')
ax.set_ylabel(r'$\pi_t$')
ax2 = ax.twinx()
ax2.set_ylabel("$w_t$")
plt.show()
Expand Down Expand Up @@ -800,8 +800,8 @@ for pi in pi_array:

fig, ax = plt.subplots()
ax.plot(pi_array, cond_var_array)
ax.set_xlabel('$\pi_{t-1}$')
ax.set_ylabel('$\sigma^{2}(\pi_{t}\\vert \pi_{t-1})$')
ax.set_xlabel(r'$\pi_{t-1}$')
ax.set_ylabel(r'$\sigma^{2}(\pi_{t}\\vert \pi_{t-1})$')
plt.show()
```

Expand Down
4 changes: 2 additions & 2 deletions lectures/linear_models.md
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ y = y.flatten()
ygrid = np.linspace(ymin, ymax, 150)

ax.hist(y, bins=50, density=True, alpha=0.4)
ax.plot(ygrid, f_y.pdf(ygrid), 'k-', lw=2, alpha=0.8, label=r'true density')
ax.plot(ygrid, f_y.pdf(ygrid), 'k-', lw=2, alpha=0.8, label='true density')
ax.set_xlim(ymin, ymax)
ax.set_xlabel('$y_t$', fontsize=12)
ax.set_ylabel('relative frequency', fontsize=12)
Expand Down Expand Up @@ -802,7 +802,7 @@ for t in range(T):
μ_x, μ_y, Σ_x, Σ_y = next(m)
population_means.append(float(μ_y))

ax.plot(population_means, color='g', lw=2, alpha=0.8, label='$G\mu_t$')
ax.plot(population_means, color='g', lw=2, alpha=0.8, label=r'$G\mu_t$')
ax.set_ylim(ymin, ymax)
ax.set_xlabel('time', fontsize=12)
ax.set_ylabel('$y_t$', fontsize=12)
Expand Down
4 changes: 2 additions & 2 deletions lectures/lln_clt.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ for ax in axes:
axlabel = '$\\bar{X}_n$ for $X_i \sim$' + name
ax.plot(list(range(n)), sample_mean, 'g-', lw=3, alpha=0.6, label=axlabel)
m = distribution.mean()
ax.plot(list(range(n)), [m] * n, 'k--', lw=1.5, label='$\mu$')
ax.plot(list(range(n)), [m] * n, 'k--', lw=1.5, label=r'$\mu$')
ax.vlines(list(range(n)), m, data, lw=0.2)
ax.legend(**legend_args, fontsize=12)

Expand Down Expand Up @@ -408,7 +408,7 @@ xmin, xmax = -3 * s, 3 * s
ax.set_xlim(xmin, xmax)
ax.hist(Y, bins=60, alpha=0.5, density=True)
xgrid = np.linspace(xmin, xmax, 200)
ax.plot(xgrid, norm.pdf(xgrid, scale=s), 'k-', lw=2, label='$N(0, \sigma^2)$')
ax.plot(xgrid, norm.pdf(xgrid, scale=s), 'k-', lw=2, label=r'$N(0, \sigma^2)$')
ax.legend()

plt.show()
Expand Down
8 changes: 4 additions & 4 deletions lectures/mix_model.md
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ def plot_π_seq(α, π1=0.2, π2=0.8, T=200):
# plot
fig, ax1 = plt.subplots()
for i in range(2):
ax1.plot(range(T+1), π_seq_mixed[i, :], label=f"$\pi_0$={π_seq_mixed[i, 0]}")
ax1.plot(range(T+1), π_seq_mixed[i, :], label=fr"$\pi_0$={π_seq_mixed[i, 0]}")

ax1.plot(np.nan, np.nan, '--', color='b', label='Log likelihood ratio process')
ax1.set_ylabel("$\pi_t$")
Expand Down Expand Up @@ -630,7 +630,7 @@ ax.set_xlabel(r'$\alpha$')
# plot KL
ax2 = ax.twinx()
# plot limit point
ax2.scatter(α_arr_x, π_lim_arr, facecolors='none', edgecolors='tab:blue', label='$\pi$ lim')
ax2.scatter(α_arr_x, π_lim_arr, facecolors='none', edgecolors='tab:blue', label=r'$\pi$ lim')
ax2.set_ylabel('π lim')

ax.legend(loc=[0.85, 0.8])
Expand Down Expand Up @@ -718,9 +718,9 @@ for i in range(len(sizes)):
data=sample, kde=True, stat='density', alpha=0.2, ax=ax,
color=colors[i], binwidth=0.02, linewidth=0.05, label=f't={sizes[i]}'
)
ax.set_title('$\pi_t(\\alpha)$ as $t$ increases')
ax.set_title(r'$\pi_t(\\alpha)$ as $t$ increases')
ax.legend()
ax.set_xlabel('$\\alpha$')
ax.set_xlabel(r'$\\alpha$')
plt.show()
```

Expand Down
4 changes: 2 additions & 2 deletions lectures/multivariate_normal.md
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ for i in range(1, n+1):
μθ_hat_higher = μθ_hat_arr + 1.96 * σθ_hat_arr

plt.hlines(θ, 1, n+1, ls='--', label='true $θ$')
plt.plot(range(1, n+1), μθ_hat_arr, color='b', label='$\hat{μ}_{θ}$')
plt.plot(range(1, n+1), μθ_hat_arr, color='b', label=r'$\hat{μ}_{θ}$')
plt.plot(range(1, n+1), μθ_hat_lower, color='b', ls='--')
plt.plot(range(1, n+1), μθ_hat_higher, color='b', ls='--')
plt.fill_between(range(1, n+1), μθ_hat_lower, μθ_hat_higher,
Expand Down Expand Up @@ -2277,7 +2277,7 @@ coordinate axis versus $y$ on the ordinate axis.

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

Expand Down
44 changes: 22 additions & 22 deletions lectures/navy_captain.md
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,9 @@ def compute_V_fre(L0_arr, L1_arr, π_star, wf):
π_star = 0.5
V_fre_arr, PFA_arr, PD_arr = compute_V_fre(L0_arr, L1_arr, π_star, wf)

plt.plot(range(T), V_fre_arr, label='$\min_{d} \overline{V}_{fre}(t,d)$')
plt.plot(range(T), V_fre_arr, label=r'$\min_{d} \overline{V}_{fre}(t,d)$')
plt.xlabel('t')
plt.title('$\pi^*=0.5$')
plt.title(r'$\pi^*=0.5$')
plt.legend()
plt.show()
```
Expand Down Expand Up @@ -434,8 +434,8 @@ for i, π_star in enumerate(π_star_arr):

```{code-cell} python3
plt.plot(π_star_arr, V_fre_bar_arr)
plt.xlabel('$\pi^*$')
plt.title('$\overline{V}_{fre}$')
plt.xlabel(r'$\pi^*$')
plt.title(r'$\overline{V}_{fre}$')

plt.show()
```
Expand All @@ -447,12 +447,12 @@ $\left(PFA,PD\right)$ change as $\pi^{*}$ varies.
fig, axs = plt.subplots(1, 2, figsize=(14, 5))

axs[0].plot(π_star_arr, t_optimal_arr)
axs[0].set_xlabel('$\pi^*$')
axs[0].set_xlabel(r'$\pi^*$')
axs[0].set_title('optimal sample size given $\pi^*$')

axs[1].plot(π_star_arr, PFA_optimal_arr, label='$PFA^*(\pi^*)$')
axs[1].plot(π_star_arr, PD_optimal_arr, label='$PD^*(\pi^*)$')
axs[1].set_xlabel('$\pi^*$')
axs[1].set_xlabel(r'$\pi^*$')
axs[1].legend()
axs[1].set_title('optimal PFA and PD given $\pi^*$')

Expand Down Expand Up @@ -587,7 +587,7 @@ plt.vlines(β, 0, β * wf.L0, linestyle="--")
plt.vlines(α, 0, (1 - α) * wf.L1, linestyle="--")

ax.set(xlim=(0, 1), ylim=(0, 0.5 * max(wf.L0, wf.L1)), ylabel="cost",
xlabel="$\pi$", title="Value function")
xlabel=r"$\pi$", title="Value function")

plt.legend(borderpad=1.1)
plt.show()
Expand Down Expand Up @@ -689,7 +689,7 @@ plt.vlines(β, 0, wf.L0, linestyle='--')
plt.text(β+0.01, wf.L0/2, 'β')
plt.vlines(α, 0, wf.L0, linestyle='--')
plt.text(α+0.01, wf.L0/2, 'α')
plt.xlabel('$\pi$')
plt.xlabel(r'$\pi$')
plt.title('Objective value function $V(\pi)$')
plt.legend()
plt.show()
Expand Down Expand Up @@ -734,11 +734,11 @@ for i, π_star in enumerate(π_star_arr):
axs[row_i, col_i].vlines(π_optimal, V_baye_bar, V_baye.max(), linestyle='--')
axs[row_i, col_i].text(π_optimal+0.05, (V_baye_bar + V_baye.max()) / 2,
'${\pi_0^*}=$'+f'{π_optimal:0.2f}')
axs[row_i, col_i].set_xlabel('$\pi$')
axs[row_i, col_i].set_ylabel('$\overline{V}_{baye}(\pi)$')
axs[row_i, col_i].set_title('$\pi^*=$' + f'{π_star}')
axs[row_i, col_i].set_xlabel(r'$\pi$')
axs[row_i, col_i].set_ylabel(r'$\overline{V}_{baye}(\pi)$')
axs[row_i, col_i].set_title(r'$\pi^*=$' + f'{π_star}')

fig.suptitle('$\overline{V}_{baye}(\pi)=\pi^*V^0(\pi) + (1-\pi^*)V^1(\pi)$', fontsize=16)
fig.suptitle(r'$\overline{V}_{baye}(\pi)=\pi^*V^0(\pi) + (1-\pi^*)V^1(\pi)$', fontsize=16)
plt.show()
```

Expand All @@ -763,14 +763,14 @@ for i, π_star in enumerate(π_star_arr):
fig, axs = plt.subplots(1, 2, figsize=(14, 5))

axs[0].plot(π_star_arr, V_baye_bar_arr)
axs[0].set_xlabel('$\pi^*$')
axs[0].set_title('$\overline{V}_{baye}$')
axs[0].set_xlabel(r'$\pi^*$')
axs[0].set_title(r'$\overline{V}_{baye}$')

axs[1].plot(π_star_arr, π_optimal_arr, label='optimal prior')
axs[1].plot([π_star_arr.min(), π_star_arr.max()],
[π_star_arr.min(), π_star_arr.max()],
c='k', linestyle='--', label='45 degree line')
axs[1].set_xlabel('$\pi^*$')
axs[1].set_xlabel(r'$\pi^*$')
axs[1].set_title('optimal prior given $\pi^*$')
axs[1].legend()

Expand Down Expand Up @@ -799,10 +799,10 @@ V_baye_bar = V_baye.min()
```

```{code-cell} python3
plt.plot(range(T), V_fre_arr, label='$\min_{d} \overline{V}_{fre}(t,d)$')
plt.plot([0, T], [V_baye_bar, V_baye_bar], label='$\overline{V}_{baye}$')
plt.plot(range(T), V_fre_arr, label=r'$\min_{d} \overline{V}_{fre}(t,d)$')
plt.plot([0, T], [V_baye_bar, V_baye_bar], label=r'$\overline{V}_{baye}$')
plt.xlabel('t')
plt.title('$\pi^*=0.5$')
plt.title(r'$\pi^*=0.5$')
plt.legend()
plt.show()
```
Expand All @@ -816,14 +816,14 @@ rule does better on average for all values of $\pi^{*}$.
```{code-cell} python3
fig, axs = plt.subplots(1, 2, figsize=(14, 5))

axs[0].plot(π_star_arr, V_fre_bar_arr, label='$\overline{V}_{fre}$')
axs[0].plot(π_star_arr, V_baye_bar_arr, label='$\overline{V}_{baye}$')
axs[0].plot(π_star_arr, V_fre_bar_arr, label=r'$\overline{V}_{fre}$')
axs[0].plot(π_star_arr, V_baye_bar_arr, label=r'$\overline{V}_{baye}$')
axs[0].legend()
axs[0].set_xlabel('$\pi^*$')
axs[0].set_xlabel(r'$\pi^*$')

axs[1].plot(π_star_arr, V_fre_bar_arr - V_baye_bar_arr, label='$diff$')
axs[1].legend()
axs[1].set_xlabel('$\pi^*$')
axs[1].set_xlabel(r'$\pi^*$')

plt.show()
```
Expand Down
Loading
Loading