Bootstrapping
Why bootstrappign with unique samples is difficult
from itertools import izip
from numpy import array, log, exp
from scipy.special import gammaln
import itertools as it
def log_factorial(x):
"""Returns the logarithm of x!
Also accepts lists and NumPy arrays in place of x."""
return gammaln(array(x)+1)
input = [1, 2, 3.5, 4, 7,7.3, 8.6, 12.4, 13.8, 18.1]
n = 0
for i in it.combinations_with_replacement(input,10):
n = n+ 1
res = []
wj = []
for combo in it.combinations_with_replacement(input,10):
counts = \[combo.count(i) for i in input\]
prob = exp(log\_factorial(10) - sum(\[ log\_factorial(c) for c in counts\]) + 10\*log(1./10))
res.append(sum(combo\[2:-2\])/6.)
wj.append(prob)
mu = sum([wj[i]*res[i] for i in range(n)])
print mu
se = (sum( [ wj[i] *( (res[i]-mu)**2 ) for i in range(n) ] ))**0.5
print se
7.255138602
2.02985932053
-
Learnt how fast the code runs in python
-
Learnt about never using factorial function in python, instead use gamma