Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import factorial,exp,sqrt
- def permutation(n,r):
- """returns nPr"""
- return factorial(n)/factorial(n-r)
- def combination(n,r):
- """Returns nCr"""
- return factorial(n)/(factorial(r)*factorial(n-r))
- def binomial_distribution(x,n,p):
- """
- Computes the probability of having x successes out of n trials.
- Each trial has a probability of success p
- """
- nCx = combination(n,x)
- q = 1-p
- return nCx*(p**x)*(q**(n-x))
- def geometric_distribution(n,p):
- """
- Computes the probability of 1st success on the nth trial.
- Each trial has a probability of success p
- """
- q = 1 - p
- return p*q**(n-1)
- def poisson(k,l):
- """
- Computes the probability of k successes.
- The average number of successes is l
- """
- return (l**k)*exp(-l)/factorial(k)
- def erf(x):
- t = 1 / (1 + 0.5*abs(x))
- tau = t*exp( -x**2 - 1.26551223 + 1.00002368*t + 0.37409196*t**2 + 0.09678418*t**3
- - 0.18628806*t**4 + 0.27886807*t**5 -1.13520398*t**6 + 1.48851587*t**7
- - 0.82215223*t**8 + 0.17087277*t**9)
- if x < 0:
- return tau - 1
- else:
- return 1 - tau
- def norm(x):
- """
- Computes the probability of X <= x in the normal
- distribution.
- """
- return 0.5*(1 + erf(x/sqrt(2)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement