Skip to content

Commit aaab768

Browse files
committed
fix linear_models
1 parent fef0379 commit aaab768

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

lectures/linear_models.md

Lines changed: 23 additions & 19 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
---
@@ -33,10 +35,9 @@ kernelspec:
3335

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

36-
```{code-cell} ipython
37-
---
38-
tags: [hide-output]
39-
---
38+
```{code-cell} ipython3
39+
:tags: [hide-output]
40+
4041
!pip install quantecon
4142
```
4243

@@ -65,9 +66,8 @@ Its many applications include:
6566

6667
Let's start with some imports:
6768

68-
```{code-cell} ipython
69+
```{code-cell} ipython3
6970
import matplotlib.pyplot as plt
70-
plt.rcParams["figure.figsize"] = (11, 5) #set default figure size
7171
import numpy as np
7272
from quantecon import LinearStateSpace
7373
from scipy.stats import norm
@@ -186,7 +186,8 @@ You can confirm that under these definitions, {eq}`st_space_rep` and {eq}`st_ex_
186186
The next figure shows the dynamics of this process when $\phi_0 = 1.1, \phi_1=0.8, \phi_2 = -0.8, y_0 = y_{-1} = 1$.
187187

188188
(lss_sode_fig)=
189-
```{code-cell} python3
189+
190+
```{code-cell} ipython3
190191
def plot_lss(A,
191192
C,
192193
G,
@@ -205,7 +206,7 @@ def plot_lss(A,
205206
plt.show()
206207
```
207208

208-
```{code-cell} python3
209+
```{code-cell} ipython3
209210
ϕ_0, ϕ_1, ϕ_2 = 1.1, 0.8, -0.8
210211
211212
A = [[1, 0, 0 ],
@@ -269,7 +270,8 @@ y_{-3} = 1
269270
$$
270271

271272
(lss_uap_fig)=
272-
```{code-cell} python3
273+
274+
```{code-cell} ipython3
273275
ϕ_1, ϕ_2, ϕ_3, ϕ_4 = 0.5, -0.2, 0, 0.5
274276
σ = 0.2
275277
@@ -651,7 +653,7 @@ The system in question is the univariate autoregressive model {eq}`eq_ar_rep`.
651653

652654
The values of $y_T$ are represented by black dots in the left-hand figure
653655

654-
```{code-cell} python3
656+
```{code-cell} ipython3
655657
def cross_section_plot(A,
656658
C,
657659
G,
@@ -695,7 +697,7 @@ def cross_section_plot(A,
695697
plt.show()
696698
```
697699

698-
```{code-cell} python3
700+
```{code-cell} ipython3
699701
ϕ_1, ϕ_2, ϕ_3, ϕ_4 = 0.5, -0.2, 0, 0.5
700702
σ = 0.1
701703
@@ -716,14 +718,14 @@ that shows relative frequencies from our sample of 20 $y_T$'s.
716718

717719
Here is another figure, this time with 100 observations
718720

719-
```{code-cell} python3
721+
```{code-cell} ipython3
720722
t = 100
721723
cross_section_plot(A_2, C_2, G_2, T=t)
722724
```
723725

724726
Let's now try with 500,000 observations, showing only the histogram (without rotation)
725727

726-
```{code-cell} python3
728+
```{code-cell} ipython3
727729
T = 100
728730
ymin=-0.8
729731
ymax=1.25
@@ -733,7 +735,7 @@ ar = LinearStateSpace(A_2, C_2, G_2, mu_0=np.ones(4))
733735
fig, ax = plt.subplots()
734736
x, y = ar.simulate(sample_size)
735737
mu_x, mu_y, Sigma_x, Sigma_y, Sigma_yx = ar.stationary_distributions()
736-
f_y = norm(loc=float(mu_y), scale=float(np.sqrt(Sigma_y)))
738+
f_y = norm(loc=float(mu_y.item()), scale=float(np.sqrt(Sigma_y.item())))
737739
y = y.flatten()
738740
ygrid = np.linspace(ymin, ymax, 150)
739741
@@ -776,7 +778,8 @@ The parameters are the same as for the preceding figures,
776778
and the sample size is relatively small ($I=20$).
777779

778780
(lss_em_fig)=
779-
```{code-cell} python3
781+
782+
```{code-cell} ipython3
780783
I = 20
781784
T = 50
782785
ymin = -0.5
@@ -904,7 +907,7 @@ Let's look at some more time series from the same model that we analyzed above.
904907
This picture shows cross-sectional distributions for $y$ at times
905908
$T, T', T''$
906909

907-
```{code-cell} python3
910+
```{code-cell} ipython3
908911
def cross_plot(A,
909912
C,
910913
G,
@@ -944,7 +947,7 @@ def cross_plot(A,
944947
plt.show()
945948
```
946949

947-
```{code-cell} python3
950+
```{code-cell} ipython3
948951
cross_plot(A_2, C_2, G_2)
949952
```
950953

@@ -988,7 +991,8 @@ where $\mu_{\infty}$ and $\Sigma_{\infty}$ are fixed points of {eq}`lss_mut_line
988991
Let's see what happens to the preceding figure if we start $x_0$ at the stationary distribution.
989992

990993
(lss_s_fig)=
991-
```{code-cell} python3
994+
995+
```{code-cell} ipython3
992996
cross_plot(A_2, C_2, G_2, steady_state='True')
993997
```
994998

0 commit comments

Comments
 (0)