Ejemplo n.º 1
0
    def test_sample_birth(self):

        prep_dir("test/output/birth_death_sample")

        n = 1
        T = 1.0
        birth = 2.0
        death = 0.5

        tic("sampling")
        samples = [
            birthdeath.sample_birth_wait_time(n, T, birth, death)
            for i in xrange(10000)
        ]
        toc()

        tic("samplingC")
        samples2 = [
            spidir.sampleBirthWaitTime1(T, birth, death) for i in xrange(10000)
        ]
        toc()

        cond = 1.0 - birthdeath.prob_no_birth(n, T, birth, death)

        x, y2 = distrib(samples, 20)
        x2, y3 = distrib(samples2, 20)
        y = [
            birthdeath.birth_wait_time(i, n, T, birth, death) / cond for i in x
        ]

        rp.plot(x, y, t="l", xlab="", ylab="")
        rp.lines(x, y2, col="red")
        rp.lines(x2, y3, col="blue")
        raw_input()
Ejemplo n.º 2
0
    def test_sample_birth(self):

        prep_dir("test/output/birth_death_sample")

        n = 1
        T = 1.0
        birth = 2.0
        death = 0.5

        tic("sampling")
        samples = [birthdeath.sample_birth_wait_time(n, T, birth, death)
                   for i in xrange(10000)]        
        toc()

        tic("samplingC")
        samples2 = [spidir.sampleBirthWaitTime1(T, birth, death)
                   for i in xrange(10000)]        
        toc()

        cond = 1.0 - birthdeath.prob_no_birth(n, T, birth, death)

        x, y2 = distrib(samples, 20)
        x2, y3 = distrib(samples2, 20)
        y = [birthdeath.birth_wait_time(i, n, T, birth, death) / cond
              for i in x]

        rp.plot(x, y, t="l", xlab="", ylab="")
        rp.lines(x, y2, col="red")
        rp.lines(x2, y3, col="blue")
        raw_input()
Ejemplo n.º 3
0
    def walk(dup, parent_time):
        remain = time_span - (start_time - parent_time)

        #while True:
        t = birthdeath.sample_birth_wait_time(1, remain, birth, death)
        times[dup] = parent_time - t
        
        snode = recon[dup]
        for child in dup.children:
            if events[child] == "dup" and recon[child] == snode:
                walk(child, times[dup])
Ejemplo n.º 4
0
    def walk(dup):
        if dup.parent:
            parent_time = times[dup.parent]
        else:
            parent_time = start_time
        remain = time_span - (start_time - parent_time)

        while True:
            t = birthdeath.sample_birth_wait_time(1, remain, birth, death)
            times[dup] = parent_time - t
            assert t >= 0.0

            if times[dup] != parent_time:
                break
            else:
                print t, remain, dup.parent

        for child in dup.children:
            if events[child] == "dup":
                walk(child)
Ejemplo n.º 5
0
    def walk(dup):
        if dup.parent:
            parent_time = times[dup.parent]
        else:
            parent_time = start_time
        remain = time_span - (start_time - parent_time)

        while True:
            t = birthdeath.sample_birth_wait_time(1, remain, birth, death)
            times[dup] = parent_time - t
            assert t >= 0.0

            if times[dup] != parent_time:
                break
            else:
                print t, remain, dup.parent

        for child in dup.children:
            if events[child] == "dup":
                walk(child)