For a project I have a specification with formulas, I have to implement. In these formulas a cumulative standard normal distribution function exists, that takes a float and outputs a probability. The function is symbolized by a Φ. Exists a Java-library, that computes this function?
If you want the exact code, this one seems to be the same function used in OpenOffice Calc (I've made some changes for it to work 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
Apache Commons - Math has what you are looking for.
More specifically, check out the NormalDistribution
class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With