probability
-
dependence and independence
-
e and f are independent
P(E,F) = P(E)P(F)
-
-
conditional probability
-
e and f are not independent
P(E|F) = P(E,F)/P(F) # rewrite as this P(E,F) = P(E|F)P(F) # when e and f are independent P(E|F) = P(E)
-
b
both children are girlsg
the older child is a girlP(B|G) = P(B,G)/P(G) = P(B)/P(G) = 1/2
-
b
both children are gilrsl
at the least one of them is a girlP(B|L) = P(B,L)/P(L) = P(B)/P(L) = 1/3
-
check
def random_kid(): return random.choice(['boy', 'girl']) both_girls = 0 older_girl = 0 either_girl = 0 random.seed(0) for _ in range(10000): younger = random_kid() older = random_kid() if older == 'girl': older_girl += 1 if older == 'girl' and younger == 'girl': both_girls += 1 if older == 'girl' or younger == 'girl': either_girl += 1 print 'p(both | older)', both_girls / older_girl # 0.514 ~ 1/2 print 'p(both | either)', both_girls / either_girl # 0.342 ~ 1/3
-
-
bayes’s theorem
P(E|F) = P(E,F)/P(F) = P(F|E)P(E)/P(F) # given P(F) = P(F,E) + P(F,¬E) # so P(E|F) = P(F|E)P(E)/[P(F|E)P(E)+P(F|¬E)P(¬E)]
continuous distribution
-
probability density function
pdf
-
density function for the uniform distribution
def uniform_pdf(f): return 1 if x >= 0 and x < 1 else 0
-
-
cumulative distribution function
cdf
def uniform_cdf(x): """returns the probability that a uniform random variable is <= x""" # uniform random is never less than 0 if x < 0 return 0 # e.g. P(X <= 0.4) = 0.4 elif x < 1 return x #uniform random is aways less than 1 else: return 1