@@ -4,7 +4,7 @@ jupytext:
44 extension : .md
55 format_name : myst
66 format_version : 0.13
7- jupytext_version : 1.16.2
7+ jupytext_version : 1.16.1
88kernelspec :
99 display_name : Python 3 (ipykernel)
1010 language : python
@@ -49,7 +49,12 @@ We will use the following imports:
4949import numpy as np
5050import matplotlib.pyplot as plt
5151from matplotlib import cm
52- plt.rcParams["figure.figsize"] = (11, 5) #set default figure size
52+
53+ # Custom figsize for this lecture
54+ plt.rcParams["figure.figsize"] = (11, 5)
55+
56+ # Set decimal printing to 3 decimal places
57+ np.set_printoptions(precision=3, suppress=True)
5358```
5459
5560## Samuelson's model
@@ -142,8 +147,8 @@ T = 80
142147α_1 = 1.53
143148α_2 = -.9
144149
145- y_neg1 = 28. # y_{-1}
146- y_0 = 24.
150+ y_neg1 = 28.0 # y_{-1}
151+ y_0 = 24.0
147152```
148153
149154Now we construct $A$ and $b$.
@@ -197,6 +202,13 @@ point precision:
197202np.allclose(y, y_second_method)
198203```
199204
205+ $A$ is invertible as it is lower triangular and [ its diagonal entries are non-zero] ( https://www.statlect.com/matrix-algebra/triangular-matrix )
206+
207+ ``` {code-cell} ipython3
208+ # Check if A is lower triangular
209+ np.allclose(A, np.tril(A))
210+ ```
211+
200212``` {note}
201213In general, `np.linalg.solve` is more numerically stable than using
202214`np.linalg.inv` directly.
@@ -392,7 +404,13 @@ class population_moments:
392404 Parameters:
393405 α_0, α_1, α_2, T, y_neg1, y_0
394406 """
395- def __init__(self, α_0, α_1, α_2, T, y_neg1, y_0, σ_u):
407+ def __init__(self, α_0=10.0,
408+ α_1=1.53,
409+ α_2=-.9,
410+ T=80,
411+ y_neg1=28.0,
412+ y_0=24.0,
413+ σ_u=1):
396414
397415 # compute A
398416 A = np.identity(T)
@@ -437,8 +455,7 @@ class population_moments:
437455 return self.μ_y, self.Σ_y
438456
439457
440- series_process = population_moments(
441- α_0=10.0, α_1=1.53, α_2=-.9, T=80, y_neg1=28., y_0=24., σ_u=1)
458+ series_process = population_moments()
442459
443460μ_y, Σ_y = series_process.get_moments()
444461A_inv = series_process.A_inv
@@ -483,12 +500,17 @@ Notice how the population variance increases and asymptotes.
483500Let's print out the covariance matrix $\Sigma_y$ for a time series $y$.
484501
485502```{code-cell} ipython3
486- series_process = population_moments(
487- α_0=0, α_1=.8, α_2=0, T=6, y_neg1=0., y_0=0., σ_u=1)
503+ series_process = population_moments(α_0=0,
504+ α_1=.8,
505+ α_2=0,
506+ T=6,
507+ y_neg1=0.,
508+ y_0=0.,
509+ σ_u=1)
488510
489511μ_y, Σ_y = series_process.get_moments()
490512print("μ_y = ", μ_y)
491- print("Σ_y = ", Σ_y)
513+ print("Σ_y = \n ", Σ_y)
492514```
493515
494516Notice that the covariance between $y_t$ and $y_{t-1}$ -- the elements on the superdiagonal -- are *not* identical.
@@ -502,9 +524,9 @@ We describe how to do that in [Linear State Space Models](https://python.quantec
502524But just to set the stage for that analysis, let's print out the bottom right corner of $\Sigma_y$.
503525
504526```{code-cell} ipython3
505- series_process = population_moments(
506- α_0=10.0, α_1=1.53, α_2=-.9, T=80, y_neg1=28., y_0=24., σ_u=1)
527+ series_process = population_moments()
507528μ_y, Σ_y = series_process.get_moments()
529+
508530print("bottom right corner of Σ_y = \n", Σ_y[72:,72:])
509531```
510532
@@ -529,26 +551,13 @@ To study the structure of $A^{-1}$, we shall print just up to $3$ decimals.
529551Let's begin by printing out just the upper left hand corner of $A^{-1}$.
530552
531553```{code-cell} ipython3
532- with np.printoptions(precision=3, suppress=True):
533- print(A_inv[0:7,0:7])
554+ print(A_inv[0:7,0:7])
534555```
535556
536557Evidently, $A^{-1}$ is a lower triangular matrix.
537558
538-
539- Let's print out the lower right hand corner of $A^{-1}$ and stare at it.
540-
541- ```{code-cell} ipython3
542- with np.printoptions(precision=3, suppress=True):
543- print(A_inv[72:,72:])
544- ```
545-
546559Notice how every row ends with the previous row's pre-diagonal entries.
547560
548-
549-
550-
551-
552561Since $A^{-1}$ is lower triangular, each row represents $ y_t$ for a particular $t$ as the sum of
553562- a time-dependent function $A^{-1} b$ of the initial conditions incorporated in $b$, and
554563- a weighted sum of current and past values of the IID shocks $\{u_t\}$.
@@ -566,9 +575,6 @@ This is a **moving average** representation with time-varying coefficients.
566575Just as system {eq}`eq:eqma` constitutes a
567576**moving average** representation for $y$, system {eq}`eq:eqar` constitutes an **autoregressive** representation for $y$.
568577
569-
570-
571-
572578## A forward looking model
573579
574580Samuelson’s model is *backward looking* in the sense that we give it *initial conditions* and let it
@@ -638,7 +644,7 @@ for i in range(T):
638644```
639645
640646```{code-cell} ipython3
641- B
647+ print(B)
642648```
643649
644650```{code-cell} ipython3
0 commit comments