Introduction: AI Today and in the Past. Probability and Bayes Rule
Vadim Sokolov
George Mason University
Fall 2026
Wednesdays 7:20–10:00, Enterprise 276. Weeks 1–7 lecture. Week 8 midterm. Weeks 9–14 studio and the project. Week 15 is the defense. Lecture is optional.
Labs 10, midterm 40, studio 10, defense 40. A correct number is not enough. You have to say what it means and what would change the choice.
Nothing is due tonight. Lab 1 is due before next class. On-time submission is the 10%. Not graded.
Laptops stay closed between stops. Open them on the orange slide. Use whatever AI you want at the stop, and disclose it. You are responsible for work you did not write. Midterm: pen and paper, one cheat sheet, no laptop, phone, or watch.
Set up the tutor this week, about ten minutes. R or Python; use the language you will defend.
I suggest cursor as your AI agent. $20 (16 if you pay for a year) subscription should be enough for the course.
On this Day (August 26):
Four blocks. In each one I lecture for 20 to 30 minutes, then we stop. Lids down while I talk.
You work the problem on your own first. Then compare with a neighbor. Laptop and AI are allowed at the stop. Then we reveal and start the next block.
The orange slides are the stop. Stay there until we discuss. The green slides are the solution. Do not skip ahead.
The take-home lab is separate. These in-class problems are not submitted.
The wish is old: Talos, Galatea, clay, a golem.
Albertus Magnus, 13th century, spends years on a brass head that answers questions.
Robots and Automatic Machines Were Generally Very Inventive: Al-Jazari (XII Century)
Hesdin Castle (Robert II of Artois), Leonardo’s robot…
Jaquet-Droz automata (XVIII century):
Logic machine of Ramon Llull (XIII-XIV centuries)
From the proposal:
Old AI
If rain outside, then take umbrella
This rule cannot be learned from data. It does not allow inference. Cannot say anything about rain outside if I see an umbrella.
New AI
Probability of taking umbrella, given there is rain
Conditional probability rule can be learned from data. Allows for inference. We can calculate the probability of rain outside if we see an umbrella.
Laptop and AI are allowed. Solo first. Then compare with a neighbor. Stay on this slide until we reveal.
A hospital currently uses 400 if-then rules, written by doctors, to recommend antibiotics. Write two sentences.
Count it right if sentence 1 names brittleness or the absence of a degree of belief, and sentence 2 names inheriting whatever the history rewarded. The paragraphs below are one way to say that.
Definition:
The computer program learns as the data is accumulating relative to a certain problem class \(T\) and the target function of \(P\) if the quality of solving these problems (relative to \(P\)) improves with gaining new experience.
There are no correct answers, only data, e.g. clustering:
The three paradigms say what you are given. These are decisions you make while you learn. They are not a fourth paradigm.
Reasoning is computing what else follows from what you already believe. Old AI used logic. New AI uses probability. A Bayes net is the clean version. An LLM chain is the messy one. This course is the clean one, so you can check the messy one.
If you cannot say what was conditioned on, you did not reason. You generated.
Reasoning needs something to reason over. Generation needs something to generate from. That object is a representation. Old AI wrote it by hand. New AI learns it from data. Same job.
A representation is a bet about which distinctions matter. A bad one makes every later model look worse than it is.
In shadows of data, uncertainty reigns,
Bayesian whispers, where knowledge remains.
With prior beliefs, we start our quest,
Updating with evidence, we strive for the best.
A dance of the models, predictions unfold,
Inferences drawn, from the new and the old.
Through probabilities, we find our way,
In the world of AI, it’s the Bayesian sway.
So gather your data, let prior thoughts flow,
In the realm of the unknown, let your insights grow.
For in this approach, with each little clue,
We weave understanding, both rich and true.
A humorous and illustrative scene of a hockey player sitting on a bench in full gear, holding a hockey stick in one hand and a whiteboard marker in th
Where this actually runs. Not a demo.
Sampling from \(P(\text{output} \mid \text{prompt})\) is the mechanism. Selecting the sample is still a decision.
Old AI: Deep Blue (1997) vs. Garry Kasparov.
Kasparov vs IBM’s DeepBlue in 1997
Alpha GO vs Lee Sedol: Move 37 by AlphaGo in Game Two
A model that only emits a point answer is unfinished. How confident is this? How well does it describe the data we have? If we ran the experiment again, how much would the number move? Classification, generation, and AlphaGo all produce those questions. A rule that fires or does not cannot.
The rest of tonight, and the next six weeks, is the machinery behind those statements.
Probability lets us talk efficiently about things that we are uncertain about.
All these involve estimating or predicting unknowns!!
Random Variables are numbers that we are not sure about. There’s a list of potential outcomes. We assign probabilities to each outcome.
Example: Two fair coins. Four equally likely outcomes:
\[\{TT,\; TH,\; HT,\; HH\}\]
Let \(X\) be the number of heads. \(X\) is not the coins. \(X\) is a function from those four outcomes to a number.
\[ \begin{array}{c|c} \text{outcome} & X \\ \hline TT & 0 \\ TH & 1 \\ HT & 1 \\ HH & 2 \end{array} \]
So \(X\) can be \(0\), \(1\), or \(2\). We do not yet know which. The next slide is the list of probabilities for those three numbers. That list is the distribution of \(X\).
Probability is a language designed to help us communicate about uncertainty. We assign a number between \(0\) and \(1\) measuring how likely that event is to occur. It’s immensely useful, and there’s only a few basic rules.
We describe the behavior of random variables with a Probability Distribution
Example: Suppose we are about to toss two coins. Let \(X\) denote the number of heads.
\[X = \left\{ \begin{array}{ll} 0 \text{ with prob. } 1/4\\ 1 \text{ with prob. } 1/2\\ 2 \text{ with prob. } 1/4 \end{array} \right.\]
\(X\) is called a Discrete Random Variable
Question: What is \(P(X=0)\)? How about \(P(X \geq 1)\)?
Pete Rose of the Cincinnati Reds set a National League record of hitting safely in \(44\) consecutive games …
What probability might reasonably be associated with that hitting streak?
Joe DiMaggio’s record is \(56\)! His batting average was \(.325\)
Let \(A_i\) be the event that Rose hits safely in game \(i\). Independence across games gives
\[P(A_1 \cap \cdots \cap A_{44}) = P(A_1)\cdots P(A_{44}) = \bigl(P(A_1)\bigr)^{44}\]
One game, four independent at-bats, batting average \(0.300\):
\[\begin{align*} P(A_1) &= 1 - P(\text{four outs}) \\ &= 1 - (0.7)^4 \\ &= 0.7599 \end{align*}\]
So \[P(\text{44-game hitting streak}) = (0.7599)^{44} \approx 5.67 \times 10^{-6}\]
There are three basic inferences:
Use probability to describe outcomes involving more than one variable at a time. Need to be able to measure what we think will happen to one variable relative to another
In general the notation is ...
Relationship between the joint and conditional ...
\[\begin{align*} P(x,y) & = P(x) P(y \mid x) \\ & = P(y) P(x \mid y) \end{align*}\]
Relationship between the joint and marginal ...
\[\begin{align*} P(x) & = \sum_y P(x,y) \\ P(y) & = \sum_x P(x,y) \end{align*}\]
“happiness index” as a function of salary.
| Salary (\(X\)) | Happiness (\(Y\)): 0 (low) | 1 (medium) | 2 (high) |
|---|---|---|---|
| low 0 | 0.03 | 0.12 | 0.07 |
| medium 1 | 0.02 | 0.13 | 0.11 |
| high 2 | 0.01 | 0.13 | 0.14 |
| very high 3 | 0.01 | 0.09 | 0.14 |
Is \(P(Y=2 \mid X=3) > P(Y=2)\)?
Laptop and AI are allowed. Solo first. Then compare with a neighbor. Stay on this slide until we reveal.
A wealth-management team wants to pitch a “wellbeing” product only to top-salary clients. The table is last year’s book.
| Salary \(X\) / Happiness \(Y\) | 0 | 1 | 2 |
|---|---|---|---|
| 0 | 0.03 | 0.12 | 0.07 |
| 1 | 0.02 | 0.13 | 0.11 |
| 2 | 0.01 | 0.13 | 0.14 |
| 3 | 0.01 | 0.09 | 0.14 |
The computation of \(P(x \mid y)\) from \(P(x)\) and \(P(y \mid x)\) is called Bayes theorem ... \[ P(x \mid y) = \frac{P(y,x)}{P(y)} = \frac{P(y,x)}{\sum_x P(y,x)} = \frac{P(y \mid x)P(x)}{\sum_x P(y \mid x)P(x)} \]
This shows now the conditional distribution is related to the joint and marginal distributions.
You’ll be given all the quantities on the r.h.s.
Key fact: \(P(x \mid y)\) is generally different from \(P(y \mid x)\)!
Example: Most people would agree
\[\begin{align*} Pr & \left ( Practice \; hard \mid Play \; in \; NBA \right ) \approx 1\\ Pr & \left ( Play \; in \; NBA \mid Practice \; hard \right ) \approx 0 \end{align*}\]
The main reason for the difference is that \(P( Play \; in \; NBA ) \approx 0\).
Two random variable \(X\) and \(Y\) are independent if \[ P(Y = y \mid X = x) = P (Y = y) \] for all possible \(x\) and \(y\) values. Knowing \(X=x\) tells you nothing about \(Y\)!
Example: Tossing a coin twice. What’s the probability of getting \(H\) in the second toss given we saw a \(T\) in the first one?
Sally Clark was accused and convicted of killing her two children
They could have both died of SIDS.
The chance of a family which are non-smokers and over 25 having a SIDS death is around 1 in 8,500.
The chance of a family which has already had a SIDS death having a second is around 1 in 100.
The chance of a mother killing her two children is around 1 in 1,000,000.
The \(\frac{1}{100}\) comes from taking into account genetics.
\[ P \left( \mathrm{both} \; \; \mathrm{SIDS} \right) = (1/8500) (1/8500) = (1/73,000,000) \]
\[ \frac{p(I|E)}{p(G|E)} = \frac{P( E \cap I)}{P( E \cap G)} \] \(P( E \cap I) = P(E|I )P(I)\) needs discussion of \(p(I)\).
\[ \frac{p(I|E)}{p(G|E)} = \frac{1/850,000}{1/1,000,000} = 1.18 \] This step treats the two stories as the only hypotheses and gives them equal prior odds. That is a modeling choice; \(p(I)\) still needs a real discussion.
In terms of posterior probabilities
\[ p( G|E) = \frac{1}{1 + 1.18} \approx 0.46 \]
\[ \frac{p(I|E)}{p(G|E)} = \frac{1}{73} \; \text{and} \; p( G|E) \approx 0.99 \] The suspect looks guilty.
The expected value of a random variable is simply a weighted average of the possible values X can assume.
The weights are the probabilities of occurrence of those values.
\[E(X) = \sum_x xP(X=x)\]
With \(n\) equally likely outcomes with values \(x_1, \ldots, x_n\), \(P(X = x_i) = 1/n\)
\[E(X) = \frac{x_1+x_2+\ldots+x_n}{n}\]
\[E(X) = \frac{1}{37}\times 36 + \frac{36}{37}\times 0 = 0.97\]
\[E(X) = \frac{18}{37}\times 2 + \frac{19}{37}\times 0 = 0.97\]
Casino is guaranteed to make money in the long run!
The variance is calculated as
\[Var(X) = E\left((X - E(X))^2\right)\]
A simpler calculation is \(Var(X) = E(X^2) - E(X)^2\).
The standard deviation is the square-root of variance.
\[sd(X) = \sqrt{Var(X)}\]
\[Var(X) = \frac{1}{37}\times (36 - 0.97)^2 + \frac{36}{37}\times (0 - 0.97)^2 = 34\]
\[Var(X) = \frac{18}{37}\times (2 - 0.97)^2+ \frac{19}{37}\times (0- 0.97)^2 = 1\]
If your goal is to spend as much time as possible in the casino (free drinks): place small bets on black/red
Tortoise and Hare are selling cars. Probability distributions, means and variances for \(X\), the number of cars sold
| 0 | 1 | 2 | 3 | Mean | Variance | sd | |
|---|---|---|---|---|---|---|---|
| cars sold | \(X\) | \(E(X)\) | \(Var(X)\) | \(\sqrt{Var(X)}\) | |||
| Tortoise | 0 | 0.5 | 0.5 | 0 | 1.5 | 0.25 | 0.5 |
| Hare | 0.5 | 0 | 0 | 0.5 | 1.5 | 2.25 | 1.5 |
Let’s do Tortoise expectations and variances
The Tortoise \[\begin{align*} E(T) &= (1/2)(1) + (1/2)(2) = 1.5 \\ Var(T) &= E(T^2) - E(T)^2 \\ &= (1/2)(1)^2 + (1/2)(2)^2 - (1.5)^2 = 0.25 \end{align*}\]
Now the Hare’s \[\begin{align*} E(H) &= (1/2)(0) + (1/2)(3) = 1.5 \\ Var(H) &= (1/2)(0)^2 + (1/2)(3)^2- (1.5)^2 = 2.25 \end{align*}\]
What do these tell us above the long run behavior?
We can express probabilities in terms of Odds via \[ O(A) = \frac{ 1- P(A) }{ P(A) } \; \; \text{or} \; \; P(A) = \frac{ 1 }{ 1 + O(A) } \]
In terms of probability \(P = \frac{1}{3}\).
Source: The Secret Betting Strategy That Beats Online Bookmakers
Suppose that we have two random variables \(X\) and \(Y\)
We need to measure whether they move together or in opposite directions The Covariance is defined by
\[Cov(X,Y) = E\left((X- E(X))(Y- E(Y))\right)\]
In terms of probability distributions, we need to calculate
\[Cov(X,Y) = \sum_{x,y} (x - E(X))(y - E(Y))P(x,y)\]
VIX vs S&P vs AAPL
The Correlation is defined by
\[Corr(X,Y) = \frac{Cov(X,Y)}{sd(X) sd(Y)}\]
If \(Cov(\text{Apple Sales, Economy}) = 5\), \(sd(\text{Apple Sales}) = 2\) and \(sd(\text{Economy}) = 3.5\), then there’s a \(71.4\)% correlation
\[Corr(\text{Apple Sales, Economy}) = \frac{5}{2 \times 3.5} = \frac{5}{7} = 0.714\]
Two key properties:
Let \(a, b\) be given constants
where \(Cov(X,Y)\) is the covariance between random variables.
Laptop and AI are allowed. Solo first. Then compare with a neighbor. Stay on this slide until we reveal.
Many decision problems are this. It is counterintuitive. It is the right answer. The denominator is the law of total probability.
\[ P(A \mid B) = \frac{P(A \cap B)}{P(B)} = \frac{P(B \mid A)\, P(A)}{P(B)} \]
\[ P(B) = P(B \mid A)\, P(A) + P(B \mid \bar{A})\, P(\bar{A}) \]
Alice is a 40-year-old woman. What is the chance that she really has breast cancer when she gets a positive mammogram, given:
The posterior probability \(P(\text{cancer} \mid \text{positive mammogram})\)?
Of 1000 cases:
Let’s think about this intuitively. Imagine 1000 people like Alice.
Now pick one of those 107 at random. What is the chance she has cancer? \[P(\text{cancer} \mid \text{positive}) = \frac{8}{107} \approx 7.5\%\]
\[P(\text{cancer} \mid \text{positive mammogram})=\frac{8}{107}\approx 7.5\%\]
Posterior Probability
Most women who test positive on a mammogram are healthy, because the vast majority of women who receive mammograms in the first place are healthy.
The Apple Watch Series 4 can perform a single-lead ECG and detect atrial fibrillation. The software can correctly identify 98% of cases of atrial fibrillation (sensitivity) and 99% of cases of non-atrial fibrillation (specificity).
Take prevalence \(P(\text{AF})=0.02\) in the population we care about. What is \(P(\text{AF} \mid \text{watch says AF})\)?
Bayes’ Theorem: \[ P(A|B)=\frac{P(B|A)P(A)}{P(B)} \]
Counts from 100,000 people at 2% prevalence, 98% sensitivity, 99% specificity:
| Predicted | atrial fibrillation | no atrial fibrillation |
|---|---|---|
| atrial fibrillation | 1960 | 980 |
| no atrial fibrillation | 40 | 97020 |
\[ 0.6667 = \frac{0.98\cdot 0.02}{ 0.0294} \]
The conditional probability of having atrial fibrillation when the Apple Watch Series 4 detects atrial fibrillation is about 67%.
How Abraham Wald improved aircraft survivability. Raw Reports from the Field
| Type of damage suffered | Returned (316 total) | Shot down (60 total) |
|---|---|---|
| Engine | 29 | ? |
| Cockpit | 36 | ? |
| Fuselage | 105 | ? |
| None | 146 | 0 |
This fact would allow Wald to estimate: \[ P(\text{damage on fuselage} \mid \text{returns safely}) = 105/316 \approx 32\% \] You need the inverse probability : \[ P(\text{returns safely} \mid \text{damage on fuselage}) \] Completely different!
Imputation: fill-in missing data.
| Type of damage suffered | Returned (316 total) | Shot down (60 total) |
|---|---|---|
| Engine | 29 | 31 |
| Cockpit | 36 | 21 |
| Fuselage | 105 | 8 |
| None | 146 | 0 |
Then Wald got:
\[\begin{align*} P(\text{returns safely} \mid \text{damage on fuselage}) & =\frac{105}{105+8}\approx 93\%\\ P(\text{returns safely} \mid \text{damage on engine}) & =\frac{29}{29+31}\approx 48\% \end{align*}\]
Laptop and AI are allowed. Solo first. Then compare with a neighbor. Stay on this slide until we reveal.
Many Business Applications!! Suggestions vs Search….
evidence: known facts about criminal (e.g. blood type, DNA, ...)
suspect: matches a trait with evidence at scene of crime
Let \(G\) denote the event that the suspect is the criminal.
Bayes computes the conditional probability of guilt
\[ P ( G | \text{evidence} ) \] Evidence \(E\): suspect and criminal possess a common trait
Bayes Theorem yields \[ P ( G | \text{evidence} ) = \frac{ P ( \text{evidence} | G ) P ( G ) }{ P ( \text{evidence} )} \]
In terms of relative odds \[ \frac{ P ( I | \text{evidence} ) }{ P ( G | \text{evidence} ) } = \frac{ P ( \text{evidence} | I ) }{ P ( \text{evidence} | G ) } \frac{ P ( I ) }{ P ( G ) } \]
There are two terms:
How many people on the island?
Sensitivity “what if” analysis?
The most common fallacy is confusing \[ P ( \text{evidence} | G ) \; \; \text{with} \; \; P ( G | \text{evidence} ) \]
Bayes rule yields \[ P ( G | \text{evidence} ) = \frac{ P ( \text{evidence} | G ) p( G )}{ P ( \text{evidence} )} \] Your assessment of \(P( G )\) will matter.
Suppose there’s a criminal on a island of \(N+1\) people.
Bayes factors are likelihood ratios
The Bayes factor is given by \[ \frac{p(E|I)}{p(E|G)}=p \]
If we start with a uniform prior distribution we have
\[ p(G)=\frac{1}{N+1},\qquad p(I)=\frac{N}{N+1},\qquad odds(I)=N \]
Posterior probability of innocence from the posterior odds of innocence: \[ p(I\mid y)=\frac{odds(I\mid y)}{1+odds(I\mid y)} \]
The posterior \(p(I\mid y)\) is not \(p(y\mid I)=p\).
\[ p( I\mid y) = \frac{1}{1+1} = \frac{1}{2} \]
The odds on innocence are \(odds(I|y)=1\).
There’s a \(50/50\) chance that the criminal has been found.
Laptop and AI are allowed. Solo first. Then compare with a neighbor. Stay on this slide until we reveal.
Prior odds of innocence \(O(I)=1000\). Bayes factor \(10^{-4}\), so posterior odds \(O(I\mid E)=0.1\). Then \(P(I\mid E)=0.1/1.1\approx 0.091\), hence \(P(G\mid E)\approx 0.91\).
The prosecutor reported \(1-p=0.9999\).
That is \(1-P(\text{match}\mid\text{innocent})\), not \(P(\text{guilty}\mid\text{match})\).
Expected matches among the other 1,000 people: \(1000\times 10^{-4}=0.1\).
That 0.1 is why \(P(I\mid E)=0.1/1.1\), not one half. Evidence, not a conviction.
The O.J. Simpson trial was possibly the trial of the century
The murder of his wife Nicole Brown Simpson, and a friend, Ron Goldman, in June 1994 and the trial dominated the TV networks
DNA evidence and probability: \(p( E| G)\)
Bayes Theorem: \(p( G | E )\)
Prosecutor’s Fallacy: \(p( G|E ) \neq p(E|G)\)
Odds ratio \[ \frac{ p( I|E) }{ p ( G | E ) } = \frac{ p( E|I )}{ p( E|G) } \frac{ p(I) }{p(G ) } \] Prior odds conditioned on background information.
Suppose that you are a juror in a murder case of a husband who is accused of killing his wife.
The husband is known is have battered her in the past.
Consider the three events:
\(G\) “husband murders wife in a given year”
\(M\) “wife is murdered in a given year”
\(B\) “husband is known to batter his wife”
In 1994, 5000 women were murdered, 1500 by their husband
Given a population of 100 million women at the time \[ p( M | I ) = \frac{ 3500 }{ 10^8 } \approx \frac{1}{30,000} . \] We’ll also need \(p( M | I , B ) = p( M | I )\)
What’s the “match probability” for a rare event?
Bayes theorem in Odds \[ \frac{p(G|M,B)}{p(I|M,B)} = \frac{p(M|G,B)}{p(M|I,B)} \frac{p(G|B)}{p(I|B)} \]
By assumption,
\[ \frac{p(G|B)}{p(I|B)} = \frac{1}{999} \]
Therefore, \[ \frac{p(G|M,B)}{p(I|M,B)} \approx 30 \; \text{and} \; p(G|M,B) = \frac{30}{31} \approx 97\% \] More than a 50/50 chance that your spouse murdered you!
The defense stated to the press: in any given year
“Fewer than 1 in 2000 of batterers go on to murder their wives”.
Now estimate \(p( M | \bar{G} , B ) = p( M| \bar{G} ) = \frac{1}{20,000}\) (a round figure for murders not by the husband; the previous slide used \(1/30,000\)).
The posterior odds of guilt are then prior odds times the Bayes factor \(p(M\mid G,B)/p(M\mid \bar G,B)=1/(1/20,000)\):
\[ \frac{ p( G | M , B ) }{ p( \bar{G} | M , B ) } = \frac{1}{999} \times 20{,}000 \approx 20 \] which implies posterior probabilities
\[ p( \bar{G} | M , B ) = \frac{1}{1+20} \; \text{and} \; p( G | M , B ) = \frac{20}{21} \] Hence its over 95% chance that O.J. is guilty based on this information!
Defense intended this information to exonerate O.J.
“Witness” 80 % certain saw a “checker” \(C\) taxi in the accident.
What’s your \(P ( C | E )\) ?
Need \(P ( C )\). Say \(P( C ) = 0.2\) and \(P( E | C) = 0.8\).
Then your posterior is
\[ P ( C | E ) = \frac{0.8 \cdot 0.2}{ 0.8 \cdot 0.2 + 0.2 \cdot 0.8 } = 0.5 \]
Therefore \(O ( C ) = 1\) a 50/50 bet.
Most people don’t update quickly enough in light of new data.
Ward Edwards, 1960s. When you have a small sample, Bayes still updates.
Likelihood ratio, binomial coefficients cancel: \[ \frac{0.7^3\cdot 0.3}{0.3^3\cdot 0.7} = \frac{0.7^2}{0.3^2} \approx 5.44 \] Equal priors, so \[ P(\text{70\%}\mid \text{data}) = \frac{5.44}{1+5.44} \approx 0.845 \]
Three wins in four games is not “pretty sure.” It is 85%, and most people stop well short of that.
The following problem is known as the “exchange paradox”.
You know that \(y = \frac{1}{2} x\) or \(y = 2 x\). You are thinking about whether you should switch your opened envelope for the unopened envelope of your friend. It is tempting to do an expected value calculation as follows \[ E( y) = \frac{1}{2} \cdot \frac{1}{2} x + \frac{1}{2} \cdot 2 x = \frac{5}{4} x > x \] Therefore, it looks as if you should switch no matter what value of \(x\) you see. A consequence of this, following the logic of backwards induction, that even if you didn’t open your envelope that you would want to switch!
Where’s the flaw in this argument? Use Bayes rule to update the probabilities of which envelope your opponent has! Assume \(p(m)\) of dollars to be placed in the envelope by the swami.
Such an assumption then allows us to calculate an odds ratio \[ \frac{ p \left ( y = \frac{1}{2} x | x \right ) }{ p \left ( y = 2 x | x \right ) } \] concerning the likelihood of which envelope your opponent has.
Then, the expected value is given by
\[ E(y) = p \left ( y = \frac{1}{2} x \; \vert \; x \right ) \cdot \frac{1}{2} x + p \left ( y = 2 x | x \right ) \cdot 2 x \] and the condition \(E( y) > x\) becomes a decision rule.
Three prisoners \(A , B , C\).
Each believe are equally likely to be set free.
Prisoner \(A\) goes to the warden \(W\) and asks if s/he is getting axed.
The Warden can’t tell \(A\) anything about him.
He provides the new information: \(WB\) = “\(B\) is to be executed”
Uniform Prior Probabilities: \[ \begin{array}{c|ccc} Prior & A & B & C \\\hline P ( \text{Pardon} ) & 0.33 & 0.33 & 0.33 \end{array} \]
Posterior: Compute \(P ( A | WB )\)?
What happens if \(C\) overhears the conversation?
Compute \(P ( C | WB )\)?
Named after the host of the long-running TV show, Let’s make a Deal.
There is a prize (a car, say) behind one of the doors and something worthless behind the other two doors: two goats.
The game is as follows:
You pick a door.
Monty then opens one of the other two doors, revealing a goat.
You have the choice of switching doors.
Is it advantageous to switch?
Assume you pick door \(A\) at random. Then \(P(A) = ( 1 /3 )\).
You need to figure out \(P( A | MB )\) after Monte reveals \(B\) is a goat.
Sheldon Bayes
\[P(H \mid D)=\frac{P(H)\,P(D\mid H)}{P(D)}\]
Bayes’s rule: prior belief + facts = revised belief.
Two errors: An infected person may test negative, a well person tests positive.
Sensitivity (or power) \(=\) true positive rate (or recall) % sick people who are correctly identified \(P(T \mid D)\).
In a perfect world, we’d like \(P(\bar{T} \mid D) \approx 0\)
Specificity \(=\) true negative rate % of negatives correctly identified as such \(P(\bar{T} \mid \bar{D})\).
We want the probability: \(P(D \mid T)\)
We can use accuracy rate: \[ \text{accuracy} = \frac{\text{Number of Correct answers}}{n} \]
or its dual, error rate \[ \text{error rate} = 1 - \text{accuracy} \]
You remember, we have two types of errors. We can use confusion matrix to quantify those
| Predicted: YES | Predicted: NO | |
|---|---|---|
| Actual: YES | TPR | FNR |
| Actual: NO | FPR | TNR |
True positive rate (TPR) is sensitivity. True negative rate (TNR) is specificity. False positive rate is \(FPR = 1 - \text{specificity}\), not specificity.
Your company will test-market a new product. After a positive, neutral, or negative reaction, what are the probabilities of high and low sales?
Netflix Bayes and AI
Step 1: Set-up your notation. Let \[H = \text{high sales} \quad L = \text{low sales}\] \[\text{Pos} = \text{positive} \quad \text{Neu = Neutral} \quad \text{Neg} = \text{Negative}\]
Step 2: List the known conditional probabilities For the marketing test we have \[\begin{align*} P(\text{Pos} \mid H) &= 0.70, P(\text{Neu} \mid H)=0.25, P(\text{Neg} \mid H) = 0.05 \\ P(\text{Pos} \mid L) &= 0.15, P(\text{Neu} \mid L)=0.35, P(\text{Neg} \mid L) = 0.50 \end{align*}\]
Finally, the base rates are \(P(H) = 0.08\) and \(P(L) = 0.92\)
Step 3: Describe the posterior probabilities that are required: \[P(H \mid \text{Pos})\]
The probability of high sales given a positive marketing test. Compute the probability of a positive test \[\begin{align*} P(\text{Pos}) &= P(\text{Pos} \mid H)P(H) +P(\text{Pos} \mid L)P(L) \\ &= 0.70 \times 0.08 + 0.15 \times 0.92 = 0.194 \end{align*}\]
Now use Bayes Rule \[\begin{align*} P(H \mid \text{Pos}) &= \frac{P(\text{Pos} \mid H)P(H)}{P(\text{Pos})} \\ &= \frac{0.70 \times 0.08}{0.194} = 0.288 \end{align*}\]
Hence 28.8% you’ll have high sales in the market.
We should interpret this relative to our initial probability of only \(8\)%.
Large jar containing \(1024\) fair coins and one two-headed coin.
\(\frac{1}{1025}\) probability of initially picking the two headed coin. \(\frac{1}{1024}\) chance of getting \(10\) heads in a row from a fair coin Therefore, it’s a \(50/50\) bet.
Let \(E\) be the event that you get \(10\) Heads in a row \[P(\text{two headed} \mid E) = \frac{P(E \mid \text{two headed})P(\text{two headed})}{P(E \mid \text{fair})P(\text{fair}) + P(E \mid \text{two headed})P(\text{two headed})}\]
Therefore, the posterior probability \[P(\text{two headed} \mid E) = \frac{1 \times \frac{1}{1025}}{\frac{1}{1024} \times \frac{1024}{1025} + 1 \times \frac{1}{1025}} = 0.50\]
We can use the telescoping property of conditional probabilities to write the joint probability distribution as a product of conditional probabilities. This is the essence of the chain rule of probability. It is given by \[ p(x_1, x_2, \ldots, x_n) = p(x_1)p(x_2 \mid x_1)p(x_3 \mid x_1, x_2) \ldots p(x_n \mid x_1, x_2, \ldots, x_{n-1}). \]
right hand side can be simplified if some of the variables are conditionally independent
Input \(X\) and label \(Y\):
\(X:\) the image \(Y:\) the label, “cat” or not
Silicon Valley: Season 4: Not Hotdog
What’s our best decision?
Pick \(\hat{y}\) as the most likely category given that \(X=x\), namely \[\hat{y} = \arg \max_y \; p(Y= y \mid X = x)\]
I need the probability table \(P(X=x, Y=y)\) and marginal \(P(X=x)\).
Use of the Bayes rule allows us to build our first predictive model, called Naive Bayes classifier.
A fruit may be considered an apple if it is:
Each feature contributes independently to the probability:
| Fruit | Long | Sweet | Yellow | Total |
|---|---|---|---|---|
| Banana | 400 | 350 | 450 | 500 |
| Orange | 0 | 150 | 300 | 300 |
| Other | 100 | 150 | 50 | 200 |
| Total | 500 | 650 | 800 | 1000 |
Bananas (500 total):
Oranges (300 total):
Other (200 total):
Given evidence \(E\) (Long, Sweet, Yellow), calculate probability for each class:
Banana: \[P(B \mid E) = \frac{0.8 \times 0.7 \times 0.9 \times 0.5}{P(E)} = \frac{0.252}{P(E)}\]
Orange: \[P(O \mid E) = 0\] (since P(Long|Orange) = 0)
Other Fruit: \[P(F \mid E) = \frac{0.5 \times 0.75 \times 0.25 \times 0.2}{P(E)} = \frac{0.01875}{P(E)}\]
Result: Long, Sweet, Yellow fruit is classified as a Banana
The original spam filtering algorithm was based on Naive Bayes.
Key Assumptions:
For a new email with words \(\{w_{e1}, w_{e2}, \ldots, w_{ek}\}\):
\[P(\text{spam} \mid \text{email}) = \frac{P(\text{email} \mid \text{spam}) \times P(\text{spam})}{P(\text{email})}\]
Where: \[P(\text{email} \mid \text{spam}) = P(w_{e1} \mid \text{spam}) \times P(w_{e2} \mid \text{spam}) \times \ldots \times P(w_{ek} \mid \text{spam})\]
The “naive” assumption:
Despite limitations:
While Naive Bayes has limitations, it paved the way for more sophisticated models:
But Naive Bayes remains valuable for:
When two nodes are connected they are not independent.
Line Structure
\[ p(b\mid c,a) = p(b\mid c),~ p(a,b,c) = p(a)p(c\mid a)p(b\mid c) \]
\(a\) and \(b\) connected through \(c\). Thus, \(a\) can influence \(b\). However, once \(c\) is known, \(a\) and \(b\) are independent.
Lambda Structure
\[ p(a\mid b,c) = p(a\mid c), ~ p(a,b,c) = p(a\mid c)p(b\mid c)p(c) \]
\(a\) can influence \(b\) through \(c\), but once \(c\) is known, \(a\) and \(b\) are independent.
V-structure
\[ p(a\mid b) = p(a),~ p(a,b,c) = p(c\mid a,b)p(a)p(b) \]
\(a\) and \(b\) are independent, but once \(c\) is known, \(a\) and \(b\) are not independent. You can formally derive these independencies from the graph by comparing \(p(a,b\mid c)\) and \(p(a\mid c)p(b\mid c)\).
\(b\) = burglary, \(e\) = earthquake, \(a\) = alarm, and \(r\) = radio message about small earthquake.
The joint distribution is then given by \[ p(b,e,a,r) = p(r \mid a,b,e)p(a \mid b,e)p(b\mid e)p(e). \] Since we know the causal relations, we can simplify this expression \[ p(b,e,a,r) = p(r \mid e)p(a \mid b,e)p(b)p(e). \]
| \(p(a=1 \mid b,e)\) | b | e |
|---|---|---|
| 0 | 0 | 0 |
| 0.1 | 0 | 1 |
| 1 | 1 | 0 |
| 1 | 1 | 1 |
\[ p(a=1 \mid b,e) + p(a=0 \mid b,e) = 1. \] Also know \(p(r=1 \mid e=1) = 0.5\) and \(p(r=1 \mid e=0) = 0\), \(p(b) = 2\cdot10^{-4}\) and \(p(e) = 10^{-2}\) (historical data)
Graph allowed us to have a more compact representation of the joint probability distribution. The original naive representations requires specifying \(2^4\) parameters.
\[ p(b \mid a) = \dfrac{p(a \mid b)p(b)}{p(a)},\qquad p(a) = p(a=1 \mid b=1)p(b=1) + p(a=1 \mid b=0)p(b=0). \] We have everything but \(p(a \mid b)\). This is obtained by marginalizing \(p(a=1 \mid b,e)\), to yield \[ p(a \mid b) = p(a \mid b,e=1)p(e=1) + p(a \mid b,e=0)p(e=0). \] We can calculate \[ p(a=1 \mid b=1) = 1, ~p(a=1 \mid b=0) = 0.1*10^{-2} + 0 = 10^{-3}. \] This leads to \(p(b \mid a) = 2\cdot10^{-4}/(2\cdot10^{-4} + 10^{-3}(1-2\cdot10^{-4})) = 1/6\).
Figure 3: Relationship between the prior and posterior
\[ p(b=1 \mid a=1,r=1) = \dfrac{p(a,r \mid b)p(b)}{p(a,r)} \] and \[ p(b=1 \mid a=1, r=1) = \dfrac{\sum_e p(b=1,e,a=1,r=1)}{\sum_b\sum_ep(b,e,a=1,r=1)} \] \[ =\dfrac{\sum_ep(r=1 \mid e)p(a=1 \mid b=1,e)p(b=1)p(e)}{\sum_b\sum_ep(r=1 \mid e)p(a=1 \mid b,e)p(b)p(e)} \] which is \(\approx 2\%\) in our case. This effect is called explaining away, namely when new information explains some previously known fact.
Translate a sentence. Hear a wake word. Stay in the lane. Pick the next show.
None of those is certain. Each is the question you have been answering all night: given what I just saw, what is likely?
That is Bayes. Next: will this subscriber like Saving Private Ryan?
Will a subscriber like Saving Private Ryan, given that he or she liked the HBO series Band of Brothers?
Both are epic dramas about the Normandy invasion and its aftermath.
100 people in your database, and every one of them has seen both films.
Their viewing histories come in the form of a big “ratings matrix”.
| Liked Band of Brothers | Didn’t like it | |
|---|---|---|
| Liked Saving Private Ryan | 56 subscribers | 6 subscribers |
| Didn’t like it | 14 subscribers | 24 subscribers |
\[P(\text{likes Saving Private Ryan} \mid \text{likes Band of Brothers})=\frac{56}{56+14}=80\%\]
But real problem is much more complicated:
The solution to all three issues is careful modeling.
The fundamental equation is: \[\text{Predicted Rating} =\text{Overall Average} + \text{Film Offset} + \text{User Offset} + \text{User-Film Interaction}\]
These three terms provide a baseline for a given user/film pair:
The leftover term, user-film interaction, is not a one-off. Ratings of similar shows move together because they share a hidden feature of the person.
Bernoulli Trials: A sequence of repeated experiments are Bernoulli trials if:
If \(X\) is the number of successes it is a Binomial Random Variable.
Patriots won 19 out of 25 coin tosses in 2014-15 season. What is the probability of that happening?
\[\Pr(Y=19) = {25 \choose 19} 0.5^{25} = 177{,}100 \times 0.5^{25} = 0.005\]
Rare under a fair toss. Not a proof they cheated.
We calculate probabilities using: \[P(X=x) = {n \choose x} p^x(1-p)^{n-x}\] \({n \choose x}\) counts the number of ways of getting \(x\) successes in \(n\) trials.
The formula for \(n \choose x\) is \[{n \choose x} = \frac{n!}{x!(n-x)!}\] where \(n!=n\times(n-1)\times(n-2)\times...\times 2 \times 1\).
Binomial Mass Function
In R: dbinom(z, n, p) and rbinom(1000, n, p)
\(X\sim\mathrm{Binomial}(n,p)\)
A fair coin is the noisiest Bernoulli. At \(p=0\) or \(1\), variance is zero: you already know.
For the Patriots, \(n=25\), \(p=\tfrac12\): \(E=12.5\), \(Var=6.25\).
Laptop and AI are allowed. Solo first. Then compare with a neighbor. Stay on this slide until we reveal.
EPL Odds
We have a historical set of data on scores
| home team | results | visit team | |
|---|---|---|---|
| Chelsea | \(2\) | \(1\) | West Ham |
| Chelsea | \(5\) | \(1\) | Sunderland |
| Watford | \(1\) | \(2\) | Chelsea |
| Chelsea | \(3\) | \(0\) | Burnley |
| \(\dots\) |
Tomorrow Manchester United (MU) is playing Hall U. I want to place a bet.
How can I predict the outcome of this game?
The Poisson distribution counts the occurrence of events Given the rate \(\lambda\) we calculate probabilities as follows
\[P(X = x) = \frac{e^{-\lambda} \lambda^x}{x!} \quad \text{where } x=0,1,2,3, \ldots\]
The Poisson Mean and Variance are:
| Poisson Distribution | Parameters |
|---|---|
| Expected value | \(\mu = E(X) = \lambda\) |
| Variance | \(\sigma^2 = Var(X) = \lambda\) |
\(\lambda\) is the rate of occurrence of an event.
Laptop and AI are allowed. Solo first. Then compare with a neighbor. Stay on this slide until we reveal.
For each, name Binomial or Poisson. Give the parameters if you can. One sentence on why.
Binomial is a fixed number of independent yes/no trials. Poisson is a count in a window, with a rate and no \(n\).
I can build a model assuming goals follow Poisson distribution.
I calculate \(\lambda\) by taking an average.
(a) MU against
(b) MU for
Our Poisson model fits the empirical data!!
Calculate Odds for the possible scores in a match?
\[0-0, \; 1-0, \; 0-1, \; 1-1, \; 2-0, \ldots\]
Let
\(X=\) Goals scored by Hall U
\(Y=\) Goals scored by MU
What’s the odds of a MU winning? \(P(X < Y)\) Odds of a draw? \(P(X = Y)\)
Each team gets an “attack” strength and “defence” weakness rating Adjust home and away average goal estimates
EPL Table
ManU (away). League away average \(1.20\) from epl.csv. Prediction: \(1.20 \times 1.46 \times 1.37 = 2.41\)
Average \(\times\) Attack strength \(\times\) Defense weakness
Hull (home). League home average \(1.60\). Prediction: \(1.60 \times 0.85 \times 0.52 = 0.71\).
The two league averages are different. Using one number for both would erase home advantage, which is the effect this model is built to capture.
Simulation (\(n=100\))
| Team | Expected Goals | 0 | 1 | 2 | 3 | 4 | 5 | \(\ge 6\) |
|---|---|---|---|---|---|---|---|---|
| Man U | 2.41 | 11 | 22 | 27 | 17 | 13 | 5 | 5 |
| Hull City | 0.71 | 45 | 34 | 16 | 3 | 2 | 0 | 0 |
A model is only as good as its predictions
Suppose we are trying to predict tomorrow’s return on the S&P500…
There’s a number of questions that come to mind
They are continuous (as opposed to discrete) random variables
There are infinitely many normals: every mean, every variance. They are all the same bell, just shifted and stretched. We keep one copy.
pnorm, qnorm, rnorm(1000, 0, 1).Our probability model is written \(X \sim N(\mu,\sigma^2)\) \(\mu\) is the mean, \(\sigma^2\) is the variance
\(95\)% probability \(X\) is inside \(\mu \pm 1.96 \sigma\).
By changing the mean parameter \(\mu\), we change the center of the bell curve
Normal Distribution - Mean
By changing the variance parameter \(\sigma^2\), we change the “fatness” of the bell curve
Normal Distribution - Variance
Chicago Wind Speed (2007-2014) data on a log scale seem to be well described by the Normal distribution
Normal Distribution - Wind Data
pnorm and qnormWe can find probabilities and quantiles in R. Here are the important values
qnorm is the inverse of pnorm. Simulation rnorm. N=1000, x=rnorm(N,0,1), p=sum(x<1.96)/N
Here are two useful facts: If \(X \sim \text{N}(\mu, \sigma^2)\), then
\[\begin{align*} P(\mu - 2.58 \sigma < X < \mu + 2.58 \sigma) =& 0.99 \\ P(\mu - 1.96 \sigma < X < \mu + 1.96 \sigma) =& 0.95 \end{align*}\]
Normal Distribution Tails
Examples of upper and lower tail areas. The lower tail area of \(0.1\) is at \(z = -1.28\). The upper tail area of \(0.05\) is at \(z=1.64\)
How extreme was the 1987 crash of \(-21.76\)%?
Prior to the October, 1987 crash SP500 monthly returns were \(1.2\)% with a risk/volatility of \(4.3\)% \[X \sim N(0.012, 0.043^2)\] Standardize: \[Z =\frac{X-\mu}{\sigma} = \frac{X - 0.012}{0.043} \sim N(0,1)\]
Calculate the observed \(Z\): \[Z = \frac{-0.2176 - 0.012}{0.043} = -5.34\] That’s a \(5\)-sigma event!
We assumed returns follow normal distribution. Using an inaccurate model can lead to inaccurate results.
S&P 500 Returns vs Normal
A real estate firm offers a free trip. Of those who accept, 5% buy a property. If the firm brings \(n=1000\) people, what is \(P(X \ge 60)\) for \(X\sim\mathrm{Binomial}(1000, 0.05)\)?
Mean \(\mu=np=50\), \(\sigma=\sqrt{np(1-p)}=\sqrt{47.5}=6.89\). Continuity correction: \[Z=\frac{59.5-50}{6.89}=1.38, \qquad P(Z\ge 1.38)\approx 0.084\]
In R the exact value is a one-liner, and the approximation is there to be checked, not to replace it: