Which java-library computes the cumulative standard normal distribution function?
Asked Answered
T

5

11

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?

Thereinto answered 14/1, 2009 at 12:24 Comment(0)
T
3

A co-worker suggested colt, as he used it before. This function has exactly the result as the example in the reference document.

Thereinto answered 14/1, 2009 at 15:24 Comment(0)
C
14

Apache Commons - Math has what you are looking for.

More specifically, check out the NormalDistribution class.

Confection answered 14/1, 2009 at 12:33 Comment(0)
W
8

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

Wain answered 4/12, 2011 at 19:23 Comment(2)
the question wants the pdf of normal distribution!Elmoelmore
I don't think so. The question says "cumulative standard normal distribution function" both in the title and the text ... unless Φ means it's supposed to be the probability density function...Wain
T
3

A co-worker suggested colt, as he used it before. This function has exactly the result as the example in the reference document.

Thereinto answered 14/1, 2009 at 15:24 Comment(0)
Y
2

SuanShu, a Java numerical analysis library, computes the normal distribution and many other statistical distributions.

Yielding answered 24/6, 2010 at 16:59 Comment(0)
L
2

You could use the power series formula, which only takes up about 10 lines of code... see for example http://introcs.cs.princeton.edu/java/22library/Gaussian.java.html (the function Phi)

Lookout answered 18/11, 2012 at 22:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.