You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tn...@apache.org on 2013/10/21 22:28:05 UTC

svn commit: r1534363 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/NormalDistribution.java

Author: tn
Date: Mon Oct 21 20:28:05 2013
New Revision: 1534363

URL: http://svn.apache.org/r1534363
Log:
Replace impl of NormalDistribution.density by calling FastMath.exp(logDensity()) which should be faster.

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/NormalDistribution.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/NormalDistribution.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/NormalDistribution.java?rev=1534363&r1=1534362&r2=1534363&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/NormalDistribution.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/NormalDistribution.java Mon Oct 21 20:28:05 2013
@@ -41,8 +41,6 @@ public class NormalDistribution extends 
     public static final double DEFAULT_INVERSE_ABSOLUTE_ACCURACY = 1e-9;
     /** Serializable version identifier. */
     private static final long serialVersionUID = 8589540077390120676L;
-    /** √(2 π) */
-    private static final double SQRT2PI = FastMath.sqrt(2 * FastMath.PI);
     /** √(2) */
     private static final double SQRT2 = FastMath.sqrt(2.0);
     /** Mean of this distribution. */
@@ -150,9 +148,7 @@ public class NormalDistribution extends 
 
     /** {@inheritDoc} */
     public double density(double x) {
-        final double x0 = x - mean;
-        final double x1 = x0 / standardDeviation;
-        return FastMath.exp(-0.5 * x1 * x1) / (standardDeviation * SQRT2PI);
+        return FastMath.exp(logDensity(x));
     }
 
     /** {@inheritDoc} */