Beispiel #1
0
    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()