3

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?

Pro.Hessam
  • 819
  • 3
  • 11
  • 26

2 Answers2

5

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

Carsten
  • 17,991
  • 4
  • 48
  • 53
  • Thanks. For the sake of completeness, I'd like to mention that the error function does not have a closed formula and is approximated using some numerical method. – Pro.Hessam Apr 21 '15 at 20:24
  • 1
    Right, you can see exactly what Commons Math does by looking at the implementation of `Erf` in the `special` package. It does use methods referenced in the Wikipedia Erf article[1]. [1]:http://en.wikipedia.org/wiki/Error_function#Approximation_with_elementary_functions – Phil Steitz Apr 21 '15 at 21:51
1

You can probably see the source code or the javadoc. See there http://commons.apache.org/proper/commons-math/source-repository.html

and

http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math3/distribution/NormalDistribution.html

Also, there is alot of information in the user's guide. The section about distribution seems interesting: http://commons.apache.org/proper/commons-math/userguide/distribution.html

JFPicard
  • 5,029
  • 3
  • 19
  • 43
  • Thanks but my question is not answered in the javadoc. And I tend to ask my peers before investigating the source code. – Pro.Hessam Apr 21 '15 at 20:15
  • 1
    @Pro.Hessam That's kinda rude. You can just look at the source code in a matter of seconds, while you choose not to do that but rely on the time and patience of others to do your work. – Carsten Apr 21 '15 at 20:20
  • @Carsten I was hoping to find someone familiar with the library in the community to answer my question. Not to waste anybody's time. – Pro.Hessam Apr 21 '15 at 20:27