Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    def test_plot_prob_bounded_coal(self):
        n = 1000
        k = 4
        t = 800
        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, 2):
            x, y = distrib([q[i] - q[i-1] for q in alltimes], width=20)
            p.plot(x, y, style="lines", xmax=500)

        x = list(frange(0, 500, 10))
        #for i in range(1, 2): #k):
        y2 = [coal.prob_bounded_coal(j, k, n, t) for j in x]
        p.plot(x, y2, style="lines", xmax=500)

        fequals(y, y2, rel=.05, eabs=.01)
Exemplo n.º 3
0
    def test_plot_bounded_coal(self):
        n = 1000
        k = 6
        T = 500

        # plots should differ
        p = plotfunc(lambda t: coal.prob_bounded_coal(t, k, n, T),
                     0, 1000, 10)
        p.plotfunc(lambda t: coal.prob_coal(t, k, n),
                   0, 1000, 10)
Exemplo n.º 4
0
    def test_cdf_coal_bounded(self):
        n = 1000
        k = 4
        t = 500
        step = .1
        x = list(frange(0, 500, step))
        y = [coal.prob_bounded_coal(i, k, n, t) * step for i in x]
        y2 = cumsum(y)
        y3 = [coal.cdf_bounded_coal(i, k, n, t) for i in x]

        p = plot(x, y2, style="lines")
        p.plot(x, y3, style="lines")
        p.plot([0, 500], [1, 1], style="lines")

        fequals(y2, y3, eabs=.01)
Exemplo n.º 5
0
    def test_prob_coal_cond_counts_simple(self):

        # when we condition on b=1, it is the same as the bounded coal
        # PDF.
        # prob_coal_cond_counts is actually a more general version of
        # prob_bounded_coal

        outdir = 'test/tmp/test_coal/Coal_test_prob_coal_counys_simple/'
        make_clean_dir(outdir)

        a = 5
        b = 1
        t = 2000
        n = 1000
        p = Gnuplot()
        p.enableOutput(False)

        for x in frange(0, 2000, 10):
            y = coal.prob_coal_cond_counts_simple(x, a, b, t, n)
            y2 = coal.prob_bounded_coal(x, a, n, t)
            self.assertAlmostEqual(y, y2)