Skip to content

Commit 003c9f0

Browse files
Tom's edit of likelihood lecture Sept 23
1 parent 47b536c commit 003c9f0

File tree

1 file changed

+304
-0
lines changed

1 file changed

+304
-0
lines changed

lectures/likelihood_bayes.md

Lines changed: 304 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,310 @@ We thus conclude that the likelihood ratio process is a key ingredient of the f
369369
a Bayesian's posteior probabilty that nature has drawn history $w^t$ as repeated draws from density
370370
$g$.
371371

372+
373+
INSERT NEW BEGINS
374+
375+
### Behavior of posterior probabilities $\{\pi_t\}$ under the subjective probability distribution
376+
377+
378+
379+
#### A perspective on Bayes's law as a theory of learning
380+
381+
We'll continue with our setting in which a McCall worker knows that successive
382+
draws of his wage are drawn from either $F$ or $G$, but does not know which of these two distributions
383+
nature has drawn once-and-for-all before time $0$.
384+
385+
We'll review and reiterate and rearrange some formulas that we have encountered above and in associated lectures.
386+
387+
The worker's initial beliefs induce a joint probability distribution
388+
over a potentially infinite sequence of draws $w_0, w_1, \ldots $.
389+
390+
Bayes' law is simply an application of laws of
391+
probability to compute the conditional distribution of the $t$th draw $w_t$ conditional on $[w_0, \ldots, w_{t-1}]$.
392+
393+
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}$.
394+
395+
We assume that the workers also knows the laws of probability theory.
396+
397+
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.
398+
399+
400+
#### Mechanical details again
401+
402+
At time $0$ **before** drawing a wage offer, the worker attaches probability $\pi_{-1} \in (0,1)$ to the distribution being $F$.
403+
404+
Before drawing a wage at time $0$, the worker thus believes that the density of $w_0$
405+
is
406+
407+
$$
408+
h(w_0;\pi_{-1}) = \pi_{-1} f(w_0) + (1-\pi_{-1}) g(w_0).
409+
$$
410+
411+
Let $a \in \{ f, g\} $ be an index that indicates whether nature chose permanently to draw from distribution $f$ or from distribution $g$.
412+
413+
After drawing $w_0$, the worker uses Bayes' law to deduce that
414+
the posterior probability $\pi_0 = {\rm Prob}{a = f | w_0} $
415+
that the density is $f(w)$ is
416+
417+
$$
418+
\pi_0 = { \pi_{-1} f(w_0) \over \pi_{-1} f(w_0) + (1-\pi_{-1}) g(w_0)} .
419+
$$
420+
421+
422+
More generally, after making the $t$th draw and having observed $w_t, w_{t-1}, \ldots, w_0$, the worker believes that
423+
the probability that $w_{t+1}$ is being drawn from distribution $F$ is
424+
425+
$$
426+
\pi_t = \pi_t(w_t | \pi_{t-1}) \equiv { \pi_{t-1} f(w_t)/g(w_t) \over \pi_{t-1} f(w_t)/g(w_t) + (1-\pi_{t-1})} \tag{44}
427+
$$
428+
429+
430+
or
431+
432+
433+
<a id='equation-eq-recur1'></a>
434+
$$
435+
\pi_t=\frac{\pi_{t-1} l_t(w_t)}{\pi_{t-1} l_t(w_t)+1-\pi_{t-1}} \tag{56.1}
436+
$$
437+
438+
439+
and that the density of $w_{t+1}$ conditional on $w_t, w_{t-1}, \ldots, w_0$ is
440+
441+
$$
442+
h(w_{t+1};\pi_{t}) = \pi_{t} f(w_{t+1}) + (1-\pi_{t}) g(w_{t+1}) .
443+
$$
444+
445+
Notice that
446+
447+
$$
448+
\eqalign{ E(\pi_t | \pi_{t-1}) & = \int \Bigl[ { \pi_{t-1} f(w) \over \pi_{t-1} f(w) + (1-\pi_{t-1})g(w) } \Bigr]
449+
\Bigl[ \pi_{t-1} f(w) + (1-\pi_{t-1})g(w) \Bigr] d w \cr
450+
& = \pi_{t-1} \int f(w) dw \cr
451+
& = \pi_{t-1}, \cr}
452+
$$
453+
454+
so that the process $\pi_t$ is a **martingale**.
455+
456+
Indeed, it is a **bounded martingale** because each $\pi_t$, being a probability,
457+
is between $0$ and $1$.
458+
459+
460+
In the first line in the above string of equalities, the term in the first set of brackets
461+
is just $\pi_t$ as a function of $w_{t}$, while the term in the second set of brackets is the density of $w_{t}$ conditional
462+
on $w_{t-1}, \ldots , w_0$ or equivalently conditional on the *sufficient statistic* $\pi_{t-1}$ for $w_{t-1}, \ldots , w_0$.
463+
464+
Notice that here we are computing $E(\pi_t | \pi_{t-1})$ under the **subjective** density described in the second
465+
term in brackets.
466+
467+
Because $\{\pi_t\}$ is a bounded martingale sequence, it follows from the **martingale convergence theorem** that $\pi_t$ converges almost surely to a random variable in $[0,1]$.
468+
469+
Practically, this means that probability one is attached to sample paths
470+
$\{\pi_t\}_{t=0}^\infty$ that converge.
471+
472+
According to the theorem, it different sample paths can converge to different limiting values.
473+
474+
Thus, let $\{\pi_t(\omega)\}_{t=0}^\infty$ denote a particular sample path indexed by a particular $\omega
475+
\in \Omega$.
476+
477+
We can think of nature as drawing an $\omega \in \Omega$ from a probability distribution
478+
${\textrm{Prob}} \Omega$ and then generating a single realization (or _simulation_) $\{\pi_t(\omega)\}_{t=0}^\infty$ of the process.
479+
480+
The limit points of $\{\pi_t(\omega)\}_{t=0}^\infty$ as $t \rightarrow +\infty$ are realizations of a random variable that is swept out as we sample $\omega$ from $\Omega$ and construct repeated draws of $\{\pi_t(\omega)\}_{t=0}^\infty$.
481+
482+
483+
By staring at law of motion (44) or (56), we can figure out some things about the probability distribution of the limit points
484+
485+
$$
486+
\pi_\infty(\omega) = \lim_{\rightarrow + \infty} \pi_t(\omega).
487+
$$
488+
489+
490+
491+
492+
Evidently, since the likelihood ratio $\ell(w_t) $ differs from $1$ when $f \neq g$,
493+
as we have assumed, the only possible fixed points of (44) are
494+
495+
$$
496+
\pi_\infty(\omega) =1
497+
$$
498+
499+
500+
and
501+
502+
$$
503+
\pi_\infty(\omega) =0
504+
$$
505+
506+
507+
Thus, for some realizations, $\lim_{\rightarrow + \infty} \pi_t(\omega) =1$
508+
while for other realizations, $\lim_{\rightarrow + \infty} \pi_t(\omega) =0$.
509+
510+
Now let's remember that $\{\pi_t\}_{t=0}^\infty$ is a martingale and apply the law of iterated expectations.
511+
512+
513+
The law of iterated expectations implies
514+
515+
$$
516+
E_t \pi_{t+j} = \pi_t
517+
$$
518+
519+
and in particular
520+
521+
$$
522+
E_{-1} \pi_{t+j} = \pi_{-1}.
523+
$$
524+
525+
Applying the above formula to $\pi_\infty$, we obtain
526+
527+
$$
528+
E_{-1} \pi_\infty(\omega) = \pi_{-1} \tag{20}
529+
$$
530+
531+
where the mathematical expectation $E_{-1}$ here is taken with respect to the probability
532+
measure ${\textrm{Prob}(\Omega)}$.
533+
534+
Since the only two values that $\pi_\infty(\omega)$ can take are $1$ and $0$, we know that for some $\lambda \in [0,1]$
535+
536+
$$
537+
{\textrm{Prob}}\Bigl(\pi_\infty(\omega) = 1\Bigr) = \lambda, \quad {\textrm{Prob}}\Bigl(\pi_\infty(\omega) = 0\Bigr) = 1- \lambda
538+
$$
539+
540+
and consequently that
541+
542+
$$
543+
E_{-1} \pi_\infty(\omega) = \lambda \cdot 1 + (1-\lambda) \cdot 0 = \lambda
544+
$$
545+
546+
547+
Combining this equation with equation (20), we deduce that
548+
the probability that ${\textrm{Prob}(\Omega)}$ attaches to
549+
$\pi_\infty(\omega)$ being $1$ must be $\pi_{-1}$.
550+
551+
552+
Thus, under the worker's subjective distribution, $\pi_{-1}$ of the sample paths
553+
of $\{\pi_t\}$ will converge pointwise to $1$ and $1 - \pi_{-1}$ of the sample paths will
554+
converge pointwise to $0$.
555+
556+
557+
558+
#### Some simulations
559+
560+
Let's watch the martingale convergence theorem at work in some simulations of our learning model under the worker's subjective distribution.
561+
562+
Let us simulate $\left\{ \pi_{t}\right\} _{t=0}^{T}$, $\left\{ w_{t}\right\} _{t=0}^{T}$ paths where for each $t\geq0$, $w_t$ is drawn from the subjective distribution
563+
564+
$$
565+
\pi_{t-1}f\left(w_{t}\right)+\left(1-\pi_{t-1}\right)g\left(w_{t}\right)
566+
$$
567+
568+
We'll plot a large sample of paths.
569+
570+
```{code-cell} ipython3
571+
@njit
572+
def martingale_simulate(π0, N=5000, T=200):
573+
574+
π_path = np.empty((N,T+1))
575+
w_path = np.empty((N,T))
576+
π_path[:,0] = π0
577+
578+
for n in range(N):
579+
π = π0
580+
for t in range(T):
581+
# draw w
582+
if np.random.rand() <= π:
583+
w = np.random.beta(F_a, F_b)
584+
else:
585+
w = np.random.beta(G_a, G_b)
586+
π = π*f(w)/g(w)/(π*f(w)/g(w) + 1 - π)
587+
π_path[n,t+1] = π
588+
w_path[n,t] = w
589+
590+
return π_path, w_path
591+
592+
def fraction_0_1(π0, N, T, decimals):
593+
594+
π_path, w_path = martingale_simulate(π0, N=N, T=T)
595+
values, counts = np.unique(np.round(π_path[:,-1], decimals=decimals), return_counts=True)
596+
return values, counts
597+
598+
def create_table(π0s, N=10000, T=500, decimals=2):
599+
600+
outcomes = []
601+
for π0 in π0s:
602+
values, counts = fraction_0_1(π0, N=N, T=T, decimals=decimals)
603+
freq = counts/N
604+
outcomes.append(dict(zip(values, freq)))
605+
table = pd.DataFrame(outcomes).sort_index(axis=1).fillna(0)
606+
table.index = π0s
607+
return table
608+
609+
610+
611+
# simulate
612+
T = 200
613+
π0 = .5
614+
615+
π_path, w_path = martingale_simulate(π0=π0, T=T, N=10000)
616+
```
617+
618+
```{code-cell} ipython3
619+
fig, ax = plt.subplots()
620+
for i in range(100):
621+
ax.plot(range(T+1), π_path[i, :])
622+
623+
ax.set_xlabel('$t$')
624+
ax.set_ylabel('$\pi_t$')
625+
plt.show()
626+
```
627+
628+
```{code-cell} ipython3
629+
fig, ax = plt.subplots()
630+
for t in [1, 10, T-1]:
631+
ax.hist(π_path[:,t], bins=20, alpha=0.4, label=f'T={t}')
632+
633+
ax.set_ylabel('count')
634+
ax.set_xlabel('$\pi_T$')
635+
ax.legend(loc='upper right')
636+
plt.show()
637+
```
638+
639+
```{code-cell} ipython3
640+
fig, ax = plt.subplots()
641+
for i, j in enumerate([10, 100]):
642+
ax.plot(range(T+1), π_path[j,:], color=colors[i], label=f'$\pi$_path, {j}-th simulation')
643+
ax.plot(range(1,T+1), w_path[j,:], color=colors[i], label=f'$w$_path, {j}-th simulation', alpha=0.3)
644+
645+
ax.legend(loc='upper right')
646+
ax.set_xlabel('$t$')
647+
ax.set_ylabel('$\pi_t$')
648+
ax2 = ax.twinx()
649+
ax2.set_ylabel("$w_t$")
650+
plt.show()
651+
```
652+
653+
Now let's use our Python code to generate a table that checks out our earlier claims about the
654+
probability distribution of the pointwise limits $\pi_{\infty}(\omega)$.
655+
656+
We'll use our simulations to generate a histogram of this distribution.
657+
658+
```{code-cell} ipython3
659+
# create table
660+
table = create_table(list(np.linspace(0,1,11)), N=10000, T=500)
661+
table
662+
```
663+
664+
665+
666+
667+
668+
669+
670+
INSERT NEW ENDS
671+
672+
673+
674+
675+
372676
## Sequels
373677

374678
This lecture has been devoted to building some useful infrastructure.

0 commit comments

Comments
 (0)