-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbinomial_probability.py
57 lines (44 loc) · 1.91 KB
/
binomial_probability.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python
# Copyright (c) 2009 GWU & NHLBI, NIH
# Authors: Chongzhi Zang, Weiqun Peng and Keji Zhao
#
# This software is distributable under the terms of the GNU General
# Public License (GPL) v2, the text of which can be found at
# http://www.gnu.org/copyleft/gpl.html. Installing, importing or
# otherwise using this module constitutes acceptance of the terms of
# this License.
#
# Disclaimer
#
# This software is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# Comments and/or additions are welcome (send e-mail to:
import re, os, sys, shutil
from math import *
from scipy import *
from string import *
from optparse import OptionParser
import operator
#import associate_binary_modification_with_expression
plus = re.compile("\+");
minus = re.compile("\-");
Dir = os.getcwd();
def binomial_probability_calculator(p, n, k):
return (round(misc.comb(n, k)) * pow(p, k) * pow(1 - p, n - k))
def main(argv):
parser = OptionParser()
parser.add_option("-m", "--total", action="store", type="int", dest="m", help="pool size, natural number", metavar="<int>")
parser.add_option("-p", "--total_positive", action="store", type="int", dest="p", help="total positive number to decide p, must be less than m", metavar="<int>")
parser.add_option("-n", "--n", action="store", type="int", dest="n", help="n", metavar="<int>")
parser.add_option("-k", "--k", action="store", type="int", dest="k", help="k", metavar="<int>")
(opt, args) = parser.parse_args(argv)
if len(argv) < 8:
parser.print_help()
sys.exit(1)
print 'Binomial probability is', binomial_probability_calculator(float(opt.p)/opt.m, opt.n, opt.k)
if __name__ == "__main__":
main(sys.argv)