def _test_survivor_distrib(self): """ensure proper number of survivors""" T = 1.2 birth = 2.0 death = 1.0 ntrees = 10000 survivors = [] # number of survivors in a tree for i in xrange(ntrees): tree = birthdeath.sample_birth_death_tree(T, birth, death) if len(tree.leaves()) == 1: if tree.leaves()[0].dist >= T: survivors.append(1) else: survivors.append(0) else: survivors.append(len(tree.leaves())) doomprob = birthdeath.prob_birth_death(1, 0, T, birth, death) h = [(1.0 - doomprob) * x/float(ntrees) for x in util.hist_int(survivors)] h[0] = doomprob h2 = [birthdeath.prob_birth_death(1, x, T, birth, death) for x in range(0, 10)] diff = util.vsub(h[:10], h2[:10]) #print h[:10] #print h2[:10] self.assert_(max(map(abs, diff)) < .01)
def test_birth_death_large(self): t = 0.0392320007 birth = 0.400400013 death = 0.400000006 print "large" print birthdeath.prob_birth_death(60, 71, t, birth, death) print spidir.birthDeathCounts2(60, 71, t, birth, death) print spidir.birthDeathCounts(60, 71, t, birth, death) t = 0.067008 birth = 0.010100 death = 0.010000 print spidir.birthDeathCounts(51, 51, t, birth, death) print spidir.birthDeathCounts2(51, 51, t, birth, death) print spidir.birthDeathCounts(51, 51, t, birth, death)
def test_birth_death_same(self): counts = list(range(1, 10)) birth = .2 death = .1 lam = birth t = 10.4 for a in range(1, 10): for b in range(0, 10): l = spidir.birthDeathCounts(a, b, t, birth, death) #l2 = spidir.birthDeathCounts2(a, b, t, birth, death*.999) #l2 = prob_birth_death_same(a, b, t, lam) l2 = l l3 = birthdeath.prob_birth_death(a, b, t, birth, death) print a, b, l, l2, l3 #fequal(l, l2, .01) fequal(l, l3, .01)
def test_birth_death(self): counts = list(range(1, 10)) birth = 0.01 death = 0.02 t = 1.0 for a in range(1, 10): for b in range(0, 10): l = spidir.birthDeathCounts(a, b, t, birth, death) #l2 = spidir.birthDeathCounts2(a, b, t, birth, death) l2 = l l3 = birthdeath.prob_birth_death(a, b, t, birth, death) print a, b, l, l2, l3 #fequal(l, l2, .1) fequal(l, l3, .01) fequal(sum(spidir.birthDeathCounts(a, b, t, birth, death) for b in xrange(0, 20)), 1.0, .001)
def test_birth_death(self): counts = list(range(1, 10)) birth = 0.01 death = 0.02 t = 1.0 for a in range(1, 10): for b in range(0, 10): l = spidir.birthDeathCounts(a, b, t, birth, death) #l2 = spidir.birthDeathCounts2(a, b, t, birth, death) l2 = l l3 = birthdeath.prob_birth_death(a, b, t, birth, death) print a, b, l, l2, l3 #fequal(l, l2, .1) fequal(l, l3, .01) fequal( sum( spidir.birthDeathCounts(a, b, t, birth, death) for b in xrange(0, 20)), 1.0, .001)