Algorithms CSCI 235, Fall 2017 Lecture 10 Probability II
Conditional Probability Conditional probability (having prior knowledge): Probability of A given B = Example: Experiment A with H1 = 1/3, H2 = 1/4, H3 = 1/5 What is the probability of A3 (exactly 2 tails) given A4 (two consecutive flips the same)? A3 = {HTT, THT, TTH} A4 = {HHH, HHT, HTT, THH, TTH, TTT}
Example 2 Ann has 2 children, one of which is a girl. What is the probability that the other child is a boy? (Assume a child is a girl or boy with equal probability) Pr{G} = 1/2 Pr{B} = 1/2
Independence If two events are independent then Probability of A given B = (Knowledge of B does not change the probability of A) Therefore: Definition: Events A and B are independent if
Example of independence Of the four events in experiment A, which are independent? Recall: Event A1: First flip is head = {HHH, HHT, HTH, HTT} Event A2: Second flip is tail = {HTH, HTT, TTH, TTT} Event A3: Exactly 2 tails = {HTT, THT, TTH} Event A4: Two consecutive flips are the same= {HHH, HHT, HTT, THH, TTH, TTT}
Checking for independence 1. Are A1 and A2 independent? Pr{A1}=Pr{HHH} + Pr{HHT} + Pr{HTH} + Pr{HTT} = 1/60 + 1/15 + 1/20 + 1/5 = 20/60 = 1/3 Pr{A2}=Pr{HTH} + Pr{HTT} + Pr{TTH} + Pr{TTT} = 1/20 + 1/5 + 1/10 + 2/5 = 3/4 If A1 and A2 are independent, then = 1/20 + 1/5 = 5/20 = 1/4 Pr{A1}Pr{A2} = (1/3)(3/4) = 1/4 Yes. They are independent. 2. Are A1 and A3 independent? (We will work this out in class)
Discrete Random Variables A discrete random variable maps (assigns) a real number to each element (outcome) of a sample space, S. Example: h(x) = number of heads in outcome x r(x) = length of longest run in outcome x Outcome(x) h(x) r(x) H1H2H3 3 3 H1H2T3 2 2 H1T2H3 2 1 H1T2T3 1 2 T1H2H3 2 2 T1H2T3 1 1 T1T2H3 1 2 T1T2T3 0 3
The Pre-Image The pre-image of a value, v, under a discrete random variable f is defined as: In other words: the pre-image of v under f is the set of all outcomes for which the value of f(x) = v. Example: h-1(1) = {HTT, THT, TTH} r-1(3) = ?
The probability density function The probability density function (PDF) of a discrete random variable is defined as follows: In other words: The probability density function of f for a value, v, is the sum of the probabilities of all the outcomes in the pre-image of v under f. Example: PDF(h) = ? (PDF(h))(0) = Pr{h-1(0)} = Pr{TTT} = ? (PDF(h))(1) = Pr{h-1(1)} = Pr{HTT, THT, TTH}=?
Independence of discrete random variables Discrete random variables f and g are independent if, for all v and w, f-1(v) and g-1(w) are independent. Example: Are h and r independent? Test for v = 0, w = 1: is h-1(0) independent of r-1(1)? h-1(0) = {TTT} r-1(1) = {THT, HTH}
Expected Value The expected value, E(f), of a discrete random variable, f, is a weighted average: Example: What is the expected number of heads in Experiment A? = 0(Pr{h-1(0)} + 1(Pr{h-1(1)} + 2(Pr{h-1(2)} + 3(Pr{h-1(3)} = 13/30 + 2(9/60) + 3/60 = 47/60
Example 2 What is the expected number of flips in Experiment B (flip until heads)? Assume a fair coin. Outcome b H 1 b-1(1) = H TH 2 b-1(2) = TH TTH 3 b-1(3) = TTH ... ... ... Pr{b-1(1)} = Pr{H} = 1/2 Pr{b-1(2)} = Pr{TH} = (1/2)(1/2) = 1/4 Pr{b-1(3)} = Pr{TTH} = (1/2)(1/2)(1/2) = 1/8 Pr{b-1(k)} = (1/2)k E(b) = ?