Skip to content

Commit ffbe583

Browse files
committed
fix markov_perf deprecations
1 parent 1775aa0 commit ffbe583

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

lectures/markov_perf.md

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ jupytext:
33
text_representation:
44
extension: .md
55
format_name: myst
6+
format_version: 0.13
7+
jupytext_version: 1.16.7
68
kernelspec:
7-
display_name: Python 3
9+
display_name: Python 3 (ipykernel)
810
language: python
911
name: python3
1012
---
@@ -29,10 +31,9 @@ kernelspec:
2931

3032
In addition to what's in Anaconda, this lecture will need the following libraries:
3133

32-
```{code-cell} ipython
33-
---
34-
tags: [hide-output]
35-
---
34+
```{code-cell} ipython3
35+
:tags: [hide-output]
36+
3637
!pip install quantecon
3738
```
3839

@@ -57,9 +58,8 @@ Other references include chapter 7 of {cite}`Ljungqvist2012`.
5758

5859
Let's start with some standard imports:
5960

60-
```{code-cell} ipython
61+
```{code-cell} ipython3
6162
import matplotlib.pyplot as plt
62-
plt.rcParams["figure.figsize"] = (11, 5) #set default figure size
6363
import numpy as np
6464
import quantecon as qe
6565
```
@@ -431,8 +431,10 @@ Consider the previously presented duopoly model with parameter values of:
431431

432432
From these, we compute the infinite horizon MPE using the preceding code
433433

434-
```{code-cell} python3
434+
```{code-cell} ipython3
435435
:load: _static/lecture_specific/markov_perf/duopoly_mpe.py
436+
437+
436438
```
437439

438440
Running the code produces the following output.
@@ -443,7 +445,7 @@ In particular, let's take F2 as computed above, plug it into {eq}`eq_mpe_p1p` an
443445

444446
We hope that the resulting policy will agree with F1 as computed above
445447

446-
```{code-cell} python3
448+
```{code-cell} ipython3
447449
Λ1 = A - B2 @ F2
448450
lq1 = qe.LQ(Q1, R1, Λ1, B1, beta=β)
449451
P1_ih, F1_ih, d = lq1.stationary_values()
@@ -454,7 +456,7 @@ This is close enough for rock and roll, as they say in the trade.
454456

455457
Indeed, np.allclose agrees with our assessment
456458

457-
```{code-cell} python3
459+
```{code-cell} ipython3
458460
np.allclose(F1, F1_ih)
459461
```
460462

@@ -470,7 +472,7 @@ The following program
470472
* computes the evolution of $x_t$ using {eq}`eq_mpe_cle`.
471473
* extracts and plots industry output $q_t = q_{1t} + q_{2t}$ and price $p_t = a_0 - a_1 q_t$.
472474

473-
```{code-cell} python3
475+
```{code-cell} ipython3
474476
AF = A - B1 @ F1 - B2 @ F2
475477
n = 20
476478
x = np.empty((3, n))
@@ -527,7 +529,7 @@ The optimal policy in the monopolist case can be computed using [QuantEcon.py](h
527529

528530
First, let's compute the duopoly MPE under the stated parameters
529531

530-
```{code-cell} python3
532+
```{code-cell} ipython3
531533
# == Parameters == #
532534
a0 = 10.0
533535
a1 = 2.0
@@ -558,7 +560,7 @@ F1, F2, P1, P2 = qe.nnash(A, B1, B2, R1, R2, Q1,
558560
Now we evaluate the time path of industry output and prices given
559561
initial condition $q_{10} = q_{20} = 1$.
560562

561-
```{code-cell} python3
563+
```{code-cell} ipython3
562564
AF = A - B1 @ F1 - B2 @ F2
563565
n = 20
564566
x = np.empty((3, n))
@@ -600,7 +602,7 @@ in the law of motion $x_{t+1} = A x_t + B u_t$.
600602
We solve for the optimal policy $u_t = - Fx_t$ and track the
601603
resulting dynamics of $\{q_t\}$, starting at $q_0 = 2.0$.
602604

603-
```{code-cell} python3
605+
```{code-cell} ipython3
604606
R = a1
605607
Q = γ
606608
A = B = 1
@@ -613,13 +615,13 @@ x0 = qm[0] - q_bar
613615
x = x0
614616
for i in range(1, n):
615617
x = A * x - B * F * x
616-
qm[i] = float(x) + q_bar
618+
qm[i] = float(x.item()) + q_bar
617619
pm = a0 - a1 * qm
618620
```
619621

620622
Let's have a look at the different time paths
621623

622-
```{code-cell} python3
624+
```{code-cell} ipython3
623625
fig, axes = plt.subplots(2, 1, figsize=(9, 9))
624626
625627
ax = axes[0]
@@ -712,7 +714,7 @@ The exercise is to calculate these matrices and compute the following figures.
712714

713715
The first figure shows the dynamics of inventories for each firm when the parameters are
714716

715-
```{code-cell} python3
717+
```{code-cell} ipython3
716718
δ = 0.02
717719
D = np.array([[-1, 0.5], [0.5, -1]])
718720
b = np.array([25, 25])
@@ -743,7 +745,7 @@ In this exercise, reproduce the figure when $\delta = 0.02$.
743745

744746
We treat the case $\delta = 0.02$
745747

746-
```{code-cell} python3
748+
```{code-cell} ipython3
747749
δ = 0.02
748750
D = np.array([[-1, 0.5], [0.5, -1]])
749751
b = np.array([25, 25])
@@ -772,7 +774,7 @@ $$
772774

773775
we set up the matrices as follows:
774776

775-
```{code-cell} python3
777+
```{code-cell} ipython3
776778
# == Create matrices needed to compute the Nash feedback equilibrium == #
777779
778780
A = np.array([[δ_1, 0, -δ_1 * b[0]],
@@ -812,7 +814,7 @@ M2 = np.copy(M1)
812814

813815
We can now compute the equilibrium using `qe.nnash`
814816

815-
```{code-cell} python3
817+
```{code-cell} ipython3
816818
F1, F2, P1, P2 = qe.nnash(A, B1, B2, R1,
817819
R2, Q1, Q2, S1,
818820
S2, W1, W2, M1, M2)
@@ -827,7 +829,7 @@ print(F2)
827829
Now let's look at the dynamics of inventories, and reproduce the graph
828830
corresponding to $\delta = 0.02$
829831

830-
```{code-cell} python3
832+
```{code-cell} ipython3
831833
AF = A - B1 @ F1 - B2 @ F2
832834
n = 25
833835
x = np.empty((3, n))
@@ -843,6 +845,3 @@ ax.set_title(rf'$\delta = {δ}$')
843845
ax.legend()
844846
plt.show()
845847
```
846-
847-
```{solution-end}
848-
```

0 commit comments

Comments
 (0)