我需要在我编写的 Python 应用程序中使用概率和累积密度函数。 SciPy 提供了这两种功能,但它似乎对这两个功能的依赖性太高了。 PDF 似乎很容易在没有 SciPy 的情况下实现。 ( From the docs: )
The probability density function for norm is:
norm.pdf(x) = exp(-x**2/2)/sqrt(2*pi)
有没有办法在不使用 SciPy 的情况下也获取 CDF?
请您参考如下方法:
参见 this post :
from math import *
def erfcc(x):
"""Complementary error function."""
z = abs(x)
t = 1. / (1. + 0.5*z)
r = t * exp(-z*z-1.26551223+t*(1.00002368+t*(.37409196+
t*(.09678418+t*(-.18628806+t*(.27886807+
t*(-1.13520398+t*(1.48851587+t*(-.82215223+
t*.17087277)))))))))
if (x >= 0.):
return r
else:
return 2. - r
def ncdf(x):
return 1. - 0.5*erfcc(x/(2**0.5))
