def PDF(self, x): if x < 0.0: return 0.0 else: if x == 0: nchoosek = 1.0 elif (x < 0) or (x > self.n): nchoosek = 0.0 else: nchoosek = nChooseK(self.n, x) return nchoosek * pow(self.prob, x) * pow(1.0 - self.prob, self.n - x)
def PDF(self, x): # x is number of white balls drawn # compute nchoosek(n_white,x) if x == 0: nchoosek1 = 1.0 elif (x < 0) or (x > self.n_white): nchoosek1 = 0.0 else: nchoosek1 = nChooseK(self.n_white, x) # compute nchoosek(n_black, n_drawn - x) if (self.n_drawn - x == 0): nchoosek2 = 1.0 elif (self.n_drawn - x < 0) or (self.n_drawn - x > self.n_black): nchoosek2 = 0.0 else: nchoosek2 = nChooseK(self.n_black, self.n_drawn - x) # compute nchoosek(n_white + n_black, n_drawn) if self.n_drawn == 0: nchoosek3 = 1.0 elif (self.n_drawn < 0) or (self.n_drawn > self.n_white + self.n_black): nchoosek3 = 0.0 else: nchoosek3 = nChooseK(self.n_white + self.n_black, self.n_drawn) # compute return nchoosek1 * nchoosek2 / nchoosek3
def PDF(self, x): if (math.isnan(x)): return float("nan") elif (self.n == 0.0) and (x == 0.0): return 1.0 elif (self.n == 0.0) and (x != 0.0): return 0.0 elif (self.prob == 1.0) and (x != 0.0): return 0.0 elif (self.prob == 1.0) and (x == 0.0): return 1.0 elif (x >= 0.0): if x == 0: val = 1.0 elif x < 0: val = 0.0 else: val = nChooseK(self.n + x - 1.0, x) return val * pow(1.0 - self.prob, x) * pow(self.prob, self.n) else: return 0.0