Bernoulli and Binomial Will Monroe July 1, 217 image: Antoine Taveneaux with materials by Mehran Sahami and Chris Piech
Announcements: Problem Set 2 Due this Wednesday, 7/12, at 12:3pm (before class). (Cell phone location sensing)
Announcements: Midterm Two weeks from tomorrow: Tuesday, July 25, 7:-9:pm Tell me by the end of this week if you have a conflict!
Review: Random variables A random variable takes on values probabilistically. 1 P( X =2)= 36 P( X= x) x
Review: Probability mass function The probability mass function (PMF) of a random variable is a function from values of the variable to probabilities. py (k )=P (Y =k ) P(Y =k ) k
Review: Cumulative distribution function The cumulative distribution function (CDF) of a random variable is a function giving the probability that the random variable is less than or equal to a value. F Y (k )=P(Y k ) 1.9.8.7.6 P(Y k ).5.4.3.2.1 2 3 4 5 6 7 k 8 9 1 11 12
Review: Expectation The expectation of a random variable is the average value of the variable (weighted by probability). E [ X ]= p( x) x x : p(x)> E[X] = 7 P( X =x) x
Review: Linearity of expectation Adding random variables or constants? Add the expectations. Multiplying by a constant? Multiply the expectation by the constant. E [ax +by +c ]=ae [ X ]+be [Y ]+c X 2X 2X + 4
Review: Variance Variance is the average square of the distance of a variable from the expectation. Variance measures the spread of the variable. 2 Var( X )=E [( X E [ X ]) ] 2 2 =E [ X ] (E [ X ]) E[X] Var(X) (2.42)2 P( X =x) x
Today: Basic distributions Many types of random variables come up repeatedly. Known frequently-occurring distributions lets you do computations without deriving formulas from scratch. variable family parameters X Bin (n, p) We have independent, INTEGER PLURAL NOUN each of which with probability VERB ENDING IN -S. How many of the REAL NUMBER? REPEAT VERB -S REPEAT PLURAL NOUN
Bernoulli random variable An indicator variable (a possibly biased coin flip) obeys a Bernoulli distribution. Bernoulli random variables can be or 1. X Ber ( p) p X (1)= p p X ()=1 p ( elsewhere)
Review: Indicator variable An indicator variable is a Boolean variable, which takes values or 1 corresponding to whether an event takes place. 1 if event A occurs I= [ A ]= otherwise {
Bernoulli: Fact sheet X Ber ( p) probability of success (e.g., heads)
Program crashes Run a program, crashes with prob. p, works with prob. (1 p) X: 1 if program crashes P(X = 1) = p P(X = ) = 1 - p X ~ Ber(p)
Ad revenue Serve an ad, clicked with prob. p, ignored with prob. (1 p) C: 1 if ad is clicked P(C = 1) = p P(C = ) = 1 - p C ~ Ber(p)
Bernoulli: Fact sheet X Ber ( p)? probability of success (heads, ad click,...) PMF: p X (1)= p p X ()=1 p ( elsewhere) expectation: image (right): Gabriela Serrano
Expectation of an indicator variable 1 if event A occurs I = [ A ]= otherwise { E [ I ]=P( A) 1+[1 P( A)] =P ( A )
Bernoulli: Fact sheet X Ber ( p)? probability of success (heads, ad click,...) PMF: expectation: p X (1)= p p X ()=1 p ( elsewhere) E [ X ]= p variance: image (right): Gabriela Serrano
Variance of a Bernoulli RV p X (1)= p p X ()=1 p 2 2 ( elsewhere) E [ X ]= p 1 +(1 p) 2 =p 2 2 Var( X )=E [ X ] (E [ X ]) 2 = p ( p) = p (1 p)
Bernoulli: Fact sheet? X Ber ( p) probability of success (heads, ad click,...) PMF: expectation: variance: p X (1)= p p X ()=1 p ( elsewhere) E [ X ]= p Var( X )= p(1 p) image (right): Gabriela Serrano
Jacob Bernoulli Swiss mathematician (1654-175) Came from a family of competitive mathematicians (!) image (right): The Gazette Review
Jacob Bernoulli Swiss mathematician (1654-175) Came from a family of competitive mathematicians (!) image (right): The Gazette Review
Binomial random variable The number of heads on n (possibly biased) coin flips obeys a binomial distribution. X Bin (n, p) n p k (1 p)n k if k ℕ, k n p X (k)= k otherwise { ()
Binomial: Fact sheet number of trials (flips, program runs,...) X Bin (n, p) probability of success (heads, crash,...)
Program crashes n runs of program, each crashes with prob. p, works with prob. (1 p) H: number of crashes n pk (1 p)n k P(H = k) = k () H ~ Bin(n, p)
Ad revenue n ads served, each clicked with prob. p, ignored with prob. (1 p) H: number of clicks n pk (1 p)n k P(H = k) = k () H ~ Bin(n, p)
Binomial: Fact sheet number of trials (flips, program runs,...) X Bin (n, p) probability of success (heads, crash,...) PMF: n p k (1 p)n k if k ℕ, k n p X (k )= k otherwise { ()
The Galton board n trials failure success X Bin (n,.5) X = final position = number of successes
PMF of Binomial X Bin (1,.5) P( X =k ) k
PMF of Binomial X Bin (1,.3) P( X =k ) k
Break time!
Binomial: Fact sheet number of trials (flips, program runs,...) X Bin (n, p) probability of success (heads, crash,...) PMF: expectation: n p k (1 p)n k if k ℕ, k n p X (k )= k otherwise { ()
Expectation of a binomial n p k (1 p)n k if k ℕ, k n p X (k)= k otherwise { () n E[ X ]= P( X =k ) k k = n k n k n = p (1 p) k k = k n n! k n k = p (1 p) k =1 (k 1)!(n k )! () n = n n 1 p p (1 p) k 1 k =1 n 1 j n 1 j n 1 n 1 =np p (1 p) =( p+1 p) =np j j= ( ) ( ) k 1 n k
Expectation of a binomial X = number of successes Xi = indicator variable for success on i-th trial n X = X i X i Ber ( p) i=1 n E[ X ]=E [ ] Xi i=1
Review: Linearity of expectation Adding random variables or constants? Add the expectations. Multiplying by a constant? Multiply the expectation by the constant. E [ax +by +c ]=ae [ X ]+be [Y ]+c X 2X 2X + 4
Expectation of a binomial X = number of successes Xi = indicator variable for success on i-th trial n X = X i X i Ber ( p) i=1 n E[ X ]=E [ ] n X i = E [ X i ] i=1 i=1 n = p i=1 =np
Binomial: Fact sheet number of trials (flips, program runs,...) X Bin (n, p) probability of success (heads, crash,...) PMF: expectation: variance: n p k (1 p)n k if k ℕ, k n p X (k )= k otherwise { () E [ X ]=np Var( X )=np(1 p) note: Ber ( p)=bin (1, p)
Eye color Parents each have one brown (B) and one blue (b) gene.* Brown is dominant: Bb brown eyes. Parents have 4 children. X: number of children with brown eyes E [ X ]=np=4.75=3 X Bin (4,.75) *Don t get your genetics information from CS 19! Eye color is influenced by more than one gene.
Eye color Parents each have one brown (B) and one blue (b) gene.* Brown is dominant: Bb brown eyes. Parents have 4 children. X: number of children with brown eyes 3 3 3 1 4 P ( X =3)= (.75) (.25) =4 4.422 3 4 X Bin (4,.75) () *Don t get your genetics information from CS 19! Eye color is influenced by more than one gene.
Sending satellite messages Sending a 4-bit message through space. Each bit corrupted (flipped) with probability p =.1. X: number of bits flipped X ~ Bin(4,.1) (bit flip = success. not much of a success!) 4 4 P ( X =)= (.1) (.9) 4 =(.9).656 ()
Hamming codes Message: 1 1 5 6 3 1 1 1 2 1 7 4 1 Send as: 1 1 1 Receive: 1 1 1 1
Hamming codes Message: 1 1 5 6 3 1 1 2 1 7 4 1 Send as: 1 1 1 Receive: 1 1 1 1 Correct to: 1 1 1
Hamming codes Message: 1 1 5 6 3 1 2 1 7 4 1 Send as: 1 1 1 Receive: 1 1
Hamming codes Message: 1 1 5 6 3 1 1 2 1 7 4 1 Send as: 1 1 1 Receive: 1 1 Correct to: 1 1 1
Sending satellite messages Sending a 4-bit message through space. Each bit corrupted (flipped) with probability p =.1. X: number of bits flipped X ~ Bin(4,.1) P ( X 1)=P ( X =)+ P ( X =1) 7 1 7 1 7 7 = (.1) (.9) + (.1) (.9) 1 7 6 =(.9) +7 (.1) (.9).478+.372=.85 () ()