def bootstrap(diffs, B):
m = multiprocessing.Manager()
q = m.Queue()
pool = multiprocessing.Pool()
rs = pool.map_async(bs_one, [(diffs, q) for _ in xrange(B)])
pool.close() # No more work
while (True):
if (rs.ready()): break
log.info('Waiting for %d bootstrap samples to finish...' % (B - q.qsize()))
time.sleep(1)
assert(q.qsize() == B), "qsize=%d, B=%d" % (q.qsize(), B)
count = [0] * len(diffs[0])
for i in xrange(B):
qres = q.get()
for j in xrange(len(diffs[0])):
count[j] += qres[j]
assert(q.empty())
return [(c + 1.0) / (B + 1.0) for c in count] # smoothed p-value
评论列表
文章目录