def norm_cdf(x, mu=0, sigma=1):
"""
Parameters
----------
x :
mu : float
distribution's mean
sigma : float
distribution's standard deviation
Returns
-------
float
pdf or cdf value, depending on input flag ``f``
Notes
-----
http://stackoverflow.com/questions/809362/how-to-calculate-cumulative-normal-distribution-in-python
Examples
--------
Compares total absolute error for 100 values
>>> from scipy.stats import norm
>>> sum( [abs(Util.norm_cdf(x) - norm.cdf(x)) for x in range(100)])
3.3306690738754696e-16
"""
y = 0.5 * (1 - math.erf(-(x - mu)/(sigma * math.sqrt(2.0))))
if y > 1: y = 1
return y
评论列表
文章目录