Every line of 'np random binomial' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
144 def binomial(trials, p, shape=[]): 145 """binomial(trials, p) or binomial(trials, p, [n, m, ...]) returns array of binomially distributed random integers. 146 147 trials is the number of trials in the binomial distribution. 148 p is the probability of an event in each trial of the binomial distribution.""" 149 if shape == []: 150 shape = None 151 return mt.binomial(trials, p, shape)
76 def test_binomial(self): 77 assert self.rs.binomial(10, .5) >= 0 78 assert self.rs.binomial(1000, .5) >= 0
123 def binomial(big, small): 124 ''' 125 Get the binomial coefficient (big small). 126 127 This is used in combinatorical calculations. More information: 128 http://en.wikipedia.org/wiki/Binomial_coefficient 129 ''' 130 if big == small: 131 return 1 132 if big < small: 133 return 0 134 else: 135 return (math.factorial(big) // math.factorial(big - small) 136 // math.factorial(small))
658 def binomial_like(self, x, n, p, name='binomial', prior=False): 659 """Binomial log-likelihood""" 660 661 if not shape(n) == shape(p): raise ParameterError, 'Parameters must have same dimensions' 662 663 if ndim(n) > 1: 664 665 return sum([self.binomial_like(y, _n, _p, name, prior) for y, _n, _p in zip(x, n, p)]) 666 667 else: 668 669 # Ensure valid values of parameters 670 self.constrain(p, 0, 1) 671 self.constrain(n, lower=x) 672 self.constrain(x, 0) 673 674 # Enforce array type 675 x = atleast_1d(x) 676 p = resize(p, shape(x)) 677 n = resize(n, shape(x)) 678 679 # Goodness-of-fit 680 if self._gof and not prior: 681 682 try: 683 self._like_names.append(name) 684 except AttributeError: 685 pass 686 687 expval = p * n 688 689 # Simulated values 690 y = array([rbinomial(_n, _p) for _n, _p in zip(n, p)]) 691 692 # Generate GOF points 693 gof_points = sum(transpose([self.loss(x, expval), self.loss(y, expval)])) 694 695 self._gof_loss.append(gof_points) 696 697 return sum([fbinomial(xx, nn, pp) for xx, nn, pp in zip(x, n, p)])