-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnegative_binomial.py
22 lines (19 loc) · 937 Bytes
/
negative_binomial.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import math
from combination import CombinationCalc
# returns the probability of having a certain number of failures before you have a certain number of successes
class NegativeBinomialDist(object):
def neg_binomial_calc(self, success_prob, failures, successes):
comb = CombinationCalc()
if success_prob < 0 or failures < 0 or successes < 0:
print 'None of the numbers can be negative.'
return
elif success_prob == 0 or successes == 0:
print 'Successes and success_prob cannot be zero.'
return
else:
try:
return round(comb.calc_combination(failures + successes - 1, successes - 1) * math.pow(success_prob, successes) * math.pow(1 - success_prob, failures), 4)
except:
print 'An error occurred. Enter numbers for parameters.'
#neg = NegativeBinomialDist()
#print neg.neg_binomial_calc(0.7, 0, 6)