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 all 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
2 changes: 1 addition & 1 deletion lectures/back_prop.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ kernelspec:
```{code-cell} ipython3
:tags: [hide-output]

!pip install --upgrade jax jaxlib
!pip install --upgrade jax jaxlib kaleido
!conda install -y -c plotly plotly plotly-orca retrying
```

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=rf"$\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
Loading