07: random variables ii - stanford...
TRANSCRIPT
07: Random Variables IILisa Yan
April 22, 2020
1
Binomial RV
2
07d_binomial
Lisa Yan, CS109, 2020
Consider an experiment: ๐ independent trials of Ber(๐) random variables.
def A Binomial random variable ๐ is the number of successes in ๐ trials.
Examples:โข # heads in n coin flips
โข # of 1โs in randomly generated length n bit string
โข # of disk drives crashed in 1000 computer cluster(assuming disks crash independently)
Binomial Random Variable
3
๐ = 0, 1,โฆ , ๐:
๐ ๐ = ๐ = ๐ ๐ =๐๐
๐๐ 1 โ ๐ ๐โ๐๐~Bin(๐, ๐)
Support: {0,1,โฆ , ๐}
PMF
๐ธ ๐ = ๐๐Var ๐ = ๐๐(1 โ ๐)Variance
Expectation
Lisa Yan, CS109, 2020 4
Lisa Yan, CS109, 2020
Reiterating notation
The parameters of a Binomial random variable:
โข ๐: number of independent trials
โข ๐: probability of success on each trial
5
1. The random
variable
2. is distributed
as a3. Binomial 4. with parameters
๐ ~ Bin(๐, ๐)
Lisa Yan, CS109, 2020
Reiterating notation
If ๐ is a binomial with parameters ๐ and ๐, the PMF of ๐ is
6
๐ ~ Bin(๐, ๐)
๐ ๐ = ๐ =๐๐
๐๐ 1 โ ๐ ๐โ๐
Probability Mass Function for a BinomialProbability that ๐takes on the value ๐
Lisa Yan, CS109, 2020
Three coin flips
Three fair (โheadsโ with ๐ = 0.5) coins are flipped.
โข ๐ is number of heads
โข ๐~Bin 3, 0.5
Compute the following event probabilities:
7
๐~Bin(๐, ๐) ๐ ๐ =๐๐
๐๐ 1 โ ๐ ๐โ๐
๐ ๐ = 0
๐ ๐ = 1
๐ ๐ = 2
๐ ๐ = 3
๐ ๐ = 7
P(event)๐ค
Lisa Yan, CS109, 2020
Three coin flips
Three fair (โheadsโ with ๐ = 0.5) coins are flipped.
โข ๐ is number of heads
โข ๐~Bin 3, 0.5
Compute the following event probabilities:
8
๐~Bin(๐, ๐) ๐ ๐ =๐๐
๐๐ 1 โ ๐ ๐โ๐
๐ ๐ = 0 = ๐ 0 =30
๐0 1 โ ๐ 3 =1
8
๐ ๐ = 1
๐ ๐ = 2
๐ ๐ = 3
๐ ๐ = 7
= ๐ 1 =31
๐1 1 โ ๐ 2 =3
8
= ๐ 2 =32
๐2 1 โ ๐ 1 =3
8
= ๐ 3 =33
๐3 1 โ ๐ 0 =1
8
= ๐ 7 = 0
P(event) PMF
Extra math note:
By Binomial Theorem,
we can prove
ฯ๐=0๐ ๐ ๐ = ๐ = 1
Lisa Yan, CS109, 2020
Consider an experiment: ๐ independent trials of Ber(๐) random variables.
def A Binomial random variable ๐ is the number of successes in ๐ trials.
Examples:โข # heads in n coin flips
โข # of 1โs in randomly generated length n bit string
โข # of disk drives crashed in 1000 computer cluster(assuming disks crash independently)
Binomial Random Variable
9
๐~Bin(๐, ๐)
Range: {0,1,โฆ , ๐} Variance
Expectation
PMF
๐ธ ๐ = ๐๐Var ๐ = ๐๐(1 โ ๐)
๐ = 0, 1,โฆ , ๐:
๐ ๐ = ๐ = ๐ ๐ =๐๐
๐๐ 1 โ ๐ ๐โ๐
Lisa Yan, CS109, 2020
Ber ๐ = Bin(1, ๐)
Binomial RV is sum of Bernoulli RVs
Bernoulli
โข ๐~Ber(๐)
Binomial
โข ๐~Bin ๐, ๐
โข The sum of ๐ independent Bernoulli RVs
10
๐ =
๐=1
๐
๐๐ , ๐๐ ~Ber(๐)
+
+
+
Lisa Yan, CS109, 2020
Consider an experiment: ๐ independent trials of Ber(๐) random variables.
def A Binomial random variable ๐ is the number of successes in ๐ trials.
Examples:โข # heads in n coin flips
โข # of 1โs in randomly generated length n bit string
โข # of disk drives crashed in 1000 computer cluster(assuming disks crash independently)
Binomial Random Variable
11
๐~Bin(๐, ๐)
Range: {0,1,โฆ , ๐}
๐ธ ๐ = ๐๐Var ๐ = ๐๐(1 โ ๐)Variance
Expectation
PMF ๐ = 0, 1,โฆ , ๐:
๐ ๐ = ๐ = ๐ ๐ =๐๐
๐๐ 1 โ ๐ ๐โ๐
Proof:
Lisa Yan, CS109, 2020
Consider an experiment: ๐ independent trials of Ber(๐) random variables.
def A Binomial random variable ๐ is the number of successes in ๐ trials.
Examples:โข # heads in n coin flips
โข # of 1โs in randomly generated length n bit string
โข # of disk drives crashed in 1000 computer cluster(assuming disks crash independently)
Binomial Random Variable
12
๐~Bin(๐, ๐)
Range: {0,1,โฆ , ๐}
PMF
๐ธ ๐ = ๐๐Var ๐ = ๐๐(1 โ ๐)
Weโll prove
this later in
the course
Variance
Expectation
๐ = 0, 1,โฆ , ๐:
๐ ๐ = ๐ = ๐ ๐ =๐๐
๐๐ 1 โ ๐ ๐โ๐
Lisa Yan, CS109, 2020
No, give me the variance proof right now
13
proofwiki.org
Poisson
14
08a_poisson
Lisa Yan, CS109, 2020
Before we start
The natural exponent ๐:
https://en.wikipedia.org/wiki/E_(mathematical_constant)
15
lim๐โโ
1 โ๐
๐
๐
= ๐โ๐
Jacob Bernoulli
while studying
compound interest
in 1683
Lisa Yan, CS109, 2020
Algorithmic ride sharing
16
๐โโ๏ธ
๐โโ๏ธ
๐โโ๏ธ
๐โโ๏ธ๐โโ๏ธ
Probability of ๐ requests from this area in the next 1 minute?
On average, ๐ = 5 requests per minuteSuppose we know:
Lisa Yan, CS109, 2020
Algorithmic ride sharing, approximately
At each second:โข Independent trial
โข You get a request (1) or you donโt (0).
Let ๐ = # of requests in minute.
๐ธ ๐ = ๐ = 5
17
Probability of ๐ requests from this area in the next 1 minute?
On average, ๐ = 5 requests per minute
0 0 1 0 1 โฆ 0 0 0 0 1
1 2 3 4 5 60
๐ ~ Bin ๐ = 60, ๐ = 5/60
Break a minute down into 60 seconds:
๐ ๐ = ๐ =60๐
5
60
๐
1 โ5
60
๐โ๐
But what if there are tworequests in the same second?๐ค
Lisa Yan, CS109, 2020
Algorithmic ride sharing, approximately
At each millisecond:โข Independent trial
โข You get a request (1) or you donโt (0).
Let ๐ = # of requests in minute.
๐ธ ๐ = ๐ = 5
18
Probability of ๐ requests from this area in the next 1 minute?
On average, ๐ = 5 requests per minute
Break a minute down into 60,000 milliseconds:
๐ ๐ = ๐ =๐๐
๐
๐
๐
1 โ๐
๐
๐โ๐
โฆ
1 60,000
๐ ~ Bin ๐ = 60000, ๐ = ๐/๐
But what if there are tworequests in the same millisecond?
๐ค
Lisa Yan, CS109, 2020
Algorithmic ride sharing, approximately
For each time bucket:โข Independent trial
โข You get a request (1) or you donโt (0).
Let ๐ = # of requests in minute.
๐ธ ๐ = ๐ = 5
19
Probability of ๐ requests from this area in the next 1 minute?
On average, ๐ = 5 requests per minute
Break a minute down into infinitely small buckets:
๐ ๐ = ๐
= lim๐โโ
๐๐
๐
๐
๐
1 โ๐
๐
๐โ๐
Who wants to see some cool math?
OMG so small
1 โ
๐ ~ Bin ๐, ๐ = ๐/๐
Lisa Yan, CS109, 2020
Binomial in the limit
20
๐ ๐ = ๐
= lim๐โโ
๐๐
๐
๐
๐
1 โ๐
๐
๐โ๐ = lim๐โโ
๐!
๐!(๐ โ ๐)!
๐๐
๐๐
1 โl๐
๐
1 โl๐
๐
lim๐โโ
1 โ๐
๐
๐
= ๐โ๐
= lim๐โโ
๐!
๐๐(๐ โ ๐)!
๐๐
๐!
1 โl๐
๐
1 โl๐
๐
= lim๐โโ
๐!
๐๐(๐ โ ๐)!
๐๐
๐!
๐โ๐
1 โl๐
๐
= lim๐โโ
๐ ๐ โ 1 โฏ ๐ โ ๐ + 1
๐๐๐ โ ๐ !
๐ โ ๐ !
๐๐
๐!
๐โ๐
1 โl๐
๐
= lim๐โโ
๐๐
๐๐๐๐
๐!
๐โ๐
1=๐๐
๐!๐โ๐
Lisa Yan, CS109, 2020
Algorithmic ride sharing
21
๐โโ๏ธ
๐โโ๏ธ
๐โโ๏ธ
๐โโ๏ธ๐โโ๏ธ
Probability of ๐ requests from this area in the next 1 minute?
On average, ๐ = 5 requests per minute
๐ ๐ = ๐ =๐๐
๐!๐โ๐
Lisa Yan, CS109, 2020
Simeon-Denis Poisson
French mathematician (1781 โ 1840)
โข Published his first paper at age 18
โข Professor at age 21
โข Published over 300 papers
โLife is only good for two things: doing mathematics and teaching it.โ
22
Lisa Yan, CS109, 2020
Consider an experiment that lasts a fixed interval of time.
def A Poisson random variable ๐ is the number of successes over the experiment duration.
Examples:โข # earthquakes per year
โข # server hits per second
โข # of emails per day
Yes, expectation == variance
for Poisson RV! More later.
Poisson Random Variable
23
๐ ๐ = ๐ = ๐โ๐๐๐
๐!๐~Poi(๐)
Support: {0,1, 2, โฆ }
PMF
๐ธ ๐ = ๐Var ๐ = ๐Variance
Expectation
Lisa Yan, CS109, 2020
Earthquakes
There are an average of 2.79 major earthquakes in the world each year.
What is the probability of 3 major earthquakes happening next year?
24
๐ ๐ = ๐โ๐๐๐
๐!
1. Define RVs
2. Solve
0
0.05
0.1
0.15
0.2
0.25
0.3
0 1 2 3 4 5 6 7 8 9 10
๐(๐
= ๐
)
Number of earthquakes, ๐
๐~Poi(๐)
๐ธ ๐ = ๐
Lisa Yan, CS109, 2020
Are earthquakes really Poissonian?
25
Poisson Paradigm
26
08b_poisson_paradigm
Lisa Yan, CS109, 2020
DNA
27
All the movies, images,
emails and other digital
data from more than
600 smartphones
(10,000 GB) can be
stored in the faint pink
smear of DNA at the end
of this test tube.
What is the probability
that DNA storage stays
uncorrupted?
Lisa Yan, CS109, 2020
DNA
What is the probability that DNA storage stays uncorrupted?โข In DNA (and real networks), we store large strings.โข Let string length be long, e.g., ๐ โ 104
โข Probability of corruption of each base pair is very small, e.g., ๐ = 10โ6
โข Let ๐ = # of corruptions.
What is P(DNA storage is uncorrupted) = ๐ ๐ = 0 ?
28
1. Approach 1:
๐~Bin ๐ = 104, ๐ = 10โ6
๐ ๐ = ๐ =๐๐
๐๐ 1 โ ๐ ๐โ๐
= 104
010โ6โ 0 1 โ 10โ6 104โ0
โ 0.99049829
2. Approach 2:
๐~Poi ๐ = 104 โ 10โ6 = 0.01
๐ ๐ = ๐ = ๐โ๐๐๐
๐!= ๐โ0.01
0.010
0!
= ๐โ0.01
โ 0.99049834
โ ๏ธunwieldy!a good
approximation!
โ
Lisa Yan, CS109, 2020
The Poisson Paradigm, part 1
Poisson approximates Binomial when ๐ is large, ๐ is small, and ๐ = ๐๐ is โmoderate.โ
Different interpretations of โmoderateโ:
โข ๐ > 20 and ๐ < 0.05
โข ๐ > 100 and ๐ < 0.1
Poisson is Binomial in the limit:
โข ๐ = ๐๐, where ๐ โ โ, ๐ โ 0
29
Poisson can approximate Binomial.
0
0.05
0.1
0.15
0.2
0.25
0.3
0 1 2 3 4 5 6 7 8 9 10
๐(๐
= ๐
)
๐ = ๐
Bin(10,0.3)
Bin(100,0.03)
Bin(1000,0.003)
Poi(3)
๐~Poi(๐)
๐ธ ๐ = ๐
๐~Bin(๐, ๐)
๐ธ ๐ = ๐๐
Lisa Yan, CS109, 2020
Consider an experiment that lasts a fixed interval of time.
def A Poisson random variable ๐ is the number of occurrences over the experiment duration.
Examples:โข # earthquakes per year
โข # server hits per second
โข # of emails per day
Time to show intuition for why
expectation == variance!
Poisson Random Variable
30
๐ ๐ = ๐ = ๐โ๐๐๐
๐!๐~Poi(๐)
Support: {0,1, 2, โฆ } Variance
Expectation
PMF
๐ธ ๐ = ๐Var ๐ = ๐
Lisa Yan, CS109, 2020
Properties of Poi(๐) with the Poisson paradigm
Recall the Binomial:
Consider ๐~Poi(๐), where ๐ = ๐๐ (๐ โ โ, ๐ โ 0):
Proof:
๐ธ ๐ = ๐๐ = ๐Var ๐ = ๐๐ 1 โ ๐ โ ๐ 1 โ 0 = ๐
31
๐~Bin(๐, ๐)Variance
Expectation ๐ธ ๐ = ๐๐Var ๐ = ๐๐(1 โ ๐)
Expectation ๐ธ ๐ = ๐Var ๐ = ๐
๐~Poi(๐)Variance
Lisa Yan, CS109, 2020
A Real License Plate Seen at Stanford
No, itโs not mineโฆ but I kind of wish it was.
Lisa Yan, CS109, 2020
Poisson Paradigm, part 2
Poisson can still provide a good approximation of the Binomial,even when assumptions are โmildlyโ violated.
You can apply the Poisson approximation when:
โข โSuccessesโ in trials are not entirely independente.g.: # entries in each bucket in large hash table.
โข Probability of โSuccessโ in each trial varies (slightly),like a small relative change in a very small pe.g.: Average # requests to web server/sec may fluctuate
slightly due to load on network
33
๐
We wonโt explore this too much,
but I want you to know it exists.
Other Discrete RVs
34
08c_other_discrete
Lisa Yan, CS109, 2020
Grid of random variables
35
Number of
successes
Ber(๐)One trial
Several
trials
Interval
of time
Bin(๐, ๐)
Poi(๐) (tomorrow)
One success
Several
successes
Interval of time to
first success
Time until
success
๐ = 1
Focus on understanding how and when to use RVs, not on memorizing PMFs.
Lisa Yan, CS109, 2020
Consider an experiment: independent trials of Ber(๐) random variables.
def A Geometric random variable ๐ is the # of trials until the first success.
Examples:โข Flipping a coin (๐ heads = ๐) until first heads appears
โข Generate bits with ๐ bit = 1 = ๐ until first 1 generated
Geometric RV
36
๐ ๐ = ๐ = 1 โ ๐ ๐โ1๐๐~Geo(๐)
Support: {1, 2, โฆ }
PMF
๐ธ ๐ =1
๐
Var ๐ =1โ๐
๐2Variance
Expectation
Lisa Yan, CS109, 2020
Consider an experiment: independent trials of Ber(๐) random variables.
def A Negative Binomial random variable ๐ is the # of trials until ๐ successes.
Examples:โข Flipping a coin until ๐๐กโ heads appears
โข # of strings to hash into table until bucket 1 has ๐ entries
Negative Binomial RV
37
๐ ๐ = ๐ =๐ โ 1๐ โ 1
1 โ ๐ ๐โ๐๐๐๐~NegBin(๐, ๐)
Support: {๐, ๐ + 1,โฆ }
PMF
๐ธ ๐ =๐
๐
Var ๐ =๐ 1โ๐
๐2Variance
Expectation
(fixed lecture error)
Geo ๐ = NegBin(1, ๐)
Lisa Yan, CS109, 2020
Grid of random variables
38
Number of
successes
Ber(๐)One trial
Several
trials
Interval
of time
Bin(๐, ๐)
Poi(๐)
Geo(๐)
NegBin(๐, ๐)
(tomorrow)
One success
Several
successes
Interval of time to
first success
Time until
success
๐ = 1 ๐ = 1
Lisa Yan, CS109, 2020
Catching Pokemon
Wild Pokemon are captured by throwing Pokeballs at them.
โข Each ball has probability p = 0.1 of capturing the Pokemon.
โข Each ball is an independent trial.
What is the probability that you catch the Pokemon on the 5th try?
39
1. Define events/ RVs & state goal
A. ๐~Bin 5, 0.1B. ๐~Poi 0.5C. ๐~NegBin 5, 0.1D. ๐~NegBin 1, 0.1E. ๐~Geo 0.1F. None/other
2. Solve
๐~some distribution
Want: ๐ ๐ = 5
๐ค
Lisa Yan, CS109, 2020
Wild Pokemon are captured by throwing Pokeballs at them.
โข Each ball has probability p = 0.1 of capturing the Pokemon.
โข Each ball is an independent trial.
What is the probability that you catch the Pokemon on the 5th try?
A. ๐~Bin 5, 0.1B. ๐~Poi 0.5C. ๐~NegBin 5, 0.1D. ๐~NegBin 1, 0.1E. ๐~Geo 0.1F. None/other
Catching Pokemon
40
1. Define events/ RVs & state goal
2. Solve
๐~some distribution
Want: ๐ ๐ = 5
Lisa Yan, CS109, 2020
2. Solve
Catching Pokemon
Wild Pokemon are captured by throwing Pokeballs at them.
โข Each ball has probability p = 0.1 of capturing the Pokemon.
โข Each ball is an independent trial.
What is the probability that you catch the Pokemon on the 5th try?
41
1. Define events/ RVs & state goal
2. Solve
๐~Geo 0.1
Want: ๐ ๐ = 5
๐~Geo(๐) ๐ ๐ = 1 โ ๐ ๐โ1๐
(live)08: Random Variables IIIIOishi Banerjee and Cooper RaterinkAdapted from Lisa YanJuly 8, 2020
42
Lisa Yan, CS109, 2020
Our first common RVs
43
๐ ~ Ber(๐)
๐ ~ Bin(๐, ๐)
1. The random
variable
2. is distributed
as a3. Bernoulli 4. with parameter
Example: Heads in one coin flip,
P(heads) = 0.8 = p
Example: # heads in 40 coin flips,
P(heads) = 0.8 = p
otherwise Identify PMF, or
identify as a function of an
existing random variable
Review
ThinkThe next slide has a matching question to go over by yourself. Weโll go over it together afterwards.
Post any clarifications here!
https://us.edstem.org/courses/667/discussion/84212
Think by yourself: 2 min
44
๐ค(by yourself)
Lisa Yan, CS109, 2020
Visualizing Binomial PMFs
45
0
0.1
0.2
0.3
0 1 2 3 4 5 6 7 8 9 10
0
0.1
0.2
0.3
0 1 2 3 4 5 6 7 8 9 10
๐~Bin(๐, ๐) ๐ ๐ =๐๐
๐๐ 1 โ ๐ ๐โ๐
๐ธ ๐ = ๐๐
C. D.
Match the distribution
to the graph:
1. Bin 10,0.5
2. Bin 10,0.3
3. Bin 10,0.7
4. Bin 5,0.5
0
0.1
0.2
0.3
0 1 2 3 4 5 6 7 8 9 10
0
0.1
0.2
0.3
0 1 2 3 4 5 6 7 8 9 10
A. B.
๐
๐๐=๐
๐
๐๐=๐
๐
๐๐=๐
๐
๐๐=๐
๐ค(by yourself)
Lisa Yan, CS109, 2020
Visualizing Binomial PMFs
46
Match the distribution
to the graph:
1. Bin 10,0.5
2. Bin 10,0.3
3. Bin 10,0.7
4. Bin 5,0.5
0
0.1
0.2
0.3
0 1 2 3 4 5 6 7 8 9 10
0
0.1
0.2
0.3
0 1 2 3 4 5 6 7 8 9 10
C. D.
0
0.1
0.2
0.3
0 1 2 3 4 5 6 7 8 9 10
0
0.1
0.2
0.3
0 1 2 3 4 5 6 7 8 9 10
A. B.
๐
๐๐=๐
๐
๐๐=๐
๐
๐๐=๐
๐
๐๐=๐
๐~Bin(๐, ๐) ๐ ๐ =๐๐
๐๐ 1 โ ๐ ๐โ๐
๐ธ ๐ = ๐๐
Lisa Yan, CS109, 2020
Binomial RV is sum of Bernoulli RVs
Bernoulli
โข ๐~Ber(๐)
Binomial
โข ๐~Bin ๐, ๐
โข The sum of ๐ independent Bernoulli RVs
47
๐ =
๐=1
๐
๐๐ , ๐๐ ~Ber(๐)
+
+
+
Review
Lisa Yan, CS109, 2020
NBA Finals and genetics
48
Think, thenBreakout Rooms
Check out the questions on the next slide. Post any clarifications here!
https://us.edstem.org/courses/667/discussion/84212
By yourself: 2 min
Breakout rooms: 5 min.
49
๐ค
Lisa Yan, CS109, 2020
NBA Finals and genetics
1. The Golden State Warriors are going to play the Toronto Raptors in a7-game series during the 2019 NBA finals.
โข The Warriors have a probability of 58% of winning each game, independently.
โข A team wins the series if they win at least 4 games (we play all 7 games).
What is P(Warriors winning)?
2. Each person has 2 genes per trait (e.g., eye color).โข Child receives 1 gene (equally likely) from each parent
โข Brown is โdominantโ, blue is โrecessiveโ:
โข Child has brown eyes if either (or both) genes are brown
โข Blue eyes only if both genes are blue.
โข Parents each have 1 brown and 1 blue gene.
A family has 4 children. What is P(exactly 3 children with brown eyes)?
50
๐ค
Lisa Yan, CS109, 2020
NBA Finals
The Golden State Warriors are going to play the TorontoRaptors in a 7-game series during the 2019 NBA finals.โข The Warriors have a probability of 58% of
winning each game, independently.
โข A team wins the series if they win at least 4 games(we play all 7 games).
What is P(Warriors winning)?
51
1. Define events/ RVs & state goal
๐: # games Warriors win
๐~Bin(7, 0.58)
Want:
Desired probability? (select all that apply)
A. ๐ ๐ > 4B. ๐ ๐ โฅ 4C. ๐ ๐ > 3D. 1 โ ๐ ๐ โค 3E. 1 โ ๐ ๐ < 3
๐~Bin(๐, ๐) ๐ ๐ =๐๐
๐๐ 1 โ ๐ ๐โ๐
Lisa Yan, CS109, 2020
Desired probability? (select all that apply)
A. ๐ ๐ > 4B. ๐ ๐ โฅ 4C. ๐ ๐ > 3D. 1 โ ๐ ๐ โค 3E. 1 โ ๐ ๐ < 3
NBA Finals
The Golden State Warriors are going to play the TorontoRaptors in a 7-game series during the 2019 NBA finals.โข The Warriors have a probability of 58% of
winning each game, independently.
โข A team wins the series if they win at least 4 games(we play all 7 games).
What is P(Warriors winning)?
52
1. Define events/ RVs & state goal
๐: # games Warriors win
๐~Bin(7, 0.58)
Want:
๐~Bin(๐, ๐) ๐ ๐ =๐๐
๐๐ 1 โ ๐ ๐โ๐
Lisa Yan, CS109, 2020
NBA Finals
The Golden State Warriors are going to play the Toronto Raptors in a 7-game series during the 2019 NBA finals.โข The Warriors have a probability of 58% of
winning each game, independently.
โข A team wins the series if they win at least 4 games(we play all 7 games).
What is P(Warriors winning)?
53
Cool Algebra/Probability Fact: this is identical to the probability
of winning if we define winning = first to win 4 games
1. Define events/ RVs & state goal
2. Solve
๐: # games Warriors win
๐~Bin(7, 0.58)
Want: ๐ ๐ โฅ 4
๐ ๐ โฅ 4 =
๐=4
7
๐ ๐ = ๐ =
๐=4
7
7๐
0.58๐ 0.42 7โ๐
๐~Bin(๐, ๐) ๐ ๐ =๐๐
๐๐ 1 โ ๐ ๐โ๐
Lisa Yan, CS109, 2020
Genetic inheritance
Each person has 2 genes per trait (e.g., eye color).โข Child receives 1 gene (equally likely) from each parent
โข Brown is โdominantโ, blue is โrecessiveโ:
โข Child has brown eyes if either (or both) genes are brown
โข Blue eyes only if both genes are blue.
โข Parents each have 1 brown and 1 blue gene.
A family has 4 children. What is P(exactly 3 children with brown eyes)?
54
๐~Bin(๐, ๐) ๐ ๐ =๐๐
๐๐ 1 โ ๐ ๐โ๐
A. Product of 4 independent events
B. Probability tree
C. Bernoulli, success ๐ = 3 children with brown eyes
D. Binomial, ๐ = 3 trials, success ๐ = brown-eyed child
E. Binomial, ๐ = 4 trials, success ๐ = brown-eyed child
Subset
of ideas:
Lisa Yan, CS109, 2020
Each person has 2 genes per trait (e.g., eye color).โข Child receives 1 gene (equally likely) from each parent
โข Brown is โdominantโ, blue is โrecessiveโ:
โข Child has brown eyes if either (or both) genes are brown
โข Blue eyes only if both genes are blue.
โข Parents each have 1 brown and 1 blue gene.
A family has 4 children. What is P(exactly 3 children with brown eyes)?
55
Genetic inheritance
1. Define events/ RVs & goal
3. Solve
๐: # brown-eyed children,
๐~Bin(4, ๐)๐: ๐ brownโeyed child
Want: ๐ ๐ = 3
2. Identify knownprobabilities
๐~Bin(๐, ๐) ๐ ๐ =๐๐
๐๐ 1 โ ๐ ๐โ๐
Interlude for jokes/announcements
57
Lisa Yan, CS109, 2020
Announcements
58
Midterm Quiz
Time frame: Mon-Tues, July 20-21 5pm-5pm PT
Covers: Up to and including Lecture 11
Info and practice: http://web.stanford.edu/class/archive/cs/cs109/cs109.1208/exams/quizzes.ht
ml
Lisa Yan, CS109, 2020
Interesting probability news
59
https://theconversation.com/p
olly-knows-probability-this-
parrot-can-predict-the-chances-
of-something-happening-
132767
Discrete RVs
60
LIVE
The hardest part of problem-solving is
determining what is a random variable .
Lisa Yan, CS109, 2020
Grid of random variables
61
Number of
successes
Ber(๐)One trial
Several
trials
Interval
of time
Bin(๐, ๐)
Poi(๐)
Geo(๐)
NegBin(๐, ๐)
(today!)
One success
Several
successes
Interval of time to
first success
Time until
success
๐ = 1 ๐ = 1
Review
Lisa Yan, CS109, 2020
Grid of random variables
62
Number of
successes
Ber(๐)One trial
Several
trials
Interval
of time
Bin(๐, ๐)
Poi(๐)
Geo(๐)
NegBin(๐, ๐)
(today!)
One success
Several
successes
Interval of time to
first success
Time until
success
๐ = 1 ๐ = 1
Review
Breakout Rooms
Check out the question on the next slide. Post any clarifications here!
https://us.edstem.org/courses/667/discussion/84212
Breakout rooms: 5 min. Introduce yourself!
63
๐ค
Lisa Yan, CS109, 2020
An RV Tour
How would you model the following?
1. # of snapchats you receive in a day
2. # of children until the first one withbrown eyes (same parents)
3. Whether stock went up or down in a day
4. # of probability problems you try until you get 5 correct (if you are randomly correct)
5. # of years in some decade with at least 6 Atlantic hurricanes
64
Choose from:
A. Ber ๐B. Bin ๐, ๐
C. Poi ๐D. Geo ๐E. NegBin ๐, ๐
๐ค
Lisa Yan, CS109, 2020
An RV Tour
How would you model the following?
1. # of snapchats you receive in a day
2. # of children until the first one withbrown eyes (same parents)
3. Whether stock went up or down in a day
4. # of probability problems you try until you get 5 correct (if you are randomly correct)
5. # of years in some decade with at least 6 Atlantic hurricanes
65
E. NegBin ๐ = 5, ๐
Choose from:
A. Ber ๐B. Bin ๐, ๐
A. Ber ๐ or B. Bin 1, ๐
D. Geo ๐ or E. NegBin 1, ๐
C. Poi ๐
B. Bin ๐ = 10, ๐ , where
๐ = ๐ โฅ 6 hurricanes in a year
calculated from C. Poi ๐
C. Poi ๐D. Geo ๐E. NegBin ๐, ๐
Lisa Yan, CS109, 2020
CS109 Learning Goal: Use new RVs
Letโs say you are learning about servers/networks.
You read about the M/D/1 queue:
โThe service time busy period is distributed as a Borel with parameter๐ = 0.2.โ
Goal: You can recognize terminology and understand experiment setup.
66
๐
Poisson RV
67
LIVE
Lisa Yan, CS109, 2020
Poisson Random Variable
In CS109, a Poisson RV ๐~Poi(๐)most often models
โข # of successes over a fixed interval of time.๐ = ๐ธ[๐], average success/interval
โข Approximation of ๐~Bin(๐, ๐) where ๐ is large and ๐ is small.๐ = ๐ธ ๐ = ๐๐
โข Approximation of Binomial even when successin trials are not entirely independent.
68
๐ ๐ = ๐ = ๐โ๐๐๐
๐!๐~Poi(๐)
Support: {0,1, 2,โฆ }
PMF
๐ธ ๐ = ๐Var ๐ = ๐Variance
Expectation
Review
(explored in problem set 3)
Breakout Rooms The next slide has two questions to go over
in groups.
Post any clarifications here!
https://us.edstem.org/courses/667/discussion/84212
Breakout rooms: 5 mins
69
๐ค
Lisa Yan, CS109, 2020
Web server load
1. Consider requests to a web server in 1 second.โข In the past, server load averages 2 hits/second.
โข Let ๐ = # hits the server receives in a second.
What is ๐ ๐ < 5 ?
2. Can the following BinomialRVs be approximated with Poisson?
70
๐~Poi(๐)๐ ๐ = ๐โ๐
๐๐
๐!๐ธ ๐ = ๐
๐ค
Lisa Yan, CS109, 2020
1. Web server load
Consider requests to a web server in 1 second.โข In the past, server load averages 2 hits/second.
โข Let ๐ = # hits the server receives in a second.
What is ๐ ๐ < 5 ?
71
๐~Poi(๐)๐ ๐ = ๐โ๐
๐๐
๐!
1. Define RVs 2. Solve
๐ธ ๐ = ๐
Lisa Yan, CS109, 2020
2. Can these Binomial RVs be approximated?
72
0
0.05
0.1
0 10 20 30 40 50 60 70 80 90
๐(๐
= ๐
)
Bin(100,0.5)Poi(50)
0
0.1
0.2
0.3
0 10 20 30 40 50 60 70 80 90
๐(๐
= ๐
)
Bin(100,0.04)Poi(4)
0
0.1
0.2
0.3
0 10 20 30 40 50 60 70 80 90
๐(๐
= ๐
) Bin(100,0.96) Poi(4)
โ
โ
โ ๏ธCan approximate
Bin(100,1-0.96)
Poisson approximates Binomial when ๐ is large, ๐ is small, and ๐ = ๐๐ is โmoderate.โ
Different interpretations of โmoderateโ:
โข ๐ > 20 and ๐ < 0.05
โข ๐ > 100 and ๐ < 0.1