commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject [41/53] [abbrv] [math] MATH-1343
Date Thu, 21 Apr 2016 23:15:27 GMT
MATH-1343

Unnecessary recomputation.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/b5778053
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/b5778053
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/b5778053

Branch: refs/heads/develop
Commit: b577805347d56f1927615fad311868a3537a9cb6
Parents: ae2c81a
Author: Gilles <erans@apache.org>
Authored: Sat Mar 26 02:32:10 2016 +0100
Committer: Gilles <erans@apache.org>
Committed: Sat Mar 26 02:32:10 2016 +0100

----------------------------------------------------------------------
 .../math4/distribution/BetaDistribution.java        | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/b5778053/src/main/java/org/apache/commons/math4/distribution/BetaDistribution.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/distribution/BetaDistribution.java b/src/main/java/org/apache/commons/math4/distribution/BetaDistribution.java
index 987e8eb..abccb93 100644
--- a/src/main/java/org/apache/commons/math4/distribution/BetaDistribution.java
+++ b/src/main/java/org/apache/commons/math4/distribution/BetaDistribution.java
@@ -42,10 +42,8 @@ public class BetaDistribution extends AbstractRealDistribution {
     private final double alpha;
     /** Second shape parameter. */
     private final double beta;
-    /** Normalizing factor used in density computations.
-     * updated whenever alpha or beta are changed.
-     */
-    private double z;
+    /** Normalizing factor used in density computations.*/
+    private final double z;
     /** Inverse cumulative probability accuracy. */
     private final double solverAbsoluteAccuracy;
 
@@ -75,7 +73,7 @@ public class BetaDistribution extends AbstractRealDistribution {
                             double inverseCumAccuracy) {
         this.alpha = alpha;
         this.beta = beta;
-        z = Double.NaN;
+        z = Gamma.logGamma(alpha) + Gamma.logGamma(beta) - Gamma.logGamma(alpha + beta);
         solverAbsoluteAccuracy = inverseCumAccuracy;
     }
 
@@ -97,13 +95,6 @@ public class BetaDistribution extends AbstractRealDistribution {
         return beta;
     }
 
-    /** Recompute the normalization factor. */
-    private void recomputeZ() {
-        if (Double.isNaN(z)) {
-            z = Gamma.logGamma(alpha) + Gamma.logGamma(beta) - Gamma.logGamma(alpha + beta);
-        }
-    }
-
     /** {@inheritDoc} */
     @Override
     public double density(double x) {
@@ -114,7 +105,6 @@ public class BetaDistribution extends AbstractRealDistribution {
     /** {@inheritDoc} **/
     @Override
     public double logDensity(double x) {
-        recomputeZ();
         if (x < 0 || x > 1) {
             return Double.NEGATIVE_INFINITY;
         } else if (x == 0) {


Mime
View raw message