Skip to content

Commit

Permalink
deploy: 75a181c
Browse files Browse the repository at this point in the history
  • Loading branch information
mmcky committed Jan 31, 2024
1 parent 8906b9b commit 833d8b3
Show file tree
Hide file tree
Showing 53 changed files with 2,174 additions and 2,174 deletions.
66 changes: 33 additions & 33 deletions _notebooks/ar1_bayes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "markdown",
"id": "b93518d2",
"id": "0dd278e7",
"metadata": {},
"source": [
"# Posterior Distributions for AR(1) Parameters\n",
Expand All @@ -13,7 +13,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "0b1b544a",
"id": "31a55044",
"metadata": {
"hide-output": false
},
Expand All @@ -25,7 +25,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "22e56472",
"id": "fb98c5ea",
"metadata": {
"hide-output": false
},
Expand All @@ -49,7 +49,7 @@
},
{
"cell_type": "markdown",
"id": "de3f08b4",
"id": "f0f563cd",
"metadata": {},
"source": [
"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",
Expand Down Expand Up @@ -145,7 +145,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "16a386ca",
"id": "d0512ef0",
"metadata": {
"hide-output": false
},
Expand Down Expand Up @@ -175,7 +175,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "c6ca10f6",
"id": "88fa966e",
"metadata": {
"hide-output": false
},
Expand All @@ -187,7 +187,7 @@
},
{
"cell_type": "markdown",
"id": "14c6b2e6",
"id": "629d303c",
"metadata": {},
"source": [
"Now we shall use Bayes’ law to construct a posterior distribution, conditioning on the initial value of $ y_0 $.\n",
Expand All @@ -199,7 +199,7 @@
},
{
"cell_type": "markdown",
"id": "3418a0ce",
"id": "f0e4edc9",
"metadata": {},
"source": [
"## PyMC Implementation\n",
Expand All @@ -211,7 +211,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "c0c0c904",
"id": "19c76cd7",
"metadata": {
"hide-output": false
},
Expand All @@ -234,7 +234,7 @@
},
{
"cell_type": "markdown",
"id": "c1f24f37",
"id": "218a3756",
"metadata": {},
"source": [
"[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:"
Expand All @@ -243,7 +243,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "7b65f243",
"id": "140b06b8",
"metadata": {
"hide-output": false
},
Expand All @@ -256,7 +256,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "53c8fa47",
"id": "91c78354",
"metadata": {
"hide-output": false
},
Expand All @@ -268,7 +268,7 @@
},
{
"cell_type": "markdown",
"id": "9cd49b4c",
"id": "19d8a3e1",
"metadata": {},
"source": [
"Evidently, the posteriors aren’t centered on the true values of $ .5, 1 $ that we used to generate the data.\n",
Expand All @@ -283,7 +283,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "bf309de2",
"id": "637d19f0",
"metadata": {
"hide-output": false
},
Expand All @@ -297,7 +297,7 @@
},
{
"cell_type": "markdown",
"id": "fc4cc19c",
"id": "3587872a",
"metadata": {},
"source": [
"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",
Expand All @@ -314,7 +314,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "d81e7ab8",
"id": "4acf7ff1",
"metadata": {
"hide-output": false
},
Expand All @@ -340,7 +340,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "ab38a3c1",
"id": "cb981987",
"metadata": {
"hide-output": false
},
Expand All @@ -355,7 +355,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "ce26970a",
"id": "b10e79fe",
"metadata": {
"hide-output": false
},
Expand All @@ -368,7 +368,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "0e740239",
"id": "f3b62a32",
"metadata": {
"hide-output": false
},
Expand All @@ -382,7 +382,7 @@
},
{
"cell_type": "markdown",
"id": "0102f055",
"id": "f80859fd",
"metadata": {},
"source": [
"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",
Expand All @@ -399,7 +399,7 @@
},
{
"cell_type": "markdown",
"id": "4262db1b",
"id": "9f9bce4d",
"metadata": {},
"source": [
"## Numpyro Implementation"
Expand All @@ -408,7 +408,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "9af3ee90",
"id": "af573a4d",
"metadata": {
"hide-output": false
},
Expand Down Expand Up @@ -444,7 +444,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "3dcb560a",
"id": "5dc41d5f",
"metadata": {
"hide-output": false
},
Expand All @@ -465,7 +465,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "22173585",
"id": "a232fe39",
"metadata": {
"hide-output": false
},
Expand All @@ -485,7 +485,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "264ea510",
"id": "ca6bbf0f",
"metadata": {
"hide-output": false
},
Expand All @@ -497,7 +497,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "b2c15b9c",
"id": "5b0202d7",
"metadata": {
"hide-output": false
},
Expand All @@ -508,7 +508,7 @@
},
{
"cell_type": "markdown",
"id": "634815b3",
"id": "3be9abd8",
"metadata": {},
"source": [
"Next, we again compute the posterior under the assumption that $ y_0 $ is drawn from the stationary distribution, so that\n",
Expand All @@ -523,7 +523,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "f7a329f4",
"id": "66c03f11",
"metadata": {
"hide-output": false
},
Expand All @@ -548,7 +548,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "0ec3a7b9",
"id": "bdd0ebae",
"metadata": {
"hide-output": false
},
Expand All @@ -568,7 +568,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "7e360541",
"id": "4e76fd42",
"metadata": {
"hide-output": false
},
Expand All @@ -580,7 +580,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "42daebab",
"id": "5be0ea44",
"metadata": {
"hide-output": false
},
Expand All @@ -591,7 +591,7 @@
},
{
"cell_type": "markdown",
"id": "990d16d6",
"id": "2f4abae3",
"metadata": {},
"source": [
"Look what happened to the posterior!\n",
Expand All @@ -606,7 +606,7 @@
}
],
"metadata": {
"date": 1706658080.0212908,
"date": 1706679395.7876425,
"filename": "ar1_bayes.md",
"kernelspec": {
"display_name": "Python",
Expand Down
Loading

0 comments on commit 833d8b3

Please sign in to comment.