I use these implementations:
function cdf(x, mean, variance) { return 0.5 * (1 + erf((x - mean) / (Math.sqrt(2 * variance)))); } function erf(x) {
Sources:
The error is related to the erf implementation, I think, although this is not very important for me, so you might want to look deeper into it when the error is important.
Obviously, to get the standard normal cdf, you pass the average value = 0 and variance = 1 to the cdf function, i.e.
function std_n_cdf(x) { return cdf(x, 0, 1); }
source share