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 1 commit
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
4 changes: 2 additions & 2 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
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
2 changes: 1 addition & 1 deletion 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
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
8 changes: 4 additions & 4 deletions lectures/util_rand_resp.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,11 @@ y2 = (pow(x2, 0.5) - 0.4)**2
x3 = np.arange(0.4**0.5, 1, 0.001)
y3 = pow(x3**2 - 0.4, 0.5)
plt.figure(figsize=(12, 10))
plt.plot(x1, y1, 'r-', label='Truth Border of: $U_i(Pr(A|r_i),\phi_i)=-Pr(A|r_i)+f(\phi_i)$')
plt.plot(x1, y1, 'r-', label=r'Truth Border of: $U_i(Pr(A|r_i),\phi_i)=-Pr(A|r_i)+f(\phi_i)$')
plt.fill_between(x1, 0, y1, facecolor='red', alpha=0.05)
plt.plot(x2, y2, 'b-', label='Truth Border of: $U_i(Pr(A|r_i),\phi_i)=-Pr(A|r_i)^{2}+f(\phi_i)$')
plt.plot(x2, y2, 'b-', label=r'Truth Border of: $U_i(Pr(A|r_i),\phi_i)=-Pr(A|r_i)^{2}+f(\phi_i)$')
plt.fill_between(x2, 0, y2, facecolor='blue', alpha=0.05)
plt.plot(x3, y3, 'y-', label='Truth Border of: $U_i(Pr(A|r_i),\phi_i)=-\sqrt{Pr(A|r_i)}+f(\phi_i)$')
plt.plot(x3, y3, 'y-', label=r'Truth Border of: $U_i(Pr(A|r_i),\phi_i)=-\sqrt{Pr(A|r_i)}+f(\phi_i)$')
plt.fill_between(x3, 0, y3, facecolor='green', alpha=0.05)
plt.plot(x1, x1, ':', linewidth=2)
plt.xlim([0, 1])
Expand Down Expand Up @@ -318,7 +318,7 @@ y1 = x1 - 0.4
z1 = x1
z2 = 0
plt.figure(figsize=(12, 10))
plt.plot(x1, y1,'r-',label='Truth Border of: $U_i(Pr(A|r_i),\phi_i)=-Pr(A|r_i)+f(\phi_i)$')
plt.plot(x1, y1,'r-',label=r'Truth Border of: $U_i(Pr(A|r_i),\phi_i)=-Pr(A|r_i)+f(\phi_i)$')
plt.plot(x1, x1, ':', linewidth=2)
plt.fill_between(x1, y1, z1, facecolor='blue', alpha=0.05, label='truth telling')
plt.fill_between(x1, z2, y1, facecolor='green', alpha=0.05, label='lying')
Expand Down
2 changes: 1 addition & 1 deletion lectures/wald_friedman.md
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ ax.plot(wf.π_grid, cost_L1, label='choose f1')
ax.plot(wf.π_grid, cost_L0, label='choose f0')
ax.plot(wf.π_grid,
np.amin(np.column_stack([h_star, cost_L0, cost_L1]),axis=1),
lw=15, alpha=0.1, color='b', label='$J(\pi)$')
lw=15, alpha=0.1, color='b', label=r'$J(\pi)$')

ax.annotate(r"$\beta$", xy=(β + 0.01, 0.5), fontsize=14)
ax.annotate(r"$\alpha$", xy=(α + 0.01, 0.5), fontsize=14)
Expand Down
4 changes: 2 additions & 2 deletions lectures/wealth_dynamics.md
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ gini_vals = []
for μ_r in μ_r_vals:
wdy = WealthDynamics(μ_r=μ_r)
gv, (f_vals, l_vals) = generate_lorenz_and_gini(wdy)
ax.plot(f_vals, l_vals, label=f'$\psi^*$ at $\mu_r = {μ_r:0.2}$')
ax.plot(f_vals, l_vals, label=fr'$\psi^*$ at $\mu_r = {μ_r:0.2}$')
gini_vals.append(gv)

ax.plot(f_vals, f_vals, label='equality')
Expand Down Expand Up @@ -522,7 +522,7 @@ gini_vals = []
for σ_r in σ_r_vals:
wdy = WealthDynamics(σ_r=σ_r)
gv, (f_vals, l_vals) = generate_lorenz_and_gini(wdy)
ax.plot(f_vals, l_vals, label=f'$\psi^*$ at $\sigma_r = {σ_r:0.2}$')
ax.plot(f_vals, l_vals, label=fr'$\psi^*$ at $\sigma_r = {σ_r:0.2}$')
gini_vals.append(gv)

ax.plot(f_vals, f_vals, label='equality')
Expand Down
Loading