You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 4255262
Browse filesBrowse the repository at this point in the historyBrowse files
* update RV notation
* [kalman] use X_t in code comments for state RV
Update the two "Constant value of state x_t" comments to X_t so the
code comments match the uppercase random-variable convention used in
the surrounding prose. The realized initial value x_0 comment stays
lowercase by design.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
* grammar fix from copilot
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
---------
Co-authored-by: Matt McKay <[email protected]>
Co-authored-by: Claude Opus 4.8 <[email protected]>
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Copy file name to clipboardExpand all lines: lectures/kalman.md
+20-18Lines changed: 20 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -522,13 +522,13 @@ The latter represents a linear state space model of the form
522
522
523
523
$$
524
524
\begin{aligned}
525
-
x_{t+1} & = A x_t + C w_{t+1}
525
+
X_{t+1} & = A X_t + C w_{t+1}
526
526
\\
527
-
y_t & = G x_t + H v_t
527
+
Y_t & = G X_t + H v_t
528
528
\end{aligned}
529
529
$$
530
530
531
-
where the shocks $w_t$ and $v_t$ are IID standard normals.
531
+
where $X_t$ and $Y_t$ denote random variables, and the shocks $w_t$ and $v_t$ are IID standard normals.
532
532
533
533
To connect this with the notation of this lecture we set
534
534
@@ -557,13 +557,13 @@ on {cite}`Ljungqvist2012`, section 2.9.2.
557
557
Suppose that
558
558
559
559
* all variables are scalars
560
-
* the hidden state $\{x_t\}$ is in fact constant, equal to some $\theta \in \mathbb{R}$ unknown to the modeler
560
+
* the hidden state $\{X_t\}$ is in fact constant, equal to some $\theta \in \mathbb{R}$ unknown to the modeler
561
561
562
-
State dynamics are therefore given by {eq}`kl_xdynam` with $A=1$, $Q=0$ and $x_0 = \theta$.
562
+
State dynamics are therefore given by {eq}`kl_xdynam` with $A=1$, $Q=0$ and $X_0 = \theta$.
563
563
564
-
The measurement equation is $y_t = \theta + v_t$ where $v_t$ is $N(0,1)$ and IID.
564
+
The measurement equation is $Y_t = \theta + v_t$ where $v_t$ is $N(0,1)$ and IID.
565
565
566
-
The task of this exercise to simulate the model and, using the code from `kalman.py`, plot the first five predictive densities $p_t(x) = N(\mu_t, \Sigma_t)$.
566
+
The task of this exercise is to simulate the model and, using the code from `kalman.py`, plot the first five predictive densities $p_t(x) = N(\mu_t, \Sigma_t)$ for $X_t$.
567
567
568
568
As shown in {cite}`Ljungqvist2012`, sections 2.9.1--2.9.2, these distributions asymptotically put all mass on the unknown value $\theta$.
569
569
@@ -585,7 +585,7 @@ Your figure should -- modulo randomness -- look something like this
585
585
586
586
```{code-cell} ipython3
587
587
# Parameters
588
-
θ = 10 # Constant value of state x_t
588
+
θ = 10 # Constant value of state X_t
589
589
A, C, G, H = 1, 0, 1, 1
590
590
ss = LinearStateSpace(A, C, G, H, mu_0=θ)
591
591
@@ -645,7 +645,7 @@ Plot $z_t$ against $t$, setting $\epsilon = 0.1$ and $T = 600$.
645
645
646
646
```{code-cell} ipython3
647
647
ϵ = 0.1
648
-
θ = 10 # Constant value of state x_t
648
+
θ = 10 # Constant value of state X_t
649
649
A, C, G, H = 1, 0, 1, 1
650
650
ss = LinearStateSpace(A, C, G, H, mu_0=θ)
651
651
@@ -682,25 +682,27 @@ plt.show()
682
682
:label: kalman_ex3
683
683
```
684
684
685
-
As discussed {ref}`above <kalman_convergence>`, if the shock sequence $\{W_t\}$ is not degenerate, then it is not in general possible to predict $x_t$ without error at time $t-1$ (and this would be the case even if we could observe $x_{t-1}$).
685
+
As discussed {ref}`above <kalman_convergence>`, if the shock sequence $\{W_t\}$ is not degenerate, then it is not in general possible to predict $X_t$ without error at time $t-1$ (and this would be the case even if we could observe $X_{t-1}$).
686
686
687
687
Let's now compare the prediction $\mu_t$ made by the Kalman filter
688
-
against a competitor who **is** allowed to observe $x_{t-1}$.
688
+
against a competitor who **is** allowed to observe $X_{t-1}$.
689
689
690
-
This competitor will use the conditional expectation $\mathbb E[x_t
691
-
\,|\,x_{t-1}]$, which in this case is $A x_{t-1}$.
690
+
This competitor will use the conditional expectation $\mathbb E[X_t
691
+
\,|\,X_{t-1}]$, which in this case is $A X_{t-1}$.
692
692
693
693
The conditional expectation is known to be the optimal prediction method in terms of minimizing mean squared error.
694
694
695
-
(More precisely, the minimizer of $\mathbb E \,\|x_t - g(x_{t-1}) \|^2$ with respect to $g$ is $g^*(x_{t-1}) := \mathbb E[x_t\,|\,x_{t-1}]$)
695
+
(More precisely, the minimizer of $\mathbb E \,\|X_t - g(X_{t-1}) \|^2$ with respect to $g$ is $g^*(X_{t-1}) := \mathbb E[X_t\,|\,X_{t-1}]$)
696
696
697
697
Thus we are comparing the Kalman filter against a competitor who has more
698
698
information (in the sense of being able to observe the latent state) and
699
699
behaves optimally in terms of minimizing squared error.
700
700
701
-
Our horse race will be assessed in terms of squared error.
701
+
Our horse race will be assessed in terms of realized squared error.
702
702
703
-
In particular, your task is to generate a graph plotting observations of both $\| x_t - A x_{t-1} \|^2$ and $\| x_t - \mu_t \|^2$ against $t$ for $t = 1, \ldots, 49$.
703
+
In particular, your task is to generate a graph plotting simulated realizations of both $\| X_t - A X_{t-1} \|^2$ and $\| X_t - \mu_t \|^2$ against $t$ for $t = 1, \ldots, 49$.
704
+
705
+
In the code below, `x[:, t]` is the realized value of $X_t$ along the simulated path.
704
706
705
707
For the parameters, set $G = I, R = 0.5 I$ and $Q = 0.3 I$, where $I$ is
706
708
the $2 \times 2$ identity.
@@ -731,7 +733,7 @@ $$
731
733
732
734
and $\mu_0 = (8, 8)$.
733
735
734
-
Finally, set $x_0 = (0, 0)$.
736
+
Finally, set the realized initial state to $x_0 = (0, 0)$.
735
737
736
738
737
739
```{exercise-end}
@@ -806,5 +808,5 @@ Try varying the coefficient $0.3$ in $Q = 0.3 I$ up and down.
806
808
807
809
Observe how the diagonal values in the stationary solution $\Sigma$ (see {eq}`kalman_dare`) increase and decrease in line with this coefficient.
808
810
809
-
The interpretation is that more randomness in the law of motion for $x_t$ causes more (permanent) uncertainty in prediction.
811
+
The interpretation is that more randomness in the law of motion for $X_t$ causes more (permanent) uncertainty in prediction.
0 commit comments