Skip to content

Instantly share code, notes, and snippets.

@raviprakashgiri
Last active January 25, 2016 06:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raviprakashgiri/272dd8100732dad55b51 to your computer and use it in GitHub Desktop.
Save raviprakashgiri/272dd8100732dad55b51 to your computer and use it in GitHub Desktop.
Expected Probability Python Code
# Author Ravi Prakash Giri
import sys
total = 0
def fact(n):
total = n
while n > 1:
total *= (n - 1)
n -= 1
return total
rr=range(2,16)
eps=range(2,300)
ii=range(1,240)
prob_sum_expected=0.0
encyp=[]
final=[]
const = fact(int(240))
for rho in rr:
#print "Rho = ",rho
pr=[]
p=float(rho-1)/15.0
prob_sum_expected=0.0
for encr in eps:
#print "encr =",encr
prob_sum=0.0
#print prob_sum
for i in ii:
const1 = fact(int(i))
const2 = fact(int(240-i))
intermediate = float(const/(const1*const2))
#print "inter",intermediate
tmp=float(1-pow(p,encr-1)*(1-p)-pow(p,encr))
tmp1=float(pow(p,encr-1)*(1-p))
temp_result=pow(tmp,240-i)*pow(tmp1,i)*intermediate
prob_sum=prob_sum+temp_result
#print prob_sum
#print tmp,tmp1,temp_result,prob_sum
prob_sum = prob_sum*encr
prob_sum_expected = prob_sum_expected+prob_sum
pr.append(prob_sum_expected)
final.append(pr[-1])
print final
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment