DS from scratch CH6
2015-09-28 本文已影响20人
mychen
- math.erf是 Error Function,主要和正态分布的CDF有关,正态分布的CDF是个积分,且不能被简化。
- 这种方法叫Binary Search
#通过累计概率来求正态分布分布中的值
def inverse_normal_cdf(p, mu=0, sigma=1, tolerance=0.00001):
"""find approximate inverse using binary search"""
# if not standard, compute standard and rescale
if mu != 0 or sigma != 1:
return mu + sigma * inverse_normal_cdf(p, tolerance=tolerance)
low_z, low_p = -10.0, 0 # normal_cdf(-10) is (very close to) 0
hi_z, hi_p = 10.0, 1 # normal_cdf(10) is (very close to) 1
while hi_z - low_z > tolerance:
mid_z = (low_z + hi_z) / 2 # consider the midpoint
mid_p = normal_cdf(mid_z) # and the cdf's value there
if mid_p < p:
# midpoint is still too low, search above it
low_z, low_p = mid_z, mid_p
elif mid_p > p:
# midpoint is still too high, search below it
hi_z, hi_p = mid_z, mid_p
else:
break
return mid_z
- 伯努利实验是结果只有0和1的实验,1的概率为P
- Binomial是重复N次的Bernoulli Trial
- 二项式分布的std dev是怎么算出来的?