2012-04-24 43 views
1

我需要在我編程的Python應用程序中使用概率和累積密度函數。 SciPy提供了這兩種功能,但對於這兩種功能來說,它似乎過於依賴。 PDF似乎很容易在沒有SciPy的情況下實施。 (From the docs:PDF和CDF沒有SciPy

爲範數的概率密度函數爲:

norm.pdf(X)= EXP(-x ** 2/2)/ SQRT(2 * PI)

有沒有辦法讓CDF以及沒有使用SciPy?

+0

用手整合!有一個簡單的公式...對嗎? [提示:否] – Shep 2012-04-24 17:07:15

回答

2

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))