Skip to content

Commit 86f176b

Browse files
Tom's Dec 3 edit of likelihood_bayes.md lecture
1 parent b8017a7 commit 86f176b

File tree

1 file changed

+124
-15
lines changed

1 file changed

+124
-15
lines changed

lectures/likelihood_bayes.md

Lines changed: 124 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ Bayes' law is simply an application of laws of
413413

414414
After our worker puts a subjective probability $\pi_{-1}$ on nature having selected distribution $F$, we have in effect assumes from the start that the decision maker **knows** the joint distribution for the process $\{w_t\}_{t=0}$.
415415

416-
We assume that the workers also knows the laws of probability theory.
416+
We assume that the worker also knows the laws of probability theory.
417417

418418
A respectable view is that Bayes' law is less a theory of learning than a statement about the consequences of information inflows for a decision maker who thinks he knows the truth (i.e., a joint probability distribution) from the beginning.
419419

@@ -651,30 +651,59 @@ ax.set_ylabel('$\pi_t$')
651651
plt.show()
652652
```
653653
654-
Now let's plot two paths of pairs of $\{\pi_t, w_t\}$ sequences, one in which $\pi_t \rightarrow 1$,
655-
another in which $\pi_t \rightarrow 0$.
654+
655+
656+
The above graph indicates that
657+
658+
* each of paths converges
659+
660+
* some of the paths converge to $1$
661+
662+
* some of the paths converge to $0$
663+
664+
* none of the paths converge to a limit point not equal to $0$ or $1$
665+
666+
Convergence actually occurs pretty fast, as the following graph of the cross-ensemble distribution of $\pi_t$ for various small $t$'s indicates.
667+
668+
656669
657670
```{code-cell} ipython3
658671
fig, ax = plt.subplots()
659-
for i, j in enumerate([10, 100]):
660-
ax.plot(range(T+1), π_path[j,:], color=colors[i], label=f'$\pi$_path, {j}-th simulation')
661-
ax.plot(range(1,T+1), w_path[j,:], color=colors[i], label=f'$w$_path, {j}-th simulation', alpha=0.3)
672+
for t in [1, 10, T-1]:
673+
ax.hist(π_path[:,t], bins=20, alpha=0.4, label=f'T={t}')
662674
663-
ax.legend(loc='upper right')
664-
ax.set_xlabel('$t$')
665-
ax.set_ylabel('$\pi_t$')
666-
ax2 = ax.twinx()
667-
ax2.set_ylabel("$w_t$")
675+
ax.set_ylabel('count')
676+
ax.set_xlabel('$\pi_T$')
677+
ax.legend(loc='lower right')
668678
plt.show()
669679
```
670680
681+
Evidently, by $t = 199$, $\pi_t$ has converged to either $0$ or $1$.
671682
672-
Let's plot histograms of $\pi_t$ for various values of $t$.
683+
The fraction of paths that have converged to $1$ is $.5$
684+
685+
The fractions of paths that have converged to $0$ is also $.5.
686+
687+
Does the fraction $.5$ ring a bell?
688+
689+
Yes, it does: it equals the value of $\pi_0 = .5 $ that we used to generate each sequence
690+
in the ensemble.
691+
692+
So let's change $\pi_0$ to $.3$ and watch what happens to the distribution of the ensemble of
693+
$\pi_t$'s for various $t$'s.
694+
695+
```{code-cell} ipython3
696+
# simulate
697+
T = 200
698+
π0 = .3
699+
700+
π_path3, w_path3 = martingale_simulate(π0=π0, T=T, N=10000)
701+
```
673702
674703
```{code-cell} ipython3
675704
fig, ax = plt.subplots()
676705
for t in [1, 10, T-1]:
677-
ax.hist(π_path[:,t], bins=20, alpha=0.4, label=f'T={t}')
706+
ax.hist(π_path3[:,t], bins=20, alpha=0.4, label=f'T={t}')
678707
679708
ax.set_ylabel('count')
680709
ax.set_xlabel('$\pi_T$')
@@ -683,8 +712,34 @@ plt.show()
683712
```
684713
685714
686-
The above graphs display how the distribution of $\pi_t$ across realizations are moving toward
687-
limit points that we described above and that put all probability either on $0$ or on $1$.
715+
716+
**Drilling down a little bit**
717+
718+
For the preceding ensemble that assumed $\pi_0 = .5$, the following graph shows two paths of
719+
$w_t$'s and the $\pi_t$ sequences that gave rise to them.
720+
721+
Notice that one of the paths involves systematically higher $w_t$'s, outcomes that push $\pi_t$ upward.
722+
723+
The luck of the draw early in a simulation push the subjective distribution to draw from
724+
$F$ more frequently along a sample path, and this pushes $\pi_t$ toward $0$.
725+
726+
727+
728+
```{code-cell} ipython3
729+
fig, ax = plt.subplots()
730+
for i, j in enumerate([10, 100]):
731+
ax.plot(range(T+1), π_path[j,:], color=colors[i], label=f'$\pi$_path, {j}-th simulation')
732+
ax.plot(range(1,T+1), w_path[j,:], color=colors[i], label=f'$w$_path, {j}-th simulation', alpha=0.3)
733+
734+
ax.legend(loc='upper right')
735+
ax.set_xlabel('$t$')
736+
ax.set_ylabel('$\pi_t$')
737+
ax2 = ax.twinx()
738+
ax2.set_ylabel("$w_t$")
739+
plt.show()
740+
```
741+
742+
## Initial Prior is Verified by Paths Drawn from Subjective Conditional Densities
688743
689744
690745
@@ -710,6 +765,56 @@ The fraction of simulations for which $\pi_{t}$ had converged to $1$ is indeed
710765
711766
712767
768+
### Conditional Variance of Subjective Distribution
769+
770+
We can use a Monte Carlo simulation to approximate the conditional variance of $\pi_{t+1}$ under the
771+
subjective distribution:
772+
773+
$$
774+
\sigma^2(\pi_t | \pi_{t-1}) = \int \Bigl[ { \pi_{t-1} f(w) \over \pi_{t-1} f(w) + (1-\pi_{t-1})g(w) } - \pi_{t-1} \Bigr]^2
775+
\Bigl[ \pi_{t-1} f(w) + (1-\pi_{t-1})g(w) \Bigr] d w
776+
$$
777+
778+
We approximate this for a grid of points $\pi_{t-1} \in [0,1]$.
779+
780+
Then we'll plot it.
781+
782+
```{code-cell} ipython3
783+
@njit
784+
def compute_cond_var(pi, mc_size=int(1e6)):
785+
# create monte carlo draws
786+
mc_draws = np.zeros(mc_size)
787+
788+
for i in prange(mc_size):
789+
if np.random.rand() <= pi:
790+
mc_draws[i] = np.random.beta(F_a, F_b)
791+
else:
792+
mc_draws[i] = np.random.beta(G_a, G_b)
793+
794+
dev = pi*f(mc_draws)/(pi*f(mc_draws) + (1-pi)*g(mc_draws)) - pi
795+
return np.mean(dev**2)
796+
797+
pi_array = np.linspace(0, 1, 40)
798+
cond_var_array = []
799+
800+
for pi in pi_array:
801+
cond_var_array.append(compute_cond_var(pi))
802+
803+
fig, ax = plt.subplots()
804+
ax.plot(pi_array, cond_var_array)
805+
ax.set_xlabel('$\pi_{t-1}$')
806+
ax.set_ylabel('$\sigma^{2}(\pi_{t}\\vert \pi_{t-1})$')
807+
plt.show()
808+
```
809+
810+
Notice how the conditional variance approaches $0$ for $\pi_{t-1}$ near either $0$ or $1$, where
811+
the agent is almost sure that $w_t$ is drawn from $F$ or from $G$.
812+
813+
```{code-cell} ipython3
814+
815+
```
816+
817+
713818
714819
715820
@@ -719,3 +824,7 @@ The fraction of simulations for which $\pi_{t}$ had converged to $1$ is indeed
719824
This lecture has been devoted to building some useful infrastructure that will help us understand inferences that are the foundations of
720825
results described in {doc}`this lecture <odu>` and {doc}`this lecture <wald_friedman>` and {doc}`this lecture <navy_captain>`.
721826
827+
828+
829+
830+

0 commit comments

Comments
 (0)