From 3cda85f2e34d7d6be69360a28700add2fdf9bc54 Mon Sep 17 00:00:00 2001 From: kiran Date: Fri, 24 Apr 2009 03:32:04 +0000 Subject: [PATCH] New implementation of binomial probability that accurately computes values down to around 1e-237. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@520 348d0f76-0448-11de-a6fe-93d51630548a --- .../org/broadinstitute/sting/utils/MathUtils.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/java/src/org/broadinstitute/sting/utils/MathUtils.java b/java/src/org/broadinstitute/sting/utils/MathUtils.java index c76bbc3b2..96d956b97 100755 --- a/java/src/org/broadinstitute/sting/utils/MathUtils.java +++ b/java/src/org/broadinstitute/sting/utils/MathUtils.java @@ -1,5 +1,7 @@ package org.broadinstitute.sting.utils; +import cern.jet.math.Arithmetic; + /** * MathUtils is a static class (no instantiation allowed!) with some useful math methods. * @@ -56,4 +58,17 @@ public class MathUtils { if (a > b) { return -1; } return 1; } + + /** + * Computes a binomial probability + * + * @param k number of successes + * @param n number of Bernoulli trials + * @param p probability of success + * + * @return the binomial probability of the specified configuration. Computes values down to about 1e-237. + */ + public static double binomialProbability(long k, long n, double p) { + return Arithmetic.binomial(n, k)*Math.pow(p, k)*Math.pow(1.0 - p, n - k); + } }