[ACCEPTED]-Which java-library computes the cumulative standard normal distribution function?-computation
Apache Commons - Math has what you are looking for.
More specifically, check 1 out the NormalDistribution
class.
If you want the exact code, this one seems 3 to be the same function used in OpenOffice 2 Calc (I've made some changes for it to work 1 in java):
// returns the cumulative normal distribution function (CNDF)
// for a standard normal: N(0,1)
double CNDF(double x)
{
int neg = (x < 0d) ? 1 : 0;
if ( neg == 1)
x *= -1d;
double k = (1d / ( 1d + 0.2316419 * x));
double y = (((( 1.330274429 * k - 1.821255978) * k + 1.781477937) *
k - 0.356563782) * k + 0.319381530) * k;
y = 1.0 - 0.398942280401 * Math.exp(-0.5 * x * x) * y;
return (1d - neg) * y + neg * (1d - y);
}
Found it here: http://www.codeproject.com/Messages/2622967/Re-NORMSDIST-function.aspx
A co-worker suggested colt, as he used it before. This 2 function has exactly the result as the example in 1 the reference document.
SuanShu, a Java numerical analysis library, computes the normal distribution 1 and many other statistical distributions.
You could use the power series formula, which 2 only takes up about 10 lines of code... see 1 for example http://introcs.cs.princeton.edu/java/22library/Gaussian.java.html (the function Phi
)
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.