Search code examples
javaapache-commonsnormal-distributionapache-commons-math

Apache Commons Math Normal Cumulative Probability


Wikipedia has listed a variety of numerical methods for computing cumulative probability of a normal distribution. However, with Apache Commons Math you do not need know about any of them as the library simply does the job for you:

NormalDistribution normal = new NormalDistribution(mu, sigma);
normal.cumulativeProbability(x);

For some research project, I'm interested to know what method they use. Does anyone know what method Apache Commons Math uses to approximate the normal cumulative value? Is it from the methods listed in wikipedia or they have implemented something different?


Solution

  • The beauty of open source software is that you can always check the source code. The implementation of cumulativeProbability is rather simple, it just returns

    0.5 * (1 + Erf.erf(dev / (standardDeviation * SQRT2)));
    

    where Erf.erf computes the error function. It's defined here.

    And no, it doesn' use any of the special methods in the mentioned Wikipedia article. It's just a straight-forward implementation of the formula

    enter image description here