Skip to content

Commit 1775aa0

Browse files
committed
fix deprecations warnings in kalman_2
1 parent 14b5359 commit 1775aa0

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

lectures/kalman_2.md

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ jupytext:
44
extension: .md
55
format_name: myst
66
format_version: 0.13
7-
jupytext_version: 1.14.4
7+
jupytext_version: 1.16.7
88
kernelspec:
99
display_name: Python 3 (ipykernel)
1010
language: python
@@ -237,7 +237,7 @@ for t in range(1, T):
237237
x_hat, Σ = kalman.x_hat, kalman.Sigma
238238
Σ_t[:, :, t-1] = Σ
239239
x_hat_t[:, t-1] = x_hat.reshape(-1)
240-
y_hat_t[t-1] = worker.G @ x_hat
240+
[y_hat_t[t-1]] = worker.G @ x_hat
241241
242242
x_hat_t = np.concatenate((x[:, 1][:, np.newaxis],
243243
x_hat_t), axis=1)
@@ -253,7 +253,6 @@ We also plot $E [u_0 | y^{t-1}]$, which is the firm inference about a worker's
253253
We can watch as the firm's inference $E [u_0 | y^{t-1}]$ of the worker's work ethic converges toward the hidden $u_0$, which is not directly observed by the firm.
254254

255255
```{code-cell} ipython3
256-
257256
fig, ax = plt.subplots(1, 2)
258257
259258
ax[0].plot(y_hat_t, label=r'$E[y_t| y^{t-1}]$')
@@ -273,6 +272,7 @@ ax[1].legend()
273272
fig.tight_layout()
274273
plt.show()
275274
```
275+
276276
## Some Computational Experiments
277277

278278
Let's look at $\Sigma_0$ and $\Sigma_T$ in order to see how much the firm learns about the hidden state during the horizon we have set.
@@ -290,7 +290,6 @@ Evidently, entries in the conditional covariance matrix become smaller over tim
290290
It is enlightening to portray how conditional covariance matrices $\Sigma_t$ evolve by plotting confidence ellipsoides around $E [x_t |y^{t-1}] $ at various $t$'s.
291291

292292
```{code-cell} ipython3
293-
294293
# Create a grid of points for contour plotting
295294
h_range = np.linspace(x_hat_t[0, :].min()-0.5*Σ_t[0, 0, 1],
296295
x_hat_t[0, :].max()+0.5*Σ_t[0, 0, 1], 100)
@@ -338,7 +337,6 @@ For example, let's say $h_0 = 0$ and $u_0 = 4$.
338337
Here is one way to do this.
339338

340339
```{code-cell} ipython3
341-
342340
# For example, we might want h_0 = 0 and u_0 = 4
343341
mu_0 = np.array([0.0, 4.0])
344342
@@ -361,7 +359,6 @@ print('u_0 =', u_0)
361359
Another way to accomplish the same goal is to use the following code.
362360

363361
```{code-cell} ipython3
364-
365362
# If we want to set the initial
366363
# h_0 = hhat_0 = 0 and u_0 = uhhat_0 = 4.0:
367364
worker = create_worker(hhat_0=0.0, uhat_0=4.0)
@@ -398,8 +395,8 @@ for t in range(1, T):
398395
kalman.update(y[t])
399396
x_hat, Σ = kalman.x_hat, kalman.Sigma
400397
Σ_t.append(Σ)
401-
y_hat_t[t-1] = worker.G @ x_hat
402-
u_hat_t[t-1] = x_hat[1]
398+
[y_hat_t[t-1]] = worker.G @ x_hat
399+
[u_hat_t[t-1]] = x_hat[1]
403400
404401
405402
# Generate plots for y_hat_t and u_hat_t
@@ -426,10 +423,9 @@ plt.show()
426423
More generally, we can change some or all of the parameters defining a worker in our `create_worker`
427424
namedtuple.
428425

429-
Here is an example.
426+
Here is an example.
430427

431428
```{code-cell} ipython3
432-
433429
# We can set these parameters when creating a worker -- just like classes!
434430
hard_working_worker = create_worker(α=.4, β=.8,
435431
hhat_0=7.0, uhat_0=100, σ_h=2.5, σ_u=3.2)
@@ -475,8 +471,8 @@ def simulate_workers(worker, T, ax, mu_0=None, Sigma_0=None,
475471
kalman.update(y[i])
476472
x_hat, Σ = kalman.x_hat, kalman.Sigma
477473
Σ_t.append(Σ)
478-
y_hat_t[i] = worker.G @ x_hat
479-
u_hat_t[i] = x_hat[1]
474+
[y_hat_t[i]] = worker.G @ x_hat
475+
[u_hat_t[i]] = x_hat[1]
480476
481477
if diff == True:
482478
title = ('Difference between inferred and true work ethic over time'
@@ -503,7 +499,6 @@ def simulate_workers(worker, T, ax, mu_0=None, Sigma_0=None,
503499
```
504500

505501
```{code-cell} ipython3
506-
507502
num_workers = 3
508503
T = 50
509504
fig, ax = plt.subplots(figsize=(7, 7))
@@ -516,7 +511,6 @@ plt.show()
516511
```
517512

518513
```{code-cell} ipython3
519-
520514
# We can also generate plots of u_t:
521515
522516
T = 50
@@ -539,7 +533,6 @@ plt.show()
539533
```
540534

541535
```{code-cell} ipython3
542-
543536
# We can also use exact u_0=1 and h_0=2 for all workers
544537
545538
T = 50
@@ -568,7 +561,6 @@ plt.show()
568561
```
569562

570563
```{code-cell} ipython3
571-
572564
# We can generate a plot for only one of the workers:
573565
574566
T = 50

0 commit comments

Comments
 (0)