Skip to content

Commit 4255262

Browse files
longye-tianmmckyclaudeCopilot
authored
[kalman] update RV notation (#900)
* 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]>
1 parent 5bf4394 commit 4255262

1 file changed

Lines changed: 20 additions & 18 deletions

File tree

‎lectures/kalman.md‎

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -522,13 +522,13 @@ The latter represents a linear state space model of the form
522522

523523
$$
524524
\begin{aligned}
525-
x_{t+1} & = A x_t + C w_{t+1}
525+
X_{t+1} & = A X_t + C w_{t+1}
526526
\\
527-
y_t & = G x_t + H v_t
527+
Y_t & = G X_t + H v_t
528528
\end{aligned}
529529
$$
530530

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.
532532

533533
To connect this with the notation of this lecture we set
534534

@@ -557,13 +557,13 @@ on {cite}`Ljungqvist2012`, section 2.9.2.
557557
Suppose that
558558

559559
* 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
561561

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$.
563563

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.
565565

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$.
567567

568568
As shown in {cite}`Ljungqvist2012`, sections 2.9.1--2.9.2, these distributions asymptotically put all mass on the unknown value $\theta$.
569569

@@ -585,7 +585,7 @@ Your figure should -- modulo randomness -- look something like this
585585

586586
```{code-cell} ipython3
587587
# Parameters
588-
θ = 10 # Constant value of state x_t
588+
θ = 10 # Constant value of state X_t
589589
A, C, G, H = 1, 0, 1, 1
590590
ss = LinearStateSpace(A, C, G, H, mu_0=θ)
591591
@@ -645,7 +645,7 @@ Plot $z_t$ against $t$, setting $\epsilon = 0.1$ and $T = 600$.
645645

646646
```{code-cell} ipython3
647647
ϵ = 0.1
648-
θ = 10 # Constant value of state x_t
648+
θ = 10 # Constant value of state X_t
649649
A, C, G, H = 1, 0, 1, 1
650650
ss = LinearStateSpace(A, C, G, H, mu_0=θ)
651651
@@ -682,25 +682,27 @@ plt.show()
682682
:label: kalman_ex3
683683
```
684684

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}$).
686686

687687
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}$.
689689

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}$.
692692

693693
The conditional expectation is known to be the optimal prediction method in terms of minimizing mean squared error.
694694

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}]$)
696696

697697
Thus we are comparing the Kalman filter against a competitor who has more
698698
information (in the sense of being able to observe the latent state) and
699699
behaves optimally in terms of minimizing squared error.
700700

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.
702702

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.
704706

705707
For the parameters, set $G = I, R = 0.5 I$ and $Q = 0.3 I$, where $I$ is
706708
the $2 \times 2$ identity.
@@ -731,7 +733,7 @@ $$
731733

732734
and $\mu_0 = (8, 8)$.
733735

734-
Finally, set $x_0 = (0, 0)$.
736+
Finally, set the realized initial state to $x_0 = (0, 0)$.
735737

736738

737739
```{exercise-end}
@@ -806,5 +808,5 @@ Try varying the coefficient $0.3$ in $Q = 0.3 I$ up and down.
806808
807809
Observe how the diagonal values in the stationary solution $\Sigma$ (see {eq}`kalman_dare`) increase and decrease in line with this coefficient.
808810
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.
810812
```

0 commit comments

Comments
 (0)