Tuonhan voi itsekin kehitellä:
integraali tiheysfunktiosta, laskee vaikka jollain numeerisella menetelmällä, jollei pythonissa ole valmiiksi integrointia.
edit: scipyssä on numeerinen integrointi
Edit2: Eihän normaalijakauman kertymäfunktiolle ole edes alkeisfunktioiden avulla ilmoitettavaa muotoa.
Edit3: No tässä ois valmis moduuli, jos joku vielä tarttee joskus:
s-alkuiset ovat normitettuja normaalijakaumia, muut eivät
#!/usr/bin/python
# -*- coding: ISO-8859-15 -*-
# Filename: normaldistribution.py
# Developer: Janne Solanpää
# Email: janne.solanpaa[ the funny at-sign ]gmail.com
# Depends on python-scipy and python-math
''' This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.'''
from scipy.integrate import quad
from math import pi, sqrt, e
# Standard normal distribution
#Probability density function
def snormaldist_pdf(x):
return 1/sqrt(2*pi)*e**(-0.5*x**2)
#Cumulative distribution function
def snormaldist_cdf(a,b):
return quad(lambda x: 1/sqrt(2*pi)*e**(-0.5*x**2),a,b)[0]
# The non-standard normal distribution
#Probability density function
# o = expected value
# h = standard deviation
def normaldist_pdf(x,o,h):
return 1/(h*sqrt(2*pi))*e**(-((x-o)**2)/(2*h**2))
#Cumulative distribution function
# o = expected value
# h = standard deviation
def normaldist_cdf(a,b,o,h):
return quad(lambda x: 1/(h*sqrt(2*pi))*e**(-((x-o)**2)/(2*h**2)),a,b)[0]
Edit4: Tiivistetty koodia, ja lisätty lisenssi sekä selitykset.