Mathematics

Mathematics is the study of crisply specified formal objects — for example, [number numbers] — and the ways of knowing their [mathematical_properties properties] — such as [-proofs].  We can see "[-258]" as the study of "which conclusions follow with certainty from which premises".  Using this definition of logic, we can also see mathematics as the study of logical objects in logical universes — entities whose properties follow from specifications about them, rather than from observation of the real world.  The number 3 is a logical object because its behavior follows from axioms about addition and multiplication; Mount Everest is a physical object because we learn about it by physically measuring Mount Everest.


Bayesian update

[summary:  *Bayesian updating* or *Bayesian belief revision* is a way of changing [1rf probabilistic] beliefs, in response to evidence, in a way that obeys [-1bv] and in particular [1lz].

When we observe a piece of evidence that is more likely to be seen if X is true than if X is false, we should assign more credence to X.  For example, if I take a random object from your kitchen, and then I tell you this object is sharp, you should assign more credence than you did previously that it's a knife (even though forks are also sharp, so you won't be certain).

For more on this subject see [1zq the Arbital guide to Bayes's rule].]

A Bayesian *update* or *belief revision* is a change in [1rf probabilistic] beliefs after gaining new knowledge.  For example, after observing a patient's test result, we might revise our probability that a patient has a certain disease.  If this belief revision obeys [1lz Bayes's Rule], then it is called [1r8 Bayesian].

Bayesian belief updates have a number of other interesting properties, and exemplify many key principles of clear reasoning or [9l rationality].  Mapping Bayes's Rule onto real-life problems of encountering new evidence allows us to reproduce many intuitive features that have been suggested for "how to revise beliefs in the face of new evidence".

- [21v (Extra)ordinary claims require (extra)ordinary evidence.]
- The scientific virtues of [220 falsifiability, advance prediction, boldness, precision, and falsificationism] can be seen in a Bayesian light.


Bayes' rule

[summary:  When an observation is more likely given one state of the world than another, we should increase our credence that we're in the world that was more likely to have produced that observation.

Suppose that Professor Plum and Miss Scarlet are two suspects in a murder, and that we start out thinking that Professor Plum is twice as likely to have committed the murder as Miss Scarlet.  We then discover that the victim was poisoned.  We think that, on occasions where they do commit murders, Professor Plum is around one-fourth as likely to use poison as Miss Scarlet.  Then after observing the victim was poisoned, we should think Professor Plum is around half as likely to have committed the murder as Miss Scarlet: $2 \times \dfrac{1}{4} = \dfrac{1}{2}.$

The quantitative rule at work here, in its various forms, is known as Bayes' rule.]

[summary(Technical): Bayes' rule (aka Bayes' theorem) is the quantitative [1bv law] governing how to [1ly revise probabilistic beliefs in response to observing new evidence].  Suppose we previously thought that the probability of $h_1$, denoted $\mathbb {P}(h_1)$, was twice as great as $\mathbb {P}(h_2)$.  Now we see a new piece of evidence, $e_0$, such that the probability of our seeing $e_0$ if $h_1$ is true (denoted by $\mathbb {P}(e_0\mid h_1)$) is one-fourth as great as $\mathbb {P}(e_0\mid h_2)$ (the probability of seeing $e_0$ if $h_2$ is true).  After observing $e_0$, we should think that $h_1$ is now half as likely as $h_2$:

$$\frac{\mathbb {P}(h_1\mid e_0)}{\mathbb {P}(h_2\mid e_0)} = \frac{\mathbb {P}(h_1)}{\mathbb {P}(h_2)} \cdot \frac{\mathbb {P}(e_0\mid h_1)}{\mathbb {P}(e_0\mid h_2)}$$

[1zj More generally], Bayes' rule states:  $\mathbb P(\mathbf{H}\mid e) \propto \operatorname{\mathbb {P}}(e\mid \mathbf{H}) \cdot \operatorname{\mathbb {P}}(\mathbf{H}).$]

Bayes' rule (aka Bayes' theorem) is the quantitative law of [1bv probability theory] governing how to [1ly revise] probabilistic beliefs in response to observing new evidence.

You may want to start at the [1zq Guide] or the [693 Fast Intro].

# The laws of reasoning

Imagine that, as part of a clinical study, you're being tested for a rare form of cancer, which affects 1 in 10,000 people. You have no reason to believe that you are more or less likely than average to have this form of cancer. You're administered a test which is 99% accurate, both in terms of [-specificity] and [-sensitivity]: It _correctly_ detects the cancer (in patients who have it) 99% of the time, and it _incorrectly_ detects cancer (in patients who don't have it) only 1% of the  time. The test results come back positive. What's the chance that you have cancer?

Bayes' rule says that the answer is precisely a 1 in 102 chance, which is a probability a little below 1%. The remarkable thing about this is that there is only one answer: the odds of you having that type of cancer, given the above information, is _exactly_ 1 in 102; no more, no less.

%comment: (999,900 * 0.99 + 100 * 0.99) / (100 * 0.99) = (10098 / 99) = 102.  Please leave this comment here so the above paragraph is not edited to be wrong.%

This is one of the key insights of Bayes' rule: Given what you knew, and what you saw, the maximally accurate state of belief for you to be in is completely pinned down. While that belief state is quite difficult to find in practice, we know how to find it in principle. If you want your beliefs to become more accurate as you observe the world, Bayes' rule gives some hints about what you need to do.

# Learn Bayes' rule

- [1x5 __Bayes' rule: Odds form.__] Bayes' rule is simple, if you think in terms of relative odds.
- [1zm __Bayes' rule: Proportional form.__] The fastest way to say something both convincing and true about belief-updating.
- [1zh __Bayes' rule: Log-odds form.__] A simple transformation of Bayes' rule reveals tools for measuring degree of belief, and strength of evidence.
- [554 __Bayes' rule: Probabilistic form.__] The original formulation of Bayes' rule.
- [1zj __Bayes' rule: Functional form.__] Bayes' rule for continuous variables.
- [1zg __Bayes' rule: Vector form.__] For when you want to apply Bayes' rule to lots of evidence and lots of variables, all in one go.

# Implications of Bayes' rule

- [220 __A Bayesian view of scientific virtues.__] Why is it that science relies on bold, precise, and falsifiable predictions? Because of Bayes' rule, of course.
- [update_by_inches __Update by inches.__] It's virtuous to change your mind in response to overwhelming evidence. It's even more virtuous to shift your beliefs a little bit at a time, in response to *all* evidence (no matter how small).
- [1y6 __Belief revision as probability elimination.__] Update your beliefs by throwing away large chunks of probability mass.
- [552 __Shift towards the hypothesis of least surprise.__] When you see new evidence, ask: which hypothesis is *least surprised?*
- [21v __Extraordinary claims require extraordinary evidence.__] The people who adamantly claim they were abducted by aliens do provide *some* evidence for aliens. They just don't provide quantitatively *enough* evidence.
- [ __Ideal reasoning via Bayes' rule.__] Bayes' rule is to reasoning as the [https://en.wikipedia.org/wiki/Carnot_cycle Carnot cycle] is to engines: Nobody can be a perfect Bayesian, but Bayesian reasoning is still the theoretical ideal.

# Related content

- [4vr __Subjective probability.__] Probability is in the mind, not the world. If you don't know whether a tossed coin came up heads or tails, that's a fact about you, not a fact about the coin.
- [1bv __Probability theory.__] The quantification and study of objects that represent uncertainty about the world, and methods for making those representations more accurate.
- [3qq __Information theory.__] The quantification and study of information, communication, and what it means for one object to tell us about another.

# Other articles and introductions

- [http://en.wikipedia.org/wiki/Bayes%27_rule Wikipedia]
- [http://betterexplained.com/articles/an-intuitive-and-short-explanation-of-bayes-theorem/ Better Explained]


Math 2

Do you work with math on a fairly routine basis?  Do you have little trouble grasping new mathematical ideas that use language you already know?  Having this requisite would be typical of a computer programmer, a physical engineer, or someone else who routinely works with mathematically-structured ideas.  At this level, you start to see LaTeX formulas in passing, but they'll have explanations attached.


Bayesian reasoning

[summary:  Bayesian reasoning is a way of interpreting the world, and our beliefs about the world, in the light of [1bv probability theory], in particular Bayes's Theorem or [1lz Bayes's Rule].  Applications include scientific statistics, machine learning, and everyday life.]

According to its advocates, Bayesian reasoning is a way of seeing the world, and our beliefs about the world, in the light of [1bv probability theory], in particular Bayes's Theorem or [1lz Bayes's Rule].  This probability-theoretic way of seeing the world can apply to scientific issues, to tasks in machine learning, and to everyday life.

To [1zq start learning], visit [1zq Arbital's Guide to Bayes's Rule].

After that, consider visiting the [1ly Bayesian update] page.


Odds

[summary:  Odds are a tool for expressing *relative* chances.  If the odds of a tree in a forest being sick versus healthy are 2 : 3, this says that there are 2 sick trees for every 3 healthy trees.  (The *probability* of a tree being sick, in this case, is 2/5 or 40%.)

![](https://i.imgur.com/GVZnz2c.png?0)]

[summary(Technical): Odds express relative chances.  If the odds for X versus Y are 2 : 3, this expresses that we think that X is 2/3 = 0.666... times as likely as Y.  Clearly, odds of 6 : 9 express the same idea; odds are invariant up to multiplication by a positive factor.  When an odds ratio [1rd exhausts all the possibilities], then we can convert its components to probabilities by [1rk normalizing] them so that they sum to 1.  In the example above, the probabilities would be $2:3 = \frac{2}{3+2}:\frac{3}{3+2} = 0.4:0.6.$

![](https://i.imgur.com/GVZnz2c.png?0)]

Odds are a tool for expressing relative [1rf chances].  If the odds of a tree in a forest being sick versus healthy are 2 : 3, this says that there are 2 sick trees for every 3 healthy trees.  (The probability of a tree being sick, in this case, is 2/5 or 40%.)

![](https://i.imgur.com/GVZnz2c.png?0)

Odds are expressed in the form "X to Y", e.g. "7 to 9 for X versus Y", more compactly written as $7:9$.

The representation of chances as odds is often used in gambling and [-statistics].


Mutually exclusive and exhaustive

A set of propositions is "mutually exclusive and exhaustive" when exactly one of the propositions must be true.  For example, of the two propositions "The sky is blue" and "It is not the case that the sky is blue", exactly one of those must be the case.  Therefore, the [1rf probabilities] of those propositions must sum to exactly 1.

If a set $X$ of propositions is "mutually exclusive", this states that for every two distinct propositions, the probability that both of them will be true simultaneously is zero:

$\forall i: \forall j: i \neq j \implies \mathbb{P}(X_i \wedge X_j) = 0.$

This implies that for every two distinct propositions, the probability of their union equals the sum of their probabilities:

$\mathbb{P}(X_i \vee X_j) = \mathbb{P}(X_i) + \mathbb{P}(X_j) - \mathbb{P}(X_j \wedge X_j) = \mathbb{P}(X_i) + \mathbb{P}(X_j).$

The "exhaustivity" condition states that the union of all propositions in $X,$ has probability $1$ (the probability of at least one $X_i$ happening is $1$):

$\mathbb{P}(X_1 \vee X_2 \vee \dots \vee X_N) = 1.$

Therefore mutual exclusivity and exhaustivity imply that the probabilities of the propositions sum to 1:

$\displaystyle \sum_i \mathbb{P}(X_i) = 1.$


Probability

*Probabilities* are the central subject of the discipline of [1bv].  $\mathbb{P}(X)$ denotes our level of belief, or someone's level of belief, that the proposition $X$ is true.  In the classical and canonical representation of probability, 0 expresses absolute incredulity, and 1 expresses absolute credulity. %%knows-requisite([1mh]):  Furthermore, [1rd mutually exclusive] events have additive classical probabilities: $\mathbb{P}(X \wedge Y) = 0 \implies \mathbb{P}(X \vee Y) = \mathbb{P}(X) + \mathbb{P}(Y).$%%

For the standard probability axioms, see https://en.wikipedia.org/wiki/Probability_axioms. [todo: write up page on arbital about probability axioms.]

# Notation

$\mathbb{P}(X)$ is the probability that X is true.

$\mathbb{P}(\neg X) = 1  - \mathbb{P}(X)$ is the probability that X is false.

$\mathbb{P}(X \wedge Y)$ is the probability that both X and Y are true.

$\mathbb{P}(X \vee Y)$ is the probability that X or Y or both are true.

$\mathbb{P}(X|Y) := \frac{\mathbb{P}(X \wedge Y}{\mathbb{P}(Y)}$ is the **[1rj conditional probability] of X given Y.**  That is, $\mathbb{P}(X|Y)$ is **the degree to which we would believe X, assuming Y to be true.**  $\mathbb{P}(yellow|banana)$ expresses "The probability that a banana is yellow." $\mathbb{P}(banana|yellow)$ expresses "The probability that a yellow thing is a banana".

# Centrality of the classical representation

While there are other ways of expressing quantitative degrees of belief, such as [1rb odds ratios], there are several especially useful properties or roles of classical probabilities that give them a central  / convergent / canonical status among possible ways of representing credence.

[1rb Odds ratios] are isomorphic to probabilities - we can readily go back and forth between a probability of 20%, and odds of 1:4.  But unlike odds ratios, probabilities have the further appealing property of being able to add the probabilities of two [1rd mutually exclusive] possibilities to arrive at the probability that one of them occurs.  The 1/6 probability of a six-sided die turning up 1, plus the 1/6 probability of a die turning up 2, equals the 1/3 probability that the die turns up 1 or 2.  The odds ratios 1:5, 1:5, and 1:2 don't have this direct relation (though we could convert to probabilities, add, and then convert back to odds ratios).

Thus, classical probabilities are uniquely the quantities that must appear in the [18v expected utilities] to weigh how much we proportionally care about the uncertain consequences of our decisions.  When an outcome has classical probability 1/3, we multiply the degree to which we care by a factor of 1/3, not by, e.g., the odds ratio 1:2.

If the amount you'd pay for a lottery ticket that paid out on 1 or 2 was more or less than twice the price you paid for a lottery ticket that only paid out on 1, or a lottery ticket that paid out on 2, then I could buy from you and sell to you a combination of lottery tickets such that you would end up with a certain loss.  This is an example of a [dutch_book Dutch book argument], which is one kind of coherence theorem that underpins classical probability and its role in choice.  (If we were dealing with actual betting and gambling, you might reply that you'd just refuse to bet on disadvantageous combinations; but in the much larger gamble that is life, "doing nothing" is just one more choice with an uncertain, probabilistic payoff.)

The combination of several such coherence theorems, most notably including the [Dutch Book arguments](http://plato.stanford.edu/entries/dutch-book/), [Cox's Theorem](https://en.wikipedia.org/wiki/Cox%27s_theorem) and its variations for probability theory, and the [Von Neumann-Morgenstern theorem](https://en.wikipedia.org/wiki/Von_Neumann%E2%80%93Morgenstern_utility_theorem) (VNM) and its variations for expected utility, together give the classical probabilities between 0 and 1 a *central* status in the theory of [9l epistemic and instrumental rationality].  Other ways of representing scalar probabilities, or alternatives to scalar probability, would need to be converted or munged back into classical probabilities in order to animate [agents agents] making coherent choices.

This also suggests that bounded agents which *approximate* coherence, or at least manage to avoid blatantly self-destructive violations of coherence, might have internal mental states which can be *approximately* viewed as corresponding to classical probabilities.  Perhaps not in terms of such agents necessarily containing floating-point numbers that directly represent those probabilities internally, but at least in terms of our being able to look over the agent's behavior and deduce that they were "behaving as if" they had assigned some coherent classical probability.


Joint probability

To write "the chance that both X and Y are true" using standard [1rf] notation, we write $\mathbb{P}(X \wedge Y)$ or $\mathbb{P}(X, Y)$.


Conditional probability

[summary(Brief):  $\mathbb{P}(X\mid Y)$ means "The [1rf probability] that X is true, assuming Y is true."

$\mathbb{P}(yellow\mid banana)$ is "the chance that something is yellow, given that we know it is a banana" or "the chance that a banana is yellow".

Conversely, $\mathbb{P}(banana\mid yellow)$ expresses "how much we should think a random object is a banana, after being told that it was yellow."]

[summary:  $\mathbb{P}(X\mid Y)$ means "The [1rf probability] that X is true, assuming Y is true."

- $\mathbb{P}(yellow\mid banana)$ is "the chance that something is yellow, given that we know it is a banana" or equivalently "the chance that a banana is yellow".
- $\mathbb{P}(banana\mid yellow)$ expresses "how much we should think a random object is a banana, after being told that it was yellow" or "the chance that a yellow thing is a banana".

To calculate a conditional probability $\mathbb{P}(X\mid Y)$, we consider only the cases where Y is true, and ask about the cases where X is also true.

Suppose a barrel contains 15 round green marbles, 5 round blue marbles, 70 square green marbles, and 10 square blue marbles.  "The probability that a marble is blue, after we've been told that it's round" or "The probability a round marble is blue" is calculated by restricting our attention to only the 20 round marbles, and asking about the 5 marbles that are both blue and round.

Letting $\mathbb{P}(blue \wedge round)$ denote "the probability a marble is both blue and round":

$\mathbb{P}(blue\mid round) := \frac{\mathbb{P}(blue \wedge round)}{\mathbb{P}(round)} = \frac{\text{5% blue and round marbles}}{\text{20% round marbles}} = \frac{5}{20} = 0.25.$

In general, $\mathbb{P}(X\mid Y) := \frac{\mathbb{P}(X \wedge Y)}{\mathbb{P}(Y)}.$]

[summary(Technical):  $\mathbb{P}(X\mid Y) := \frac{\mathbb{P}(X \wedge Y)}{\mathbb{P}(Y)}$ is the answer to the question, "Assuming $Y$ to be true, what is the probability of $X$?" or "Constraining our attention to only possibilities where $Y$ is true, what is the probability of $X \wedge Y$ inside those cases?"  (Where $X \wedge Y$ denotes "X and Y" or "Both X and Y are true".)

Thus, $\mathbb P(observation\mid hypothesis)$ would denote the [56v likelihood] of seeing some observation, *if* a hypothesis is true.   $\mathbb P(hypothesis\mid observation)$ would denote the [1ly revised] probability we ought to assign to a hypothesis, after learning that the observation was true.]

The conditional probability $\mathbb{P}(X\mid Y)$ means "The [1rf probability] of $X$ given $Y$."  That is, $\mathbb P(left\mid right)$ means "The probability that $left$ is true, assuming that $right$ is true."

$\mathbb P(yellow\mid banana)$ is the probability that a banana is yellow - if we know something to be a banana, what is the probability that it is yellow?

$\mathbb P(banana\mid yellow)$ is the probability that a yellow thing is a banana - if the right side is known to be $yellow$, then we ask the question on the left, what is the probability that this is a $banana$?

# Definition

To obtain the probability $\mathbb P(left \mid right),$ we constrain our attention to only cases where $right$ is true, and ask about cases within $right$ where $left$ is also true.

Let $X \wedge Y$ denote "$X$ and $Y$" or "$X$ and $Y$ are both true".  Then:

$$\mathbb P(left \mid right) = \dfrac{\mathbb P(left \wedge right)}{\mathbb P(right)}.$$

We can see this as a kind of "zooming in" on only the cases where $right$ is true, and asking, *within* this universe, for the cases where $right$ *and* $left$ are true.

# Example 1

Suppose you have a bag containing objects that are either red or blue, and either square or round, where the number of each is given by the following table:

$$\begin{array}{l\mid r\mid r}
& Red & Blue \\
\hline
Square & 1 & 2 \\
\hline
Round & 3 & 4
\end{array}$$

If you reach in and feel a round object, the conditional probability that it is red is given in by zooming in on only the round objects, and asking about the frequency of objects that are round *and* red inside this zoomed-in view:

$$\mathbb P(red\mid round) = \dfrac{\mathbb P(red \wedge round)}{\mathbb P(round)} = \dfrac{3}{3 + 4} = \dfrac{3}{7}$$

If you look at the object nearest the top, and can see that it's blue, but not see the shape, then the conditional probability that it's a square is:

$$\mathbb P(square\mid blue) = \dfrac{\mathbb P(square \wedge blue)}{\mathbb P(blue)} = \dfrac{2}{2 + 4} = \dfrac{1}{3}$$

![conditional probabilities bag](https://i.imgur.com/zscEdLj.png?0)

# Example 2

Suppose you're Sherlock Holmes investigating a case in which a red hair was left at the scene of the crime.

The Scotland Yard detective says, "Aha!  Then it's Miss Scarlet.  She has red hair, so if she was the murderer she almost certainly would have left a red hair there.  $\mathbb P(red hair\mid Scarlet) = 99\%,$ let's say, which is a near-certain conviction, so we're done."

"But no," replies Sherlock Holmes.  "You see, but you do not correctly track the meaning of the conditional probabilities, detective.  The knowledge we require for a conviction is not $\mathbb P(redhair\mid Scarlet),$ the chance that Miss Scarlet would leave a red hair, but rather $\mathbb P(Scarlet\mid redhair),$ the chance that this red hair was left by Scarlet.  There are other people in this city who have red hair."

"So you're saying..." the detective said slowly, "that $\mathbb P(redhair\mid Scarlet)$ is actually much lower than $1$?"

"No, detective.  I am saying that just because $\mathbb P(redhair\mid Scarlet)$ is high does not imply that $\mathbb P(Scarlet\mid redhair)$ is high.  It is the latter probability in which we are interested - the degree to which, *knowing* that a red hair was left at the scene, we *infer* that Miss Scarlet was the murderer.  This is not the same quantity as the degree to which, *assuming* Miss Scarlet was the murderer, we would *guess* that she might leave a red hair."

"But surely," said the detective, "these two probabilities cannot be entirely unrelated?"

"Ah, well, for that, you must read up on [1lz Bayes' rule]."

# Example 3

> "Even if most Dark Wizards are from Slytherin, very few Slytherins are Dark Wizards. There aren't all that many Dark Wizards, so not all Slytherins can be one."

> "So yeh're saying, that most Dark Wizards are Slytherins... but..."

> "But most Slytherins are not Dark Wizards."

— Harry Potter and the Methods of Rationality, Ch. 100


Normalization (probability)

[summary:  "Normalization" obtains a set of [1rf probabilities] summing to 1, in [1rd cases where they ought to sum to 1].  We do this by dividing each pre-normalized number by the sum of all pre-normalized numbers.

Suppose the [1rb odds] of Alexander Hamilton winning an election are 3 : 2.  We think the proportions are right (Alexander is 1.5 times as likely to win as not win) but we want *probabilities*.  To say that Hamilton has probability 3 of winning the election would be very strange indeed.  But if we divide each of the terms by the sum of all the terms, they'll end up summing to one:  $3:2 \cong \frac{3}{3+2} : \frac{2}{3+2} = 0.6 : 0.4.$  Thus, the probability that Hamilton wins is 60%.]

"Normalization" is an arithmetical procedure carried out to obtain a set of [1rf probabilities] summing to exactly 1, in cases where we believe that [1rd exactly one of the corresponding possibilities is true], and we already know the [1rb relative probabilities].

For example, suppose that the [1rb odds] of Alexander Hamilton winning a presidential election are 3 : 2.  But Alexander Hamilton must either win or not win, so the *probabilities* of him winning *or* not winning should sum to 1.  If we just add 3 and 2, however, we get 5, which is an unreasonably large probability.

If we rewrite the odds as 0.6 : 0.4, we've preserved the same proportions, but made the terms sum to 1.  We therefore calculate that Hamilton has a 60% probability of winning the election.

We normalized those odds by dividing each of the terms by the sum of terms, i.e., went from 3 : 2 to $\frac{3}{3+2} : \frac{2}{3+2} = 0.6 : 0.4.$

In converting the odds $m : n$ to $\frac{m}{m+n} : \frac{n}{m+n},$ the factor $\frac{1}{m+n}$ by which we multiply all elements of the ratio is called a [https://en.wikipedia.org/wiki/Normalizing_constant normalizing constant].

More generally, if we have a relative-odds function $\mathbb{O}(H)$ where $H$ has many components, and we want to convert this to a probability function $\mathbb{P}(H)$ that sums to 1, we divide every element of $\mathbb{O}(H)$ by the sum of all elements in $\mathbb{O}(H).$  That is:

$\mathbb{P}(H_i) = \frac{\mathbb{O}(H_i)}{\sum_i \mathbb{O}(H_i)}$

Analogously, if $\mathbb{O}(x)$ is a continuous distribution on $X$, we would normalize it (create a proportional probability function $\mathbb{P}(x)$ whose integral is equal to 1) by dividing $\mathbb{O}(x)$ by its own integral:

$\mathbb{P}(x) = \frac{\mathbb{O}(x)}{\int \mathbb{O}(x) \operatorname{d}x}$

In general, whenever a probability function on a variable is *proportional* to some other function, we can obtain the probability function by *normalizing* that function:

$\mathbb{P}(H) \propto \mathbb{O}(H) \implies \mathbb{P}(H) = \frac{\mathbb{O}(H)}{\sum \mathbb{O}(H)}$


Prior probability

"Prior [1rf probability]", "prior [1rb odds]", or just "prior" refers to a state of belief that obtained before seeing a piece of new evidence.  Suppose there are two suspects in a murder, Colonel Mustard and Miss Scarlet.  After determining that the victim was poisoned, you think Mustard and Scarlet are respectively 25% and 75% likely to have committed the murder.  *Before* determining that the victim was poisoned, perhaps, you thought Mustard and Scarlet were equally likely to have committed the murder (50% and 50%).  In this case, your "prior probability" of Miss Scarlet committing the murder was 50%, and your "posterior probability" after seeing the evidence was 75%.

The prior probability of a hypothesis $H$ is often being written with the unconditioned notation $\mathbb P(H)$, while the posterior after seeing the evidence $e$ is often being denoted by the [1rj conditional probability] $\mathbb P(H\mid e).$%%note: [E. T. Jaynes](http://bayes.wustl.edu/) was known to insist on using the explicit notation $\mathbb P (H\mid I_0)$ to denote the prior probability of $H$, with $I_0$ denoting the prior, and never trying to write any entirely unconditional probability $\mathbb P(X)$.  Since, said Jaynes, we always have *some* prior information.%% %%knows-requisite([1r6]): This however is a heuristic rather than a law, and might be false inside some complicated problems.  If we've already seen $e_0$ and are now updating on $e_1$, then in this new problem the new prior will be $\mathbb P(H\mid e_0)$ and the new posterior will be $\mathbb P(H\mid e_1 \wedge e_0).$ %%

For questions about how priors are "ultimately" determined, see [11w].


Interest in mathematical foundations in Bayesianism

[summary:  "Want" this [1ln requisite] if you prefer to see extra information about the mathematical foundations in [1r8 Bayesian reasoning].]

[multiple-choice(q1): Would you like to see extra information about mathematical foundations in [1bv] and [1r8]?
a:  Sure!
wants: [1rn]
b:  Not right now, thanks.
knows: [1rn]
]


Posterior probability

"Posterior [1rf probability]" or "posterior [1rb odds]" refers our state of belief *after* seeing a piece of new evidence and doing a [1ly Bayesian update].  Suppose there are two suspects in a murder, Colonel Mustard and Miss Scarlet.  Before determining the victim's cause of death, perhaps you thought Mustard and Scarlet were equally likely to have committed the murder (50% and 50%).  After determining that the victim was poisoned, you now think that Mustard and Scarlet are respectively 25% and 75% likely to have committed the murder.  In this case, your "[1rm prior probability]" of Miss Scarlet committing the murder was 50%, and your "posterior probability" *after* seeing the evidence was 75%.  The posterior probability of a hypothesis $H$ after seeing the evidence $e$ is often denoted using the [1rj conditional probability notation] $\mathbb P(H\mid e).$


Relative likelihood

Relative likelihoods express how *relatively* more likely an observation is, comparing one hypothesis to another.  For example, suppose we're investigating the murder of Mr. Boddy, and we find that he was killed by poison. The suspects are Miss Scarlett and Colonel Mustard. Now, suppose that the [-1rf probability] that Miss Scarlett would use poison, if she _were_ the murderer, is 20%. And suppose that the probability that Colonel Mustard would use poison, if he were the murderer, is 10%. Then, Miss Scarlett is *twice as likely* to use poison as a murder weapon as Colonel Mustard. Thus, the "Mr. Boddy was poisoned" evidence supports the "Scarlett" hypothesis twice as much as the "Mustard" hypothesis, for relative likelihoods of $(2 : 1).$

These likelihoods are called "relative" because it wouldn't matter if the respective probabilities were 4% and 2%, or 40% and 20% — what matters is the _relative proportion_.

Relative likelihoods may be given between many different hypotheses at once. Given the evidence $e_p$ = "Mr. Boddy was poisoned", it might be the case that Miss Scarlett, Colonel Mustard, and Mrs. White have the respective probabilities 20%, 10%, and 1% of using poison any time they commit a murder. In this case, we have three hypotheses — $H_S$ = "Scarlett did it", $H_M$ = "Mustard did it", and $H_W$ = "White did it". The relative likelihoods between them may be written $(20 : 10 : 1).$

In general, given a list of hypotheses $H_1, H_2, \ldots, H_n,$ the relative likelihoods on the evidence $e$ can be written as a [ scale-invariant list] of the likelihoods $\mathbb P(e \mid H_i)$ for each $i$ from 1 to $n.$ In other words, the relative likelihoods are

$$ \alpha \mathbb P(e \mid H_1) : \alpha \mathbb P(e \mid H_2) : \ldots : \alpha \mathbb P(e \mid H_n) $$

where the choice of $\alpha > 0$ does not change the value denoted by the list (i.e., the list is [scale_invariant_list scale-invariant]). For example, the relative likelihood list $(20 : 10 : 1)$ above denotes the same thing as the relative likelihood list $(4 : 2 : 0.20)$ denotes the same thing as the relative likelihood list $(60 : 30 : 3).$ This is why we call them "relative likelihoods" — all that matters is the ratio between each term, not the absolute values.

Any two terms in a list of relative likelihoods can be used to generate a [-56t] between two hypotheses. For example, above, the likelihood ratio $H_S$ to $H_M$ is 2/1, and the likelihood ratio of $H_S$ to $H_W$ is 20/1. This means that the evidence $e_p$ supports the "Scarlett" hypothesis 2x more than it supports the "Mustard" hypothesis, and 20x more than it supports the "White" hypothesis.

Relative likelihoods summarize the [22x strength of the evidence] represented by the observation that Mr. Boddy was poisoned — under [1lz Bayes' rule], the evidence points to Miss Scarlett to the same degree whether the absolute probabilities are 20% vs. 10%, or 4% vs. 2%.

By Bayes' rule, the way to update your beliefs in the face of evidence is to take your [1rm prior] [-1rb] and simply multiply them by the corresponding relative likelihood list, to obtain your [1rp posterior] odds. See also [1x5].


Bayes' rule examples

This page and its tabs store exemplar problems for Bayes' rule.  You can suggest additional example problems by leaving a comment on the appropriate tab.

Problem types by tab:

- [22w Introductory].  Meant as a small set of problems for people who haven't heard of Bayes' rule before, with examples that will be discussed in the introductory pages for Bayes' rule.
- [ Homework].  Problems for people who already know Bayes' rule and want to test their grasp of it in straightforward ways.
- [ Clever].  Problems for people who wish to be mathematically entertained, or that exhibit some surprising facet or gotcha of Bayes' rule.
- [1x4 Realistic].  Instances of Bayesian reasoning that have arisen in real life.


Waterfall diagram

[summary:  Waterfall diagrams, like [560 frequency diagrams], provide a way of visualizing [1lz Bayes' Rule].  For example, if 20% of the patients in the screening patient are sick (red) and 80% are healthy (blue); and 90% of the sick patients get positive test results; and 30% of the healthy patients get positive test results, we could visualize the probability flows using the following diagram:

![Waterfall diagram](https://i.imgur.com/CXsoZhA.png?0)]

Waterfall diagrams, like [560 frequency diagrams], provide a way of visualizing [1lz Bayes' Rule]. Recall that Bayes' rule (in the [1x5 odds form]) says that the posterior odds between any two hypotheses is equal to the prior odds times the relative likelihoods.

For example, in the [22s Diseasitis] problem, a patient is 20% likely to be sick (and 80% likely to be healthy) a priori, and they take a test that is 3x more likely to come back positive if they are sick. The odds of a patient being sick _given_ a positive test are thus $(1 : 4) \times (3 : 1) = (3 : 4).$

Using waterfall diagrams, we can visualize the prior odds as two separate streams of water at the top of a waterfall, and the relative likelihoods as the proportion of water from each stream that makes it to the shared pool at the bottom. The posterior odds can then be visualized as the proportion of water in the shared pool that came from each different prior stream.

![Waterfall diagram](https://i.imgur.com/CXsoZhA.png?0)

See [1x1] for a walkthrough of the diagram.

Waterfall diagrams make it clear that, when calculating the posterior odds, what matters is the _relative proportion_ between how much each gallon of red water vs each gallon of blue water makes it into the shared pool. If 45% of red water and 15% of blue water made it to the bottom, that would give the same _relative proportion_ of red and blue water in the shared pool at the bottom as 90% and 30%.

![Same relative proportions](https://i.imgur.com/6FOndjc.png?0)

Thus, it is only the relative likelihoods (and not the absolute likelihoods) that matter when calculating posterior odds.

Similarly, changing the water flows at the top of the waterfall from (20 gallons/sec red water : 80 gallons/sec blue water) to (40 gallons/sec red water : 160 gallons/sec blue water) would double the total water at bottom, but not change the relative proportions of blue and red water.  So only the *relative* prior odds matter to the *relative* posterior odds.


Waterfall diagrams and relative odds

[summary:  Waterfall diagrams, like [560 frequency diagrams], provide a way of visualizing [1lz Bayes' Rule].  For example, if 20% of the patients in the screening patient are sick (red) and 80% are healthy (blue); and 90% of the sick patients get positive test results; and 30% of the healthy patients get positive test results, we could visualize the probability flows using the following diagram:

![Waterfall diagram](https://i.imgur.com/CXsoZhA.png?0)

This diagram helps show that only the *relative* ratios matter to the final answer.  Twice as much water flowing from both streams at the top, or half as much water from each stream making it to the bottom, wouldn't change the relative proportions in the end result.]

Imagine a waterfall with two streams of water at the top, a red stream and a blue stream.  These streams separately approach the top of the waterfall, with some of the water from both streams being diverted along the way, and the remaining water falling into a shared pool below.

![unlabeled waterfall](https://i.imgur.com/D8EhY65.png?0)

Suppose that:

- At the top of the waterfall, 20 gallons/second of red water are flowing down, and 80 gallons/second of blue water are coming down.
- 90% of the red water makes it to the bottom.
- 30% of the blue water makes it to the bottom.

Of the purplish water that makes it to the bottom of the pool, how much was originally from the red stream and how much was originally from the blue stream?

%%if-after([55z]):
This is structurally identical to the [22s Diseasitis] problem from [55z before]:

- 20% of the patients in the screening population start out with Diseasitis.
- Among patients with Diseasitis, 90% turn the tongue depressor black.
- 30% of the patients without Diseasitis will also turn the tongue depressor black.
%%

%%!if-after([55z]):
This is structurally similar to the following problem, such as medical students might encounter:

You are a nurse screening 100 patients for Diseasitis, using a tongue depressor which usually turns black for patients who have the sickness.

- 20% of the patients in the screening population start out with Diseasitis.
- Among patients with Diseasitis, 90% turn the tongue depressor black (true positives).
- However, 30% of the patients without Diseasitis will also turn the tongue depressor black (false positives).

What is the chance that a patient with a blackened tongue depressor has Diseasitis?
%%

The 20% of sick patients are analogous to the 20 gallons/second of red water; the 80% of healthy patients are analogous to the 80 gallons/second of blue water:

![top labeled waterfall](https://i.imgur.com/eQh2qUt.png?0)

The 90% of the sick patients turning the tongue depressor black is analogous to 90% of the red water making it to the bottom of the waterfall.  30% of the healthy patients turning the tongue depressor black is analogous to 30% of the blue water making it to the bottom pool.

![middle labeled waterfall](https://i.imgur.com/6GBBYO5.png?0)

Therefore, the question "what portion of water in the final pool came from the red stream?" has the same answer as the question "what portion of patients that turn the tongue depressor black are sick with Diseasitis?"

%%if-after([55z]):
Now for the faster way of answering that question.
%%

We start with *4 times as much blue water as red water* at the top of the waterfall.

Then each molecule of red water is 90% likely to make it to the shared pool, and each molecule of blue water is 30% likely to make it to the pool.  (90% of red water and 30% of blue water make it to the bottom.)  So each molecule of red water is *3 times as likely* (0.90 / 0.30 = 3) as a molecule of blue water to make it to the bottom.

So we multiply prior proportions of $1 : 4$ for red vs. blue by relative likelihoods of $3 :  1$ and end up with final proportions of $(1 \cdot 3) : (4 \cdot 1) = 3 : 4$, meaning that the bottom pool has 3 parts of red water to 4 parts of blue water.

![labeled waterfall](https://i.imgur.com/QIrtuVU.png?0)

To convert these *relative* proportions into an *absolute* probability that a random water molecule at the bottom is red, we calculate 3 / (3 + 4) to see that 3/7ths (roughly 43%) of the water in the shared pool came from the red stream.

This proportion is the same as the 18 : 24 sick patients with positive results, versus healthy patients with positive test results, that we would get by [560 thinking about 100 patients].

That is, to solve the Diseasitis problem in your head, you could convert this word problem:

> 20% of the patients in a screening population have Diseasitis.  90% of the patients with Diseasitis turn the tongue depressor black, and 30% of the patients without Diseasitis turn the tongue depressor black. Given that a patient turned their tongue depressor black, what is the probability that they have Diseasitis?

Into this calculation:

> Okay, so the initial odds are (20% : 80%) = (1 : 4), and the likelihoods are (90% : 30%) = (3 : 1). Multiplying those ratios gives final odds of (3 : 4), which converts to a probability of 3/7ths.

(You might not be able to convert 3/7 to 43% in your head, but you might be able to eyeball that it was a chunk less than 50%.)

You can try doing a similar calculation for this problem:

- 90% of widgets are good and 10% are bad.
- 12% of bad widgets emit sparks.
- Only 4% of good widgets emit sparks.

What percentage of sparking widgets are bad? If you are sufficiently comfortable with the setup, try doing this problem entirely in your head.

(You might try visualizing a waterfall with good and bad widgets at the top, and only sparking widgets making it to the bottom pool.)
%todo: Have a picture of a waterfall here, with no numbers, but with the parts labeled, that can be expanded if the user wants to expand it.%

%%hidden(Show answer):
- There's (1 : 9) bad vs. good widgets.
- Bad vs. good widgets have a (12 : 4) relative likelihood to spark.
- This simplifies to (1 : 9) x (3 : 1) = (3 : 9) = (1 : 3), 1 bad sparking widget for every 3 good sparking widgets.
- Which converts to a probability of 1/(1+3) = 1/4 = 25%; that is, 25% of sparking widgets are bad.

Seeing sparks didn't make us "believe the widget is bad"; the probability only went to 25%, which is less than 50/50.  But this doesn't mean we say, "I still believe this widget is good!" and toss out the evidence and ignore it.  A bad widget is *relatively more likely* to emit sparks, and therefore seeing this evidence should cause us to think it *relatively more likely* that the widget is a bad one, even if the probability hasn't yet gone over 50%.  We increase our probability from 10% to 25%.%%

%%if-before([1x8]):
Waterfalls are one way of visualizing the "odds form" of "Bayes' rule", which states that **the prior odds times the likelihood ratio equals the posterior odds.**  In turn, this rule can be seen as formalizing the notion of "the strength of evidence" or "how much a piece of evidence should make us update our beliefs".  We'll take a look at this more general form next.
%%

%%!if-before([1x8]):
Waterfalls are one way of visualizing the [1x5 odds form] of [1lz Bayes' rule], which states that **the prior odds times the likelihood ratio equals the posterior odds**.
%%


Humans doing Bayes

Tag for examples of human beings applying explicitly Bayesian reasoning in everyday life.  Parent for rules, heuristics, and concepts that are specifically about the human, cognitive use of explicit Bayesian reasoning.


Explicit Bayes as a counter for 'worrying'

[summary:  By making up plausible Bayesian probabilities, we can summarize all of our knowledge about a problem in the same place at the same time, rather than 'worrying' by bouncing back and forth between different parts of it.  To use one real-life example, if an OKCupid match cancels your first date without explanation, then you might be tempted to 'worry' by bouncing your focus back and forth between possible valid reasons to cancel the date, versus possible ways it was a bad sign.  Alternatively, you could estimate  [1rm prior] [1rb odds] of 2 : 5 for desirability vs. undesirability of a 96% OKCupid match, a 1 : 3 [1rq likelihood ratio] for desirable vs. undesirable men flaking on the first date, decide that the [1rp posterior] odds of 2 : 15 don't warrant further pursuit, and then be done.  The point isn't that the made-up numbers are exact, but that they summarize the relevant weights into a single place and calculation, terminating the 'worry' cycle of alternating attention on particular pieces, and letting us be done.]

One of the possible [1x2 human uses of explicit Bayesian reasoning] is that making up explicit probabilities and doing the Bayesian calculation lets us summarize the relevant considerations in one place.  This can counter a mental loop of 'worrying' by bouncing back and forth between focusing on individual considerations.

One example comes from a woman who was a test subject for an early version of the Bayes intro at the same time she was dating on OKCupid, and a 96% OKCupid match canceled their first date for coffee without explanation.  After bouncing back and forth mentally between 'maybe there was a good reason he canceled' versus 'that doesn't seem like a good sign', she decided to try Bayes.  She estimated that a man like this one had [1rm prior] [1rb odds] of 2 : 5 for desirability vs. undesirability, based on his OKCupid profile and her past experience with 96% matches.  She then estimated a 1 : 3 [1rq likelihood ratio] for desirable vs. undesirable men flaking on the first date.  This worked out to 2 : 15 [1rp posterior] odds for the man being undesirable, which she decided was unfavorable enough to not pursue him further.

The point of this mental exercise wasn't that the numbers she made up were exact.  Rather, by laying out all the key factors in one place, she stopped her mind from bouncing back and forth between %%knows-requisite([1rj]): visualizing $\mathbb P(\text{cancel}|\text{desirable})$ and visualizing $\mathbb P(\text{cancel}|\text{undesirable})$, which were pulling her back and forth as arguments pointing in different directions.%% %%!knows-requisite([1rj]): switching between imagining reasons why a good prospect might've canceled, versus imagining reasons why a bad prospect might've canceled.%%  By combining both ideas into a likelihood ratio, and moving on to posterior odds, she summarized the considerations and was able to stop unproductively 'worrying'.

Worrying isn't always unproductive.  Paying more attention to an individual consideration like "Maybe there were reasons a good dating prospect might've canceled anyway?" might cause you to adjust your estimate of this consideration, thereby changing your posterior odds.  But you can get the *illusion* of progress by switching your attention from one already-known consideration to another, since it feels like these considerations are pulling on your posterior intuition each time you focus on them.  It feels like your beliefs are changing and cognitive work is being performed, but actually you're just going in circles.  This is the 'unproductive worrying' process that you can interrupt by doing an explicitly Bayesian calculation that summarizes what you already know into a single answer.

(She did send him a rejection notice spelling out her numerical reasoning; since, if he wrote back in a way indicating that he actually understood that, he might've been worth a second chance.)

(He didn't.)


Realistic (Math 1)

### What's the chance that a potentially good partner would flake on the first date?

From a test subject for an early version of the Bayes intro:

A 96% OKCupid match canceled their first date for coffee without providing an explanation.

She estimated that a man like this one had [1rm prior] [1rb odds] of 2 : 5 for desirability vs. undesirability, based on his OKCupid profile and her past experience with 96% matches.  She then estimated a 1 : 3 [1rq likelihood ratio] for desirable vs. undesirable men flaking on the first date.  This worked out to 2 : 15 [1rp posterior] odds for the man being undesirable, which she decided was unfavorable enough to not pursue him further.

She [1x3 used this explicitly Bayesian calculation to interrupt a 'worrying' cycle] wherein she was focusing on one consideration, then a different consideration, arguing for pursuing further / not pursuing further.  Making up numbers and doing the Bayesian calculation [1x3 terminated this cycle].


Bayes' rule: Odds form

[summary:  A form of [1lz Bayes' rule] that uses relative [1rb odds].

Suppose we're trying to solve a mysterious murder, and we [1rm start out] thinking the odds of Professor Plum vs. Miss Scarlet committing the murder are 1 : 2, that is, Scarlet is twice as likely as Plum to have committed the murder.  We then observe that the victim was bludgeoned with a lead pipe.  If we think that Plum, *if* he commits a murder, is around 60% likely to use a lead pipe, and that Scarlet, *if* she commits a murder, would be around 6% likely to us a lead pipe, this implies [1rq relative likelihoods] of 10 : 1 for Plum vs. Scarlet using the pipe.

The [1rp posterior] odds for Plum vs. Scarlet, after observing the victim to have been murdered by a pipe, are $(1 : 2) \times (10 : 1) = (10 : 2) = (5 : 1)$.  We now think Plum is around five times as likely as Scarlet to have committed the murder.]

One of the more convenient forms of [1lz Bayes' rule] uses [1rb relative odds]. Bayes' rule says that, when you observe a piece of evidence $e,$ your [1rp posterior] odds $\mathbb O(\boldsymbol H \mid e)$ for your hypothesis [-vector] $\boldsymbol H$ given $e$ is just your [1rm prior] odds $\mathbb O(\boldsymbol H)$ on $\boldsymbol H$ times the [-56s] $\mathcal L_e(\boldsymbol H).$

For example, suppose we're trying to solve a mysterious murder, and we start out thinking the odds of Professor Plum vs. Miss Scarlet committing the murder are 1 : 2, that is, Scarlet is twice as likely as Plum to have committed the murder [1rm a priori].  We then observe that the victim was bludgeoned with a lead pipe.  If we think that Plum, *if* he commits a murder, is around 60% likely to use a lead pipe, and that Scarlet, *if* she commits a murder, would be around 6% likely to us a lead pipe, this implies [1rq relative likelihoods] of 10 : 1 for Plum vs. Scarlet using the pipe.  The [1rp posterior] odds for Plum vs. Scarlet, after observing the victim to have been murdered by a pipe, are $(1 : 2) \times (10 : 1) = (10 : 2) = (5 : 1)$.  We now think Plum is around five times as likely as Scarlet to have committed the murder.

# Odds functions

Let $\boldsymbol H$ denote a [-vector] of hypotheses. An odds function $\mathbb O$ is a function that maps $\boldsymbol H$ to a set of [-1rb]. For example, if $\boldsymbol H = (H_1, H_2, H_3),$ then $\mathbb O(\boldsymbol H)$ might be $(6 : 2 : 1),$ which says that $H_1$ is 3x as likely as $H_2$ and 6x as likely as $H_3.$ An odds function captures our *relative* probabilities between the hypotheses in $\boldsymbol H;$ for example, (6 : 2 : 1) odds are the same as (18 : 6 : 3) odds. We don't need to know the absolute probabilities of the $H_i$ in order to know the relative odds. All we require is that the relative odds are proportional to the absolute probabilities:
$$\mathbb O(\boldsymbol H) \propto \mathbb P(\boldsymbol H).$$

In the example with the death of Mr. Boddy, suppose $H_1$ denotes the proposition "Reverend Green murdered Mr. Boddy", $H_2$ denotes "Mrs. White did it", and $H_3$ denotes "Colonel Mustard did it". Let $\boldsymbol H$ be the vector $(H_1, H_2, H_3).$ If these propositions respectively have [1rm prior] probabilities of 80%, 8%, and 4% (the remaining 8% being reserved for other hypotheses), then $\mathbb O(\boldsymbol H) = (80 : 8 : 4) = (20 : 2 : 1)$ represents our *relative* credences about the murder suspects — that Reverend Green is 10 times as likely to be the murderer as Miss White, who is twice as likely to be the murderer as Colonel Mustard.

# Likelihood functions

Suppose we discover that the victim was murdered by wrench.  Suppose we think that Reverend Green, Mrs. White, and Colonel Mustard, *if* they murdered someone, would respectively be 60%, 90%, and 30% likely to use a wrench.  Letting $e_w$ denote the observation "The victim was murdered by wrench," we would have $\mathbb P(e_w\mid \boldsymbol H) = (0.6, 0.9, 0.3).$ This gives us a [-56s] defined as $\mathcal L_{e_w}(\boldsymbol H) = P(e_w \mid \boldsymbol H).$

# Bayes' rule, odds form

Let $\mathbb O(\boldsymbol H\mid e)$ denote the [1rp posterior] odds of the hypotheses $\boldsymbol H$ after observing evidence $e.$  [1xr Bayes' rule] then states:

$$\mathbb O(\boldsymbol H) \times \mathcal L_{e}(\boldsymbol H) = \mathbb O(\boldsymbol H\mid e)$$

This says that we can multiply the relative prior credence $\mathbb O(\boldsymbol H)$ by the likelihood $\mathcal L_{e}(\boldsymbol H)$ to arrive at the relative posterior credence $\mathbb O(\boldsymbol H\mid e).$ Because odds are invariant under multiplication by a positive constant, it wouldn't make any difference if the _likelihood_ function was scaled up or down by a constant, because that would only have the effect of multiplying the final odds by a constant, which does not affect them. Thus, only the [-1rq relative likelihoods] are necessary to perform the calculation; the absolute likelihoods are unnecessary. Therefore, when performing the calculation, we can simplify $\mathcal L_e(\boldsymbol H) = (0.6, 0.9, 0.3)$ to the relative likelihoods $(2 : 3 : 1).$

In our example, this makes the calculation quite easy. The prior odds for Green vs White vs Mustard were $(20 : 2 : 1).$ The relative likelihoods were $(0.6 : 0.9 : 0.3)$ = $(2 : 3 : 1).$ Thus, the relative posterior odds after observing $e_w$ = Mr. Boddy was killed by wrench are $(20 : 2 : 1) \times (2 : 3 : 1) = (40 : 6 : 1).$ Given the evidence, Reverend Green is 40 times as likely as Colonel Mustard to be the killer, and 20/3 times as likely as Mrs. White.

Bayes' rule states that this *relative* proportioning of odds among these three suspects will be correct, regardless of how our remaining 8% probability mass is assigned to all other suspects and possibilities, or indeed, how much probability mass we assigned to other suspects to begin with. For a proof, see [1xr].

# Visualization

[560 Frequency diagrams], [1wy waterfall diagrams], and [1zm spotlight diagrams] may be helpful for explaining or visualizing the odds form of Bayes' rule.


Introduction to Bayes' rule: Odds form

[summary: The odds form of Bayes' rule is a form of [1lz Bayes' rule] that uses [1rq relative likelihoods] and [-1rb]. It says that in general, the [1rm prior] odds times the [56t likelihood ratio] equals the [1rp posterior] odds.

[22s Suppose] that the odds of a particular patient being sick are about $(1 : 4),$ i.e., they may be drawn from a population where there is 1 sick patient for every 4 healthy ones. Suppose we administer a test which comes back positive 90% of the time if the patient is _actually_ sick, but also comes back positive 30% of the time even when the patient is healthy; this means relative likelihoods of $(90 : 30) = (3 : 1)$: the test is 3x as likely to come back positive if the patient is sick. Bayes' rule then says that the odds of the patient being sick _after_ observing a positive test are $(1 : 4) \times (3 : 1) = (3 : 4),$ for a final probability of about $3/(3+4) \approx 43\%.$]

%%!if-after([1x1]):
**This introduction is meant to be read after the introductions to [55z frequency visualizations] and [1x1 waterfall visualizations].**
%%

In general, Bayes' rule states:

$$ \textbf{Prior odds} \times \textbf{Relative likelihoods} = \textbf{Posterior odds}$$

If we consider the [1wy waterfall visualization] of [22s the Diseasitis example],
then we can visualize how *relative odds* are appropriate for thinking about the two rivers at the top of the waterfall.

![Waterfall visualization](https://i.imgur.com/eQh2qUt.png?0)

The *proportion* of red vs. blue water at the bottom will be the same whether there's 200 vs. 800 gallons per second of red vs. blue water at the top of the waterfall, or 20,000 vs. 80,000 gallons/sec, or 1 vs. 4 gallons/second.  So long as the rest of the waterfall behaves in a proportional way, we'll get the same proportion of red vs blue at the bottom. Thus, we're justified in ignoring the _amount_ of water and considering only the relative proportion between amounts.

Similarly, what matters is the *relative* proportion between how much of each gallon of red water makes it into the shared pool, and how much of each gallon of blue water, makes it.  45% and 15% of the red and blue water making it to the bottom would give the same *relative proportion* of red and blue water in the bottom pool as 90% and 30%.

![Changing the proportion makes no difference](https://i.imgur.com/6FOndjc.png?0)

This justifies throwing away the specific data that 90% of the red stream and 30% of the blue stream make it down, and summarizing this into *relative likelihoods* of (3 : 1).

More generally, suppose we have a medical test that detects a sickness with a 90% true positive rate (10% false negatives) and a 30% false positive rate (70% true negatives).  A positive result on this test represents the same *strength of evidence* as a test with 60% true positives and 20% false positives.  A negative result on this test represents the same *strength of evidence* as a test with 9% false negatives and 63% true negatives.

In general, the strength of evidence is summarized by how *relatively* likely different states of the world make our observations. %%!if-before([1zh]): For more on this idea, see  [22x]. %% %%if-before([1zh]): More on this later. %%

# The equation

To state Bayes' rule in full generality, and prove it as a theorem, we'll need to introduce some new notation.

## Conditional probability

First, when $X$ is a proposition, $\mathbb P(X)$ will stand for the [1rf probability] of $X.$

In other words, $X$ is something that's either true or false in reality, but we're uncertain about it, and $\mathbb P(X)$ is a way of expressing our [4y9 degree of belief] that $X$ is true.  A patient is, in fact, either sick or healthy; but if you don't know which of these is the case, the evidence might lead you to assign a 43% subjective probability that the patient is sick.

$\mathbb \neg X$ will mean "$X$ is false", so $\mathbb P(\neg X)$ is the "the probability $X$ is false".

The Diseasitis involved some more complicated statements than this, though; in particular it involved:

- The 90% chance that a patient blackens the tongue depressor, *given* that they have Diseasitis.
- The 30% chance that a patient blackens the tongue depressor, *given* that they're healthy.
- The 3/7 chance that a patient has Diseasitis, *given* that they blackened the tongue depressor.

In these cases we want to go from some fact that is *assumed* or *known* to be true (on the right), to some other proposition (on the left) whose new probability we want to ask about, taking into account that assumption.

Probability statements like those are known as "conditional probabilities".  The standard notation for conditional probability expresses the above quantities as:

- $\mathbb P(blackened \mid sick) = 0.9$
- $\mathbb P(blackened \mid \neg sick) = 0.3$
- $\mathbb P(sick \mid blackened) = 3/7$

This standard notation for $\mathbb P(X \mid Y)$ meaning "the probability of $X$, assuming $Y$ to be true" is a helpfully symmetrical vertical line, to avoid giving you any visual clue to remember that the assumption is on the right and the inferred proposition is on the left. </sarcasm>

Conditional probability is *defined* as follows.  Using the notation $X \wedge Y$ to denote "X and Y" or "both $X$ and $Y$ are true":

$$\mathbb P(X \mid Y) := \frac{\mathbb P(X \wedge Y)}{\mathbb P(Y)}$$

E.g. in the Diseasitis example, $\mathbb P(sick \mid  blackened)$ is calculated by dividing the 18% students who are sick *and* have blackened tongue depressors ($\mathbb P(sick \wedge blackened)$), by the total 42% students who have blackened tongue depressors ($\mathbb P(blackened)$).

Or $\mathbb P(blackened \mid \neg sick),$ the probability of blackening the tongue depressor *given* that you're healthy, is equivalent to the 24 students who are healthy *and* have blackened tongue depressors, divided by the 80 students who are healthy.  24 / 80 = 3/10, so this corresponds to the 30% false positives we were told about at the start.

We can see the law of conditional probability as saying, "Let us restrict our attention to worlds where $Y$ is the case, or thingies of which $Y$ is true.  Looking only at cases where $Y$ is true, how many cases are there *inside* that restriction where $X$ is *also* true - cases with $X$ *and* $Y$?"

For more on this, see [1rj].

## Bayes' rule

Bayes' rule says:

$$\textbf{Prior odds} \times \textbf{Relative likelihoods} = \textbf{Posterior odds}$$

In the Diseasitis example, this would state:

$$\dfrac{\mathbb P({sick})}{\mathbb P(healthy)} \times \dfrac{\mathbb P({blackened}\mid {sick})}{\mathbb P({blackened}\mid healthy)} = \dfrac{\mathbb P({sick}\mid {blackened})}{\mathbb P(healthy\mid {blackened})}.$$

%todo: apparently the parallel is not super obvious, and maybe we can use slightly different colors in the text to make it clearer that e.g. Prior odds -> sick/healthy%

The [1rm prior] odds refer to the relative proportion of sick vs healthy patients, which is $1 : 4$. Converting these odds into probabilities gives us $\mathbb P(sick)=\frac{1}{4+1}=\frac{1}{5}=20\%$.

The [-1rq] refers to how much more likely each sick patient is to get a positive test result than each healthy patient, which (using [1rj conditional probability notation]) is $\frac{\mathbb P(positive \mid sick)}{\mathbb P(positive \mid healthy)}=\frac{0.90}{0.30},$ aka relative likelihoods of $3 : 1.$

The [1rp posterior] odds are the relative proportions of sick vs healthy patients among those with positive test results, or $\frac{\mathbb P(sick \mid positive)}{\mathbb P(healthy \mid positive)} = \frac{3}{4}$, aka $3 : 4$ odds.

To extract the *probability* from the relative odds, we keep in mind that probabilities of [1rd mutually exclusive and exhaustive propositions] need to sum to $1,$ that is, there is a 100% probability of *something* happening.  Since everyone is either sick or not sick, we can [1rk normalize] the odd ratio $3 : 4$ by dividing through by the sum of terms:

$$(\frac{3}{3+4} : \frac{4}{3+4}) = (\frac{3}{7} : \frac{4}{7}) \approx (0.43 : 0.57)$$

...ending up with the probabilities (0.43 : 0.57), proportional to the original ratio of (3 : 4), but summing to 1.  It would be very odd if something had probability $3$ (300% probability) of happening.

Using the waterfall visualization:

![labeled waterfall](https://i.imgur.com/CXsoZhA.png?0)

We can generalize this to _any_ two **hypotheses** $H_j$ and $H_k$ with **evidence** $e$, in which case Bayes' rule can be written as:

$$\dfrac{\mathbb P(H_j)}{\mathbb P(H_k)} \times \dfrac{\mathbb P(e \mid H_j)}{\mathbb P(e \mid H_k)} = \dfrac{\mathbb P(H_j \mid e)}{\mathbb P(H_k \mid e)}$$

which says "the posterior odds ratio for hypotheses $H_j$ vs $H_k$ (after seeing the evidence $e$) are equal to the prior odds ratio times the ratio of how well $H_j$ predicted the evidence compared to $H_k.$"

If $H_j$ and $H_k$ are [-1rd], we can convert the posterior odds into a posterior probability for $H_j$ by [1rk normalizing] the odds - dividing through the odds ratio by the sum of its terms, so that the elements of the new ratio sum to $1.$

## Proof of Bayes' rule

Rearranging [1rj the definition of conditional probability], $\mathbb P(X \wedge Y) = \mathbb P(Y) \cdot \mathbb P(X|Y).$  E.g. to find "the fraction of all patients that are sick *and* get a positive result", we multiply "the fraction of patients that are sick" times "the probability that a sick patient blackens the tongue depressor".

Then this is a proof of Bayes' rule:

$$
\frac{\mathbb P(H_j)}{\mathbb P(H_k)}
\cdot
\frac{\mathbb P(e_0 | H_j)}{\mathbb P(e_0 | H_k)}
=
\frac{\mathbb P(e_0 \wedge H_j)}{\mathbb P(e_0 \wedge H_k)}
=
\frac{\mathbb P(H_j \wedge e_0)/\mathbb P(e_0)}{\mathbb P(H_k \wedge e_0)/\mathbb P(e_0)}
=
\frac{\mathbb P(H_j | e_0)}{\mathbb P(H_k | e_0)}
$$

QED.

In the Diseasitis example, these proof steps correspond to the operations:

$$
\frac{0.20}{0.80}
\cdot
\frac{0.90}{0.30}
=
\frac{0.18}{0.24}
=
\frac{0.18/0.42}{0.24/0.42}
=
\frac{0.43}{0.57}
$$

Using red for sick, blue for healthy, grey for a mix of sick and healthy patients, and + signs for positive test results, the calculation steps can be visualized as follows:

![bayes venn](https://i.imgur.com/YBc2nYo.png?0)

%todo: maybe replace this diagram with pie-chart circles in exactly right proportions (but still with the correct populations of + signs)%

This process of observing evidence and using its likelihood ratio to transform a prior belief into a posterior belief is called a "[1ly Bayesian update]" or "belief revision."

%%if-before([21v]):
Congratulations!  You now know (we hope) what Bayes' rule is, and how to apply it to simple setups.  After this, the path continues with further implications %if-before([1zg]): and additional forms% of Bayes' rule. This might be a good time to take a break, if you want one--but we hope you continue on this Arbital path after that!
%%

%%!if-before([1zg]):
- For the generalization of the odds form of Bayes' rule to multiple hypotheses and multiple items of evidence, see [1zg].
- For a transformation of the odds form that makes the strength of evidence even more directly visible, see [1zh].
%%


Proof of Bayes' rule

Bayes' rule (in the [1x5 odds form]) says that, for every pair of hypotheses $H_i$ and $H_j$ and piece of evidence $e,$

$$\dfrac{\mathbb P(H_i)}{\mathbb P(H_j)} \times \dfrac{\mathbb P(e \mid H_i)}{\mathbb P(e \mid H_j)} = \dfrac{\mathbb P(H_i \mid e)}{\mathbb P(H_j \mid e)}.$$

By the definition of [1rj conditional probability], $\mathbb P(e \land H)$ $=$ $\mathbb P(H) \cdot \mathbb P(e \mid H),$ so

$$ \dfrac{\mathbb P(H_i)}{\mathbb P(H_j)} \times  \dfrac{\mathbb P(e\mid H_i)}{\mathbb P(e\mid H_j)} = \dfrac{\mathbb P(e \wedge H_i)}{\mathbb P(e \wedge H_j)} $$

Dividing both the numerator and the denominator by $\mathbb P(e),$ we have

$$ \dfrac{\mathbb P(e \wedge H_i)}{\mathbb P(e \wedge H_j)} = \dfrac{\mathbb P(e \wedge H_i) / \mathbb P(e)}{\mathbb P(e \wedge H_j) / \mathbb P(e)} $$

Invoking the definition of conditional probability again,

$$ \dfrac{\mathbb P(e \wedge H_i) / \mathbb P(e)}{\mathbb P(e \wedge H_j) / \mathbb P(e)} = \dfrac{\mathbb P(H_i\mid e)}{\mathbb P(H_j\mid e)}.$$

Done.

---

Of note is the equality

$$\frac{\mathbb P(H_i\mid e)}{\mathbb P(H_j\mid e)} = \frac{\mathbb P(H_i \land e)}{\mathbb P(H_j \land e)},$$

which says that the posterior odds (on the left) for $H_i$ (vs $H_j$) given evidence $e$ is exactly equal to the prior odds of $H_i$ (vs $H_j$) in the parts of $\mathbb P$ where $e$ was already true. $\mathbb P(x \land e)$ is the amount of probability mass that $\mathbb P$ allocated to worlds where both $x$ and $e$ are true, and the above equation says that after observing $e,$ your belief in $H_i$ relative to $H_j$ should be equal to $H_i$'s odds relative to $H_j$ _in those worlds._ In other words, Bayes' rule can be interpreted as saying: "Once you've seen $e$, simply throw away all probability mass except the mass on worlds where $e$ was true, and then continue reasoning according to the remaining probability mass." See also [1y6].

## Illustration (using the Diseasitis example)

Specializing to the [22s Diseasitis] problem, using red for sick, blue for healthy, and + signs for positive test results, the proof above can be visually depicted as follows:

![bayes venn](https://i.imgur.com/YBc2nYo.png?0)

This visualization can be read as saying: The ratio of the initial sick population (red) to the initial healthy population (blue), times the ratio of positive results (+) in the sick population to positive results in the blue population, equals the ratio of the positive-and-red population to positive-and-blue population. Thus we can divide both into the proportion of the whole population which got positive results (grey and +), yielding the posterior odds of sick (red) vs healthy (blue) among only those with positive results.

The corresponding numbers are:

$$\dfrac{20\%}{80\%} \times  \dfrac{90\%}{30\%} = \dfrac{18\%}{24\%} = \dfrac{0.18 / 0.42}{0.24 / 0.42} = \dfrac{3}{4}$$

for a final probability $\mathbb P(sick)$ of $\frac{3}{7} \approx 43\%.$

## Generality

The [1x5 odds] and [1zm proportional] forms of Bayes' rule talk about the *relative* probability of two hypotheses $H_i$ and $H_j.$ In the particular example of Diseasitis it happens that [1rd every patient is either sick or not-sick], so that we can [1rk normalize] the final odds 3 : 4 to probabilities of $\frac{3}{7} : \frac{4}{7}.$ However, the proof above shows that even if we were talking about two different possible diseases and their total prevalances did not sum to 1, the equation above would still hold between the *relative* prior odds for $\frac{\mathbb P(H_i)}{\mathbb P(H_j)}$ and the *relative* posterior odds for $\frac{\mathbb P(H_i\mid e)}{\mathbb P(H_j\mid e)}.$

The above proof can be specialized to the probabilistic case; see [56j].


Belief revision as probability elimination

One way of understanding the reasoning behind [1lz Bayes' rule] is that the process of updating $\mathbb P$ in the face of new evidence can be interpreted as the elimination of probability mass from $\mathbb P$ (namely, all the probability mass inconsistent with the evidence).

%todo: we have a request to use a not-Diseasitis problem here, because it was getting repetitive.%

%%!if-after([55z]):
We'll use as a first example the [22s Diseasitis] problem:

> You are screening a set of patients for a disease, which we'll call Diseasitis.  You expect that around 20% of the patients in the screening population start out with Diseasitis.  You are testing for the presence of the disease using a tongue depressor with a sensitive chemical strip.  Among patients with Diseasitis, 90% turn the tongue depressor black. However, 30% of the patients without Diseasitis will also turn the tongue depressor black. One of your patients comes into the office, takes your test, and turns the tongue depressor black. Given only that information, what is the probability that they have Diseasitis?
%%

%%if-after([55z]):
We'll again start with the [22s] example: a population has a 20% prior prevalence of Diseasitis, and we use a test with a 90% true-positive rate and a 30% false-positive rate.
%%

In the situation with a single, individual patient, before observing any evidence, there are four possible worlds we could be in:

%todo: change LaTeX to show Sick in red, Healthy in blue%

$$\begin{array}{l|r|r}
& Sick & Healthy \\
\hline
Test + & 18\% & 24\% \\
\hline
Test - & 2\% & 56\%
\end{array}$$

To *observe* that the patient gets a positive result, is to eliminate from further consideration the possible worlds where the patient gets a negative result, and vice versa:

![bayes elimination](https://i.imgur.com/LGeGIzW.png?0)

So Bayes' rule says: to update your beliefs in the face of evidence, simply throw away the probability mass that was inconsistent with the evidence.

# Example: Socks-dresser problem

Realizing that *observing evidence* corresponds to *eliminating probability mass* and concerning ourselves only with the probability mass that remains, is the key to solving the [55b sock-dresser search] problem:

> You left your socks somewhere in your room.  You think there's a 4/5 chance that they've been tossed into some random drawer of your dresser, so you start looking through your dresser's 8 drawers.  After checking 6 drawers at random, you haven't found your socks yet.  What is the probability you will find your socks in the next drawer you check?

%todo: request for a picture here%

(You can optionally try to solve this problem yourself before continuing.)

%%hidden(Answer):

We initially have 20% of the probability mass in "Socks outside the dresser", and 80% of the probability mass for "Socks inside the dresser".  This corresponds to 10% probability mass for each of the 8 drawers (because each of the 8 drawers is equally likely to contain the socks).

After eliminating the probability mass in 6 of the drawers, we have 40% of the original mass remaining, 20% for "Socks outside the dresser" and 10% each for the remaining 2 drawers.

Since this remaining 40% probability mass is now our whole world, the effect on our probability distribution is like amplifying the 40% until it expands back up to 100%, aka [1rk renormalizing the probability distribution].  Within the remaining prior probability mass of 40%, the "outside the dresser" hypothesis has half of it (prior 20%), and the two drawers have a quarter each (prior 10% each).

So the probability of finding our socks in the next drawer is 25%.

For some more flavorful examples of this method of using Bayes' rule, see [https://www.gwern.net/docs/statistics/1994-falk The ups and downs of the hope function in a fruitless search].

%%

# Extension to subjective probability

On the Bayesian paradigm, this idiom of *belief revision as conditioning a [probability_distribution probability distribution] on evidence* works both in cases where there are statistical populations with objective frequencies corresponding to the probabilities, _and_ in cases where our uncertainty is _subjective._

For example, imagine being a king thinking about a uniquely weird person who seems around 20% likely to be an assassin.  This doesn't mean that there's a population of similar people of whom 20% are assassins; it means that you weighed up your uncertainty and guesses and decided that you would bet at odds of 1 : 4 that they're an assassin.

You then estimate that, if this person is an assassin, they're 90% likely to own a dagger — so far as your subjective uncertainty goes; if you imagine them being an assassin, you think that 9 : 1 would be good betting odds for that.  If this particular person is not an assassin, you feel like the probability that she ought to own a dagger is around 30%.

When you have your guards search her, and they find a dagger, then (according to students of Bayes' rule) you should update your beliefs in the same way you update your belief in the Diseasitis setting — where there _is_ a large population with an objective frequency of sickness — despite the fact that this maybe-assassin is a unique case. According to a Bayesian, your brain can track the probabilities of different possibilities regardless, even when there are no large populations and objective frequencies anywhere to be found, and when you update your beliefs using evidence, you're not "eliminating people from consideration," you're eliminating _probability mass_ from certain _possible worlds_ represented in your own subjective belief state.

%todo: add answer check for assassin%


Probability notation for Bayes' rule

[summary:  [1lz Bayes' rule] relates [1rm prior] belief and the [1rq likelihood] of evidence to [1rp posterior] belief.

These quantities are often denoted using [1rj conditional probabilities]:

- [1rm Prior] belief in hypothesis:  $\mathbb P(H).$
- [1rq Likelihood] of evidence, conditional on hypothesis:  $\mathbb P(e \mid H).$
- [1rp Posterior] belief:  $\mathbb P(H \mid e).$
]

[1lz Bayes' rule] relates [1rm prior] belief and the [1rq likelihood] of evidence to [1rp posterior] belief.

These quantities are often written using [1rj conditional probabilities]:

- [1rm Prior] belief in the hypothesis:  $\mathbb P(H).$
- [1rq Likelihood] of evidence, conditional on the hypothesis:  $\mathbb P(e \mid H).$
- [1rp Posterior] belief in hypothesis, after seeing evidence:  $\mathbb P(H \mid e).$

For example, Bayes' rule in the [1x5 odds form] describes the relative belief in a hypothesis $H_1$ vs an alternative $H_2,$ given a piece of evidence $e,$ as follows:

$$\dfrac{\mathbb P(H_1)}{\mathbb P(H_2)} \times \dfrac{\mathbb P(e \mid H_1)}{\mathbb P(e \mid H_2)} = \dfrac{\mathbb P(H_1\mid e)}{\mathbb P(H_2\mid e)}.$$


Probability notation for Bayes' rule: Intro (Math 1)

To denote some of the quantities used in Bayes' rule, we'll need [1rj conditional probabilities].  The conditional probability $\mathbb{P}(X\mid Y)$ means "The [1rf probability] of $X$ given $Y$."  That is, $\mathbb P(\mathrm{left}\mid \mathrm{right})$ means "The probability that $\mathrm{left}$ is true, assuming that $\mathrm{right}$ is true."

$\mathbb P(\mathrm{yellow}\mid \mathrm{banana})$ is the probability that a banana is yellow - if we know something to be a banana, what is the probability that it is yellow?  $\mathbb P(\mathrm{banana}\mid \mathrm{yellow})$ is the probability that a yellow thing is a banana - if the right, known side is yellowness, then, we ask the question on the left, what is the probability that this is a banana?

In probability theory, the definition of "conditional probability" is that the conditional probability of $L,$ given $R,$ is found by looking at the probability of possibilities with both $L$ *and* $R$ *within* all possibilities with $R.$  Using $L \wedge R$ to denote the logical proposition "L and R both true":

$\mathbb P(L\mid R) = \frac{\mathbb P(L \wedge R)}{\mathbb P(R)}$

Suppose you have a bag containing objects that are either red or blue, and either square or round:

$$\begin{array}{l|r|r}
& Red & Blue \\
\hline
Square & 1 & 2 \\
\hline
Round & 3 & 4
\end{array}$$

If you reach in and feel a round object, the conditional probability that it is red is:

$\mathbb P(\mathrm{red} \mid  \mathrm{round}) = \dfrac{\mathbb P(\mathrm{red} \wedge \mathrm{round})}{\mathbb P(\mathrm{round})} \propto \dfrac{3}{3 + 4} = \frac{3}{7}$

If you look at the object nearest the top, and can see that it's blue, but not see the shape, then the conditional probability that it's a square is:

$\mathbb P(\mathrm{square} \mid  \mathrm{blue}) = \dfrac{\mathbb P(\mathrm{square} \wedge \mathrm{blue})}{\mathbb P(\mathrm{blue})} \propto \dfrac{2}{2 + 4} = \frac{1}{3}$

![conditional probabilities bag](https://i.imgur.com/zscEdLj.png?0)

# Updating as conditioning

Bayes' rule is useful because the process of *observing new evidence* can be interpreted as *conditioning a probability distribution.*

Again, the Diseasitis problem:

> 20% of the patients in the screening population start out with Diseasitis. Among patients with Diseasitis, 90% turn the tongue depressor black. 30% of the patients without Diseasitis will also turn the tongue depressor black. Among all the patients with black tongue depressors, how many have Diseasitis?

Consider a single patient, before observing any evidence.  There are four possible worlds we could be in, the product of (sick vs. healthy) times (positive vs. negative result):

$$\begin{array}{l|r|r}
& Sick & Healthy \\
\hline
Test + & 18\% & 24\% \\
\hline
Test - & 2\% & 56\%
\end{array}$$

To actually *observe* that the patient gets a negative result, is to eliminate from further consideration the possible worlds where the patient gets a positive result:

![bayes elimination](https://i.imgur.com/LGeGIzW.png?0)

Once we observe the result $\mathrm{positive}$, all of our future reasoning should take place, not in our old $\mathbb P(\cdot),$ but in our new $\mathbb P(\cdot \mid  \mathrm{positive}).$  This is why, after observing "$\mathrm{positive}$" and revising our probability distribution, when we ask about the probability the patient is sick, we are interested in the new probability $\mathbb P(\mathrm{sick}\mid \mathrm{positive})$ and not the old probability $\mathbb P(\mathrm{sick}).$

## Example: Socks-dresser problem

Realizing that *observing evidence* corresponds to [1y6 eliminating probability mass] and concerning ourselves only with the probability mass that remains, is the key to solving the [55b sock-dresser search] problem:

> You left your socks somewhere in your room.  You think there's a 4/5 chance that they're in your dresser, so you start looking through your dresser's 8 drawers.  After checking 6 drawers at random, you haven't found your socks yet.  What is the probability you will find your socks in the next drawer you check?

We initially have 20% of the probability mass in "Socks outside the dresser", and 80% of the probability mass for "Socks inside the dresser".  This corresponds to 10% probability mass for each of the 8 drawers.

After eliminating the probability mass in 6 of the drawers, we have 40% of the original mass remaining, 20% for "Socks outside the dresser" and 10% each for the remaining 2 drawers.

Since this remaining 40% probability mass is now our whole world, the effect on our probability distribution is like amplifying the 40% until it expands back up to 100%, aka [1rk renormalizing the probability distribution].  This is why we divide $\mathbb P(L \wedge R)$ by $\mathbb P(R)$ to get the new probabilities.

In this case, we divide "20% probability of being outside the dresser" by 40%, and then divide the 10% probability mass in each of the two drawers by 40%.  So the new probabilities are 1/2 for outside the dresser, and 1/4 each for the 2 drawers.  Or more simply, we could observe that, among the remaining probability mass of 40%, the "outside the dresser" hypothesis has half of it, and the two drawers have a quarter each.

So the probability of finding our socks in the next drawer is 25%.

Note that as we open successive drawers, we both become more confident that the socks are not in the dresser at all (since we eliminated several drawers they could have been in), *and* also expect more that we might find the socks in the next drawer we open (since there are so few remaining).

# Priors, likelihoods, and posteriors

Bayes' theorem is generally inquiring about some question of the form $\mathbb P(\mathrm{hypothesis}\mid \mathrm{evidence})$ - the $\mathrm{evidence}$ is known or assumed, so that we are now mentally living in the revised probability distribution $\mathbb P(\cdot\mid \mathrm{evidence}),$ and we are asking what we infer or guess about the $hypothesis.$  This quantity is the **[1rp posterior probability]** of the $\mathrm{hypothesis}.$

To carry out a Bayesian revision, we also need to know what our beliefs were before we saw the evidence.  (E.g., in the Diseasitis problem, the chance that a patient who hasn't been tested yet is sick.)  This is often written $\mathbb P(\mathrm{hypothesis}),$ and the hypothesis's probability isn't being conditioned on anything because it is our **[1rm prior]** belief.

The remaining pieces of key information are the **[1rq likelihoods]** of the evidence, given each hypothesis.  To interpret the meaning of the positive test result as evidence, we need to imagine ourselves in the world where the patient is sick - *assume* the patient to be sick, as if that were known - and then ask, just as if we hadn't seen any test result yet, what we think the probability of the evidence would be in that world.  And then we have to do a similar operation again, this time mentally inhabiting the world where the patient is healthy.  And unfortunately, it so happens that the standard notation are such as to make this idea be denoted $\mathbb P(\mathrm{evidence}\mid \mathrm{hypothesis})$ - looking deceptively like the notation for the posterior probability, but written in the reverse order.  Not surprisingly, this trips people up a bunch until they get used to it.  (You would at least hope that the standard symbol $\mathbb P(\cdot \mid \cdot)$ wouldn't be *symmetrical,* but it is.  Alas.)

## Example

Suppose you're Sherlock Holmes investigating a case in which a red hair was left at the scene of the crime.

The Scotland Yard detective says, "Aha!  Then it's Miss Scarlet.  She has red hair, so if she was the murderer she almost certainly would have left a red hair there.  $\mathbb P(\mathrm{redhair}\mid \mathrm{Scarlet}) = 99\%,$ let's say, which is a near-certain conviction, so we're done."

"But no," replies Sherlock Holmes.  "You see, but you do not correctly track the meaning of the [1rj conditional probabilities], detective.  The knowledge we require for a conviction is not $\mathbb P(\mathrm{redhair}\mid \mathrm{Scarlet}),$ the chance that Miss Scarlet would leave a red hair, but rather $\mathbb P(\mathrm{Scarlet}\mid \mathrm{redhair}),$ the chance that this red hair was left by Scarlet.  There are other people in this city who have red hair."

"So you're saying..." the detective said slowly, "that $\mathbb P(\mathrm{redhair}\mid \mathrm{Scarlet})$ is actually much lower than $1$?"

"No, detective.  I am saying that just because $\mathbb P(\mathrm{redhair}\mid \mathrm{Scarlet})$ is high does not imply that $\mathbb P(\mathrm{Scarlet}\mid \mathrm{redhair})$ is high.  It is the latter probability in which we are interested - the degree to which, *knowing* that a red hair was left at the scene, we *infer* that Miss Scarlet was the murderer.  The posterior, as the Bayesians say.  This is not the same quantity as the degree to which, *assuming* Miss Scarlet was the murderer, we would *guess* that she might leave a red hair.  That is merely the likelihood of the evidence, conditional on Miss Scarlet having done it."

## Visualization

Using the [1wy waterfall] for the [22s Diseasitis problem]:

![waterfall labeled probabilities](https://i.imgur.com/f9E0ltp.png?0)

[todo: add an Example 2 and Example 3, maybe with graphics, because I expect this part to be confusing.  steal from L0 Bayes.]


Bayes' rule: Vector form

[summary:  The [1x5 odds form of Bayes' rule] works for odds ratios between more than two hypotheses, and applying multiple pieces of evidence.  Suppose there's a bathtub full of coins.  1/2 of the coins are fair and have a 50% probability of producing heads on each coinflip; 1/3 of the coins produce 25% heads; and 1/6 produce 75% heads.  You pull out a coin at random, flip it 3 times, and get the result HTH.  You may calculate:

$$\begin{array}{rll}
(1/2 : 1/3 : 1/6) = & (3 : 2 : 1) & \\
\times & (2 : 1 : 3) & \\
\times & (2 : 3 : 1) & \\
\times & (2 : 1 : 3) & \\
= & (24 : 6 : 9) & = (8 : 2 : 3)
\end{array}$$]

%todo: This page conflates two concepts: (1) You can perform a Bayesian update on multiple hypotheses at once, by representing hypotheses via vectors; and (2) you can perform multiple Bayesian updates by multiplying by all the likelihood functions (and only normalizing once at the end). We should probably have one page for each concept, and we should possibly split this page in order to make them. (It's not yet clear whether we want one unified page for both ideas, as this one currently is.)%
%comment:  Comment from ESY: it seems to me that these two concepts are sufficiently closely related, and sufficiently combined in their demonstration, that we want to explain them on the same page.  They could arguably have different concept pages, though.%

[1lz Bayes' rule] in the [1x5 odds form] says that for every pair of hypotheses, their relative prior odds, times the relative likelihood of the evidence, equals the relative posterior odds.

Let $\mathbf H$ be a vector of hypotheses $H_1, H_2, \ldots$ Because Bayes' rule holds between every pair of hypotheses in $\mathbf H,$ we can simply multiply an odds vector by a likelihood vector in order to get the correct posterior vector:

$$\mathbb O(\mathbf H) \times \mathcal L_e(\mathbf H) = \mathbb O(\mathbf H \mid e)$$

%comment: Comment from EN: It seems to me that the dot product would be more appropriate.%

where $\mathbb O(\mathbf H)$ is the vector of relative prior odds between all the $H_i$, $\mathcal L_e(\mathbf H)$ is the vector of relative likelihoods with which each $H_i$ predicted $e,$ and $\mathbb O(\mathbf H \mid e)$ is the relative posterior odds between all the $H_i.$

In fact, we can keep multiplying by likelihood vectors to perform multiple updates at once:

$$\begin{array}{r}
\mathbb O(\mathbf H) \\
\times\ \mathcal L_{e_1}(\mathbf H) \\
\times\ \mathcal L_{e_2}(\mathbf H \wedge e_1) \\
\times\ \mathcal L_{e_3}(\mathbf H \wedge e_1 \wedge e_2) \\
= \mathbb O(\mathbf H \mid e_1 \wedge e_2 \wedge e_3)
\end{array}$$

For example, suppose there's a bathtub full of coins.  Half of the coins are "fair" and have a 50% probability of producing heads on each coinflip. A third of the coins is biased towards heads and produces heads 75% of the time.   The remaining coins are biased against heads, which they produce only 25% of the time.  You pull out a coin at random, flip it 3 times, and get the result THT.  What's the chance that this was a fair coin?

We have three hypotheses, which we'll call $H_{fair},$  $H_{heads}$, and $H_{tails}$ and respectively, with relative odds of $(1/2 : 1/3 : 1/6).$ The relative likelihoods that these three hypotheses assign to a coin landing heads is $(2 : 3 : 1)$; the relative likelihoods that they assign to a coin landing tails is $(2 : 1 : 3).$ Thus, the posterior odds for all three hypotheses are:

$$\begin{array}{rll}
(1/2 : 1/3 : 1/6) = & (3 : 2 : 1) & \\
\times & (2 : 1 : 3) & \\
\times & (2 : 3 : 1) & \\
\times & (2 : 1 : 3) & \\
= & (24 : 6 : 9) & = (8 : 2 : 3) = (8/13 : 2/13 : 3/13)
\end{array}$$

...so there is an 8/13 or ~62% probability that the coin is fair.

If you were only familiar with the [554 probability form] of Bayes' rule, which only works for one hypothesis at a time and which only uses probabilities (and so [1rk normalizes] the odds into probabilities at every step)...

$$\mathbb P(H_i\mid e) = \dfrac{\mathbb P(e\mid H_i)P(H_i)}{\sum_k \mathbb P(e\mid H_k)P(H_k)}$$

...then you might have had some gratuitous difficulty solving this problem.

Also, if you hear the idiom of "convert to odds, multiply lots and lots of things, convert back to probabilities" and think "hmm, this sounds like a place where [4h0 transforming into log-space] (where all multiplications become additions) might yield efficiency gains," then congratulations, you just invented the [1zh log-odds from of Bayes' rule]. Not only is it efficient, it also gives rise to a natural unit of measure for "strength of evidence" and "strength of belief".

# Naive Bayes

Multiplying an array of odds by an array of likelihoods is the idiom used in Bayesian spam filters.  Suppose that there are three categories of email, "Business", "Personal", and "Spam", and that the user hand-labeling the last 100 emails has labeled 50 as Business, 30 as Personal, and 20 as spam.  The word "buy" has appeared in 10 Business emails, 3 Personal emails, and 10 spam emails.  The word "rationality" has appeared in 30 Business emails, 15 Personal emails, and 1 spam email.

First, we assume that the frequencies in our data are representative of the 'true' frequencies.  (Taken literally, if we see a word we've never seen before, we'll be multiplying by a zero probability.  [Good-Turing frequency estimation](https://en.wikipedia.org/wiki/Good%E2%80%93Turing_frequency_estimation) would do better.)

Second, we make the *naive Bayes* assumption that a spam email which contains the word "buy" is no more or less likely than any other spam email to contain the word "rationality", and so on with the other categories.

Then we'd filter a message containing the phrase "buy rationality" as follows:

[1rm Prior] odds: $(5 : 3 : 2)$

[1rq Likelihood ratio] for "buy":

$$\left(\frac{10}{50} : \frac{3}{30} : \frac{10}{20}\right) = \left(\frac{1}{5} : \frac{1}{10} : \frac{1}{2}\right) = (2 : 1 : 5)$$

Likelihood ratio for "rationality":

$$\left(\frac{30}{50} : \frac{15}{30} : \frac{1}{20}\right) = \left(\frac{3}{5} : \frac{1}{2} : \frac{1}{20}\right) = (12 : 10 : 1)$$

Posterior odds:

$$(5 : 3 : 2) \times (2 : 1 : 5) \times (12 : 10 : 1) = (120 : 30 : 10) = \left(\frac{12}{16} : \frac{3}{16} : \frac{1}{16}\right)$$

%%comment:  12/16 is intentionally not in lowest form so that the 12 : 3 : 1 ratio can be clear.%%

This email would be 75% likely to be a business email, if the Naive Bayes assumptions are true.  They're almost certainly *not* true, for reasons discussed in more detail below.  But while Naive Bayes calculations are usually quantitatively wrong, they often point in the right qualitative direction - this email may indeed be more likely than not to be a business email.

(An actual implementation should add [1zh log-likelihoods] rather than multiplying by ratios, so as not to risk floating-point overflow or underflow.)

# Non-naive multiple updates

To do a multiple update less naively, we must do the equivalent of asking about the probability that a Business email contains the word "rationality", *given* that it contained the word "buy".

As a real-life example, in a certain [rationality workshop](http://rationality.org/), one participant was observed to have taken another participant to a museum, and also, on a different day, to see their workplace.  A betting market soon developed on whether the two were romantically involved.  One participant argued that, as an eyeball estimate, someone was 12 times as likely to take a fellow participant to a museum, or to their workplace, if they were romantically involved, vs. just being strangers.  They then multiplied their prior odds by a 12 : 1 likelihood ratio for the museum trip and another 12 : 1 likelihood ratio for the workplace trip, and concluded that these two were almost certainly romantically attracted.

It later turned out that the two were childhood acquaintances who were not romantically involved.  What went wrong?

If we want to update hypotheses on multiple pieces of evidence, we need to mentally stay inside the world of each hypothesis, and condition the likelihood of future evidence on the evidence already observed.  Suppose the two are *not* romantically attracted.  We observe them visit a museum.  Arguendo, we might indeed suppose that this has a probability of, say, 1% (we don't usually expect strangers to visit museums together) which might be about 1/12 the probability of making that observation if the two were romantically involved.

But after this, when we observe the workplace visit, we need to ask about the probability of the workplace visit, *given* that the two were romantically attracted *and* that they visited a museum.  This might suggest that if two non-attracted people visit a museum together *for whatever reason*, they don't just have the default probability of a non-attracted couple of making a workplace visit.  In other words:

$$\mathbb P({workplace}\mid \neg {romance} \wedge {museum}) \neq \mathbb P({workplace}\mid \neg {romance})$$

Naive Bayes, in contrast, would try to approximate the quantity $\mathbb P({museum} \wedge {workplace} \mid \neg {romance})$ as the product of $\mathbb P({museum}\mid \neg {romance}) \cdot \mathbb P({workplace}\mid \neg {romance}).$  This is what the participants did when they multiplied by a 1/12 likelihood ratio twice.

The result was a kind of double-counting of the evidence — they took into account the prior improbability of a random non-romantic couple "going places together" twice in a row, for the two pieces of evidence, and ended up performing a total update that was much too strong.

Naive Bayes spam filters often end up assigning ludicrously extreme odds, on the order of googols to one, that an email is spam or personal; and then they're sometimes wrong anyways.  If an email contains the phrase "pharmaceutical" and "pharmacy", a spam filter will double-count the improbability of a personal email talking about pharmacies, rather than considering that if I actually do get a personal email talking about a pharmacy, it is much more likely to contain the word "pharmaceutical" as well. So because of the Naive Bayes assumption, naive Bayesian spam filters are not anything remotely like well-calibrated, and they update much too extremely on the evidence.  On the other hand, they're often extreme in the correct qualitative direction — something assigned googol-to-one odds of being spam isn't *always* spam but it might be spam, say, 99.999% of the time.

To do non-naive Bayesian updates on multiple pieces of evidence, just remember to mentally inhabit the world *where the hypothesis is true*, and then ask about the likelihood of each successive piece of evidence, *in* the world where the hypothesis is true *and* the previous pieces of evidence were observed.  Don't ask, "What is the likelihood that a non-romantic couple would visit one person's workplace?" but "What is the likelihood that a non-romantic couple which previously visited a museum for some unknown reason would also visit the workplace?"

In our example with the coins in the bathtub, the likelihoods of the evidence were independent on each step - *assuming* a coin to be fair, it's no more or less likely to produce heads on the second flip after producing heads on the first flip.  So in our bathtub-coins example, the Naive Bayes assumption was actually true.