The cumulative distribution function (CDF) of Gaussian distribution with standard deviation (sig) and mean (cen) in python
Ref:
https://www.mathworks.com/help/matlab/ref/erf.html
https://introcs.cs.princeton.edu/java/11gaussian/
===============================================
python code:
================================================
from scipy import special
import matplotlib.pyplot as plt
import numpy as np
def erfValue(x, cen, sig):
# 1 x - cen
# erf(x) = --- (1 + erf(-----------------))
# 2 sqrt(2) * sig
return 0.5*(1+special.erf((x-cen)/(np.sqrt(2)*sig)))
def erfcValue(x, cen, sig):
return 1-erfValue(x, cen, sig)
cen = 9.54
sig=2
xx = np.arange(0,20,step=.01)
erf = erfValue(xx, cen, sig)
plt.figure()
plt.plot(xx,erf,'r')
x1 = cen
y1 = erfValue(x1, cen, sig)
plt.plot(x1, y1, 'k.')
plt.text(x1, y1, "(%.2f, %.2f)"%(x1,y1))
x2 = cen+sig
y2 = erfValue(x2, cen, sig)
plt.plot(x2, y2, 'k.')
plt.text(x2, y2, "(%.2f, %.2f)"%(x2,y2))
x3 = cen-sig
y3 = erfValue(x3, cen, sig)
plt.plot(x3, y3, 'k.')
plt.text(x3, y3, "(%.2f, %.2f)"%(x3,y3))
plt.title("erf curve")
plt.show()
erfc = erfcValue(xx, cen, sig)
plt.figure()
plt.plot(xx,erfc,'b')
x1 = cen
y1 = erfcValue(x1, cen, sig)
plt.plot(x1, y1, 'k.')
plt.text(x1, y1, "(%.2f, %.2f)"%(x1,y1))
x2 = cen+sig
y2 = erfcValue(x2, cen, sig)
plt.plot(x2, y2, 'k.')
plt.text(x2, y2, "(%.2f, %.2f)"%(x2,y2))
x3 = cen-sig
y3 = erfcValue(x3, cen, sig)
plt.plot(x3, y3, 'k.')
plt.text(x3, y3, "(%.2f, %.2f)"%(x3,y3))
plt.title("erfc curve")
plt.show()
================================================
Comments
Post a Comment