def test_sample_bounded_coal(self): n = 1000 k = 5 T = 500 d = [coal.sample_bounded_coal(k, n, T) for i in xrange(2000)] p = plotdistrib(d, 40) p.plotfunc(lambda t: coal.prob_bounded_coal(t, k, n, T), 0, T, T/200) eq_sample_pdf(d, lambda t: coal.prob_bounded_coal(t, k, n, T), 40)
def test_fast_sample_bounded_coal(self): # sample bounded coal times efficiently n = 1000 k = 5 t = 500 alltimes = [] # sample times for i in xrange(5000): while True: times = [0] for j in xrange(k, 1, -1): times.append(times[-1] + coal.sample_coal(j, n)) if times[-1] >= t: break if times[-1] < t: break alltimes.append(times) p = Gnuplot() for i in range(1, k): x, y = distrib([q[i] - q[i-1] for q in alltimes], width=30) p.plot(x, y, style="lines", xmax=500) p.enableOutput(True) p.replot() # sample times efficently alltimes2 = [] for i in xrange(5000): times = [0] for j in xrange(k, 1, -1): times.append(times[-1] + coal.sample_bounded_coal(j, n, t-times[-1])) alltimes2.append(times) #p = Gnuplot() for i in range(1, k): x, y = distrib([q[i] - q[i-1] for q in alltimes2], width=30) p.plot(x, y, style="lines", xmax=500) p.enableOutput(True) p.replot()