commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject [3/3] [math] Perform computation/allocation only if needed.
Date Tue, 31 May 2016 00:48:21 GMT
Perform computation/allocation only if needed.

Thanks to Dave Brosius.


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

Branch: refs/heads/develop
Commit: fc9d93db68a3c33e5ead8c7ecb187fdf0f06cc4f
Parents: 362ab2b
Author: Gilles <gilles@harfang.homelinux.org>
Authored: Tue May 31 02:38:16 2016 +0200
Committer: Gilles <gilles@harfang.homelinux.org>
Committed: Tue May 31 02:38:16 2016 +0200

----------------------------------------------------------------------
 .../math4/stat/interval/ClopperPearsonInterval.java    | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/fc9d93db/src/main/java/org/apache/commons/math4/stat/interval/ClopperPearsonInterval.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/stat/interval/ClopperPearsonInterval.java
b/src/main/java/org/apache/commons/math4/stat/interval/ClopperPearsonInterval.java
index bf5d6ad..6f257e7 100644
--- a/src/main/java/org/apache/commons/math4/stat/interval/ClopperPearsonInterval.java
+++ b/src/main/java/org/apache/commons/math4/stat/interval/ClopperPearsonInterval.java
@@ -35,19 +35,18 @@ public class ClopperPearsonInterval implements BinomialConfidenceInterval
{
         IntervalUtils.checkParameters(numberOfTrials, numberOfSuccesses, confidenceLevel);
         double lowerBound = 0;
         double upperBound = 0;
-        final double alpha = (1.0 - confidenceLevel) / 2.0;
 
-        final FDistribution distributionLowerBound = new FDistribution(2 * (numberOfTrials
- numberOfSuccesses + 1),
-                                                                       2 * numberOfSuccesses);
         if (numberOfSuccesses > 0) {
+	    final double alpha = 0.5 * (1 - confidenceLevel);
+
+	    final FDistribution distributionLowerBound = new FDistribution(2 * (numberOfTrials -
numberOfSuccesses + 1),
+									   2 * numberOfSuccesses);
             final double fValueLowerBound = distributionLowerBound.inverseCumulativeProbability(1
- alpha);
             lowerBound = numberOfSuccesses /
                          (numberOfSuccesses + (numberOfTrials - numberOfSuccesses + 1) *
fValueLowerBound);
-        }
 
-        final FDistribution distributionUpperBound = new FDistribution(2 * (numberOfSuccesses
+ 1),
-                                                                       2 * (numberOfTrials
- numberOfSuccesses));
-        if (numberOfSuccesses > 0) {
+	    final FDistribution distributionUpperBound = new FDistribution(2 * (numberOfSuccesses
+ 1),
+									   2 * (numberOfTrials - numberOfSuccesses));
             final double fValueUpperBound = distributionUpperBound.inverseCumulativeProbability(1
- alpha);
             upperBound = (numberOfSuccesses + 1) * fValueUpperBound /
                          (numberOfTrials - numberOfSuccesses + (numberOfSuccesses + 1) *
fValueUpperBound);


Mime
View raw message