|
2 | 2 | "cells": [ |
3 | 3 | { |
4 | 4 | "cell_type": "markdown", |
5 | | - "id": "c6359506", |
| 5 | + "id": "76c66ed6", |
6 | 6 | "metadata": {}, |
7 | 7 | "source": [ |
8 | 8 | "# Posterior Distributions for AR(1) Parameters" |
9 | 9 | ] |
10 | 10 | }, |
11 | 11 | { |
12 | 12 | "cell_type": "markdown", |
13 | | - "id": "4d2a9a1d", |
| 13 | + "id": "e7e3c20a", |
14 | 14 | "metadata": {}, |
15 | 15 | "source": [ |
16 | 16 | "# GPU\n", |
|
25 | 25 | { |
26 | 26 | "cell_type": "code", |
27 | 27 | "execution_count": null, |
28 | | - "id": "47f1b111", |
| 28 | + "id": "6952715b", |
29 | 29 | "metadata": { |
30 | 30 | "hide-output": false |
31 | 31 | }, |
|
36 | 36 | }, |
37 | 37 | { |
38 | 38 | "cell_type": "markdown", |
39 | | - "id": "bb3fa457", |
| 39 | + "id": "ff09b312", |
40 | 40 | "metadata": {}, |
41 | 41 | "source": [ |
42 | 42 | "In addition to what’s included in base Anaconda, we need to install the following packages" |
|
45 | 45 | { |
46 | 46 | "cell_type": "code", |
47 | 47 | "execution_count": null, |
48 | | - "id": "6639366f", |
| 48 | + "id": "65fce6ae", |
49 | 49 | "metadata": { |
50 | 50 | "hide-output": false |
51 | 51 | }, |
|
56 | 56 | }, |
57 | 57 | { |
58 | 58 | "cell_type": "markdown", |
59 | | - "id": "13f2c2e2", |
| 59 | + "id": "1e509cf6", |
60 | 60 | "metadata": {}, |
61 | 61 | "source": [ |
62 | 62 | "We’ll begin with some Python imports." |
|
65 | 65 | { |
66 | 66 | "cell_type": "code", |
67 | 67 | "execution_count": null, |
68 | | - "id": "b8576371", |
| 68 | + "id": "d90052f5", |
69 | 69 | "metadata": { |
70 | 70 | "hide-output": false |
71 | 71 | }, |
|
89 | 89 | }, |
90 | 90 | { |
91 | 91 | "cell_type": "markdown", |
92 | | - "id": "9f8aedb4", |
| 92 | + "id": "cc197b7b", |
93 | 93 | "metadata": {}, |
94 | 94 | "source": [ |
95 | 95 | "This lecture uses Bayesian methods offered by [pymc](https://www.pymc.io/projects/docs/en/stable/) and [numpyro](https://num.pyro.ai/en/stable/) to make statistical inferences about two parameters of a univariate first-order autoregression.\n", |
|
185 | 185 | { |
186 | 186 | "cell_type": "code", |
187 | 187 | "execution_count": null, |
188 | | - "id": "35aa76e8", |
| 188 | + "id": "0813473f", |
189 | 189 | "metadata": { |
190 | 190 | "hide-output": false |
191 | 191 | }, |
|
215 | 215 | { |
216 | 216 | "cell_type": "code", |
217 | 217 | "execution_count": null, |
218 | | - "id": "fe5008bf", |
| 218 | + "id": "6829658b", |
219 | 219 | "metadata": { |
220 | 220 | "hide-output": false |
221 | 221 | }, |
|
227 | 227 | }, |
228 | 228 | { |
229 | 229 | "cell_type": "markdown", |
230 | | - "id": "76facd42", |
| 230 | + "id": "60d4136b", |
231 | 231 | "metadata": {}, |
232 | 232 | "source": [ |
233 | 233 | "Now we shall use Bayes’ law to construct a posterior distribution, conditioning on the initial value of $ y_0 $.\n", |
|
239 | 239 | }, |
240 | 240 | { |
241 | 241 | "cell_type": "markdown", |
242 | | - "id": "b7715545", |
| 242 | + "id": "5e68f3fe", |
243 | 243 | "metadata": {}, |
244 | 244 | "source": [ |
245 | 245 | "## PyMC Implementation\n", |
|
251 | 251 | { |
252 | 252 | "cell_type": "code", |
253 | 253 | "execution_count": null, |
254 | | - "id": "0d794aae", |
| 254 | + "id": "091eb321", |
255 | 255 | "metadata": { |
256 | 256 | "hide-output": false |
257 | 257 | }, |
|
274 | 274 | }, |
275 | 275 | { |
276 | 276 | "cell_type": "markdown", |
277 | | - "id": "59a95a8e", |
| 277 | + "id": "6b656c43", |
278 | 278 | "metadata": {}, |
279 | 279 | "source": [ |
280 | 280 | "[pmc.sample](https://www.pymc.io/projects/docs/en/v5.10.0/api/generated/pymc.sample.html#pymc-sample) by default uses the NUTS samplers to generate samples as shown in the below cell:" |
|
283 | 283 | { |
284 | 284 | "cell_type": "code", |
285 | 285 | "execution_count": null, |
286 | | - "id": "c43150a6", |
| 286 | + "id": "de186b5e", |
287 | 287 | "metadata": { |
288 | 288 | "hide-output": false |
289 | 289 | }, |
|
296 | 296 | { |
297 | 297 | "cell_type": "code", |
298 | 298 | "execution_count": null, |
299 | | - "id": "8c58eb17", |
| 299 | + "id": "2cb0a0af", |
300 | 300 | "metadata": { |
301 | 301 | "hide-output": false |
302 | 302 | }, |
|
308 | 308 | }, |
309 | 309 | { |
310 | 310 | "cell_type": "markdown", |
311 | | - "id": "a567f1c4", |
| 311 | + "id": "0c365670", |
312 | 312 | "metadata": {}, |
313 | 313 | "source": [ |
314 | 314 | "Evidently, the posteriors aren’t centered on the true values of $ .5, 1 $ that we used to generate the data.\n", |
|
323 | 323 | { |
324 | 324 | "cell_type": "code", |
325 | 325 | "execution_count": null, |
326 | | - "id": "b414dbe0", |
| 326 | + "id": "9e300ad3", |
327 | 327 | "metadata": { |
328 | 328 | "hide-output": false |
329 | 329 | }, |
|
337 | 337 | }, |
338 | 338 | { |
339 | 339 | "cell_type": "markdown", |
340 | | - "id": "820a0465", |
| 340 | + "id": "94bf6a88", |
341 | 341 | "metadata": {}, |
342 | 342 | "source": [ |
343 | 343 | "Now we shall compute a posterior distribution after seeing the same data but instead assuming that $ y_0 $ is drawn from the stationary distribution.\n", |
|
354 | 354 | { |
355 | 355 | "cell_type": "code", |
356 | 356 | "execution_count": null, |
357 | | - "id": "3de10c77", |
| 357 | + "id": "21952b7f", |
358 | 358 | "metadata": { |
359 | 359 | "hide-output": false |
360 | 360 | }, |
|
380 | 380 | { |
381 | 381 | "cell_type": "code", |
382 | 382 | "execution_count": null, |
383 | | - "id": "908b298b", |
| 383 | + "id": "567297c7", |
384 | 384 | "metadata": { |
385 | 385 | "hide-output": false |
386 | 386 | }, |
|
395 | 395 | { |
396 | 396 | "cell_type": "code", |
397 | 397 | "execution_count": null, |
398 | | - "id": "918200c5", |
| 398 | + "id": "eb60c1e9", |
399 | 399 | "metadata": { |
400 | 400 | "hide-output": false |
401 | 401 | }, |
|
408 | 408 | { |
409 | 409 | "cell_type": "code", |
410 | 410 | "execution_count": null, |
411 | | - "id": "9de45d8a", |
| 411 | + "id": "0e3601fd", |
412 | 412 | "metadata": { |
413 | 413 | "hide-output": false |
414 | 414 | }, |
|
422 | 422 | }, |
423 | 423 | { |
424 | 424 | "cell_type": "markdown", |
425 | | - "id": "0c0441b4", |
| 425 | + "id": "779a53d1", |
426 | 426 | "metadata": {}, |
427 | 427 | "source": [ |
428 | 428 | "Please note how the posterior for $ \\rho $ has shifted to the right relative to when we conditioned on $ y_0 $ instead of assuming that $ y_0 $ is drawn from the stationary distribution.\n", |
|
439 | 439 | }, |
440 | 440 | { |
441 | 441 | "cell_type": "markdown", |
442 | | - "id": "cc5ab54f", |
| 442 | + "id": "8ad8727a", |
443 | 443 | "metadata": {}, |
444 | 444 | "source": [ |
445 | 445 | "## Numpyro Implementation" |
|
448 | 448 | { |
449 | 449 | "cell_type": "code", |
450 | 450 | "execution_count": null, |
451 | | - "id": "59295ee8", |
| 451 | + "id": "cb8feedd", |
452 | 452 | "metadata": { |
453 | 453 | "hide-output": false |
454 | 454 | }, |
|
484 | 484 | { |
485 | 485 | "cell_type": "code", |
486 | 486 | "execution_count": null, |
487 | | - "id": "f6fcb67f", |
| 487 | + "id": "5d482f7c", |
488 | 488 | "metadata": { |
489 | 489 | "hide-output": false |
490 | 490 | }, |
|
505 | 505 | { |
506 | 506 | "cell_type": "code", |
507 | 507 | "execution_count": null, |
508 | | - "id": "2e8e3c05", |
| 508 | + "id": "4ed5935f", |
509 | 509 | "metadata": { |
510 | 510 | "hide-output": false |
511 | 511 | }, |
|
525 | 525 | { |
526 | 526 | "cell_type": "code", |
527 | 527 | "execution_count": null, |
528 | | - "id": "fe205262", |
| 528 | + "id": "dedf4306", |
529 | 529 | "metadata": { |
530 | 530 | "hide-output": false |
531 | 531 | }, |
|
537 | 537 | { |
538 | 538 | "cell_type": "code", |
539 | 539 | "execution_count": null, |
540 | | - "id": "b3aa5224", |
| 540 | + "id": "3c02af17", |
541 | 541 | "metadata": { |
542 | 542 | "hide-output": false |
543 | 543 | }, |
|
548 | 548 | }, |
549 | 549 | { |
550 | 550 | "cell_type": "markdown", |
551 | | - "id": "74f5b94b", |
| 551 | + "id": "a52700dc", |
552 | 552 | "metadata": {}, |
553 | 553 | "source": [ |
554 | 554 | "Next, we again compute the posterior under the assumption that $ y_0 $ is drawn from the stationary distribution, so that\n", |
|
563 | 563 | { |
564 | 564 | "cell_type": "code", |
565 | 565 | "execution_count": null, |
566 | | - "id": "e3eb3899", |
| 566 | + "id": "b142ab27", |
567 | 567 | "metadata": { |
568 | 568 | "hide-output": false |
569 | 569 | }, |
|
588 | 588 | { |
589 | 589 | "cell_type": "code", |
590 | 590 | "execution_count": null, |
591 | | - "id": "cb2b4931", |
| 591 | + "id": "b55ea30f", |
592 | 592 | "metadata": { |
593 | 593 | "hide-output": false |
594 | 594 | }, |
|
608 | 608 | { |
609 | 609 | "cell_type": "code", |
610 | 610 | "execution_count": null, |
611 | | - "id": "4a46d4a0", |
| 611 | + "id": "3620d727", |
612 | 612 | "metadata": { |
613 | 613 | "hide-output": false |
614 | 614 | }, |
|
620 | 620 | { |
621 | 621 | "cell_type": "code", |
622 | 622 | "execution_count": null, |
623 | | - "id": "1cdfc066", |
| 623 | + "id": "67bf8a04", |
624 | 624 | "metadata": { |
625 | 625 | "hide-output": false |
626 | 626 | }, |
|
631 | 631 | }, |
632 | 632 | { |
633 | 633 | "cell_type": "markdown", |
634 | | - "id": "a13d08ea", |
| 634 | + "id": "c38f52d9", |
635 | 635 | "metadata": {}, |
636 | 636 | "source": [ |
637 | 637 | "Look what happened to the posterior!\n", |
|
646 | 646 | } |
647 | 647 | ], |
648 | 648 | "metadata": { |
649 | | - "date": 1763691523.9891539, |
| 649 | + "date": 1763717903.4266343, |
650 | 650 | "filename": "ar1_bayes.md", |
651 | 651 | "kernelspec": { |
652 | 652 | "display_name": "Python", |
|
0 commit comments