def test_two_deme_growth_without_hard_reset(self): N0 = [90, 10] md = np.array(self.pop.diploid_metadata, copy=False) md['deme'][N0[0]:] = 1 t = [14, 23] # generations of growth in each deme N1 = [5361, 616] G0 = np.exp((np.log(N1[0]) - np.log(N0[0])) / t[0]) G1 = np.exp((np.log(N1[1]) - np.log(N0[1])) / t[1]) g = [] g.append(fwdpy11.SetExponentialGrowth(7, 0, G0)) g.append(fwdpy11.SetExponentialGrowth(7 + t[0], 0, fwdpy11.NOGROWTH)) g.append(fwdpy11.SetExponentialGrowth(33, 1, G1)) g.append(fwdpy11.SetExponentialGrowth(33 + t[1], 1, fwdpy11.NOGROWTH)) # after X generations of growth, N[0] changes to 100 # and the growth rate is not reset. p = [fwdpy11.SetDemeSize(11, 0, 100, False)] d = fwdpy11.DiscreteDemography(set_growth_rates=g, set_deme_sizes=p) ddr.DiscreteDemography_roundtrip(self.rng, self.pop, d, 100) md = np.array(self.pop.diploid_metadata, copy=False) deme_sizes = np.unique(md['deme'], return_counts=True) N1[0] = np.round(100. * np.power(G0, 7 + t[0] - 11)) self.assertEqual(self.pop.N, sum(N1)) for i, j in zip(deme_sizes[1], N1): self.assertEqual(i, j)
def test_two_deme_growth_with_hard_reset(self): N0 = [90, 10] md = np.array(self.pop.diploid_metadata, copy=False) md['deme'][N0[0]:] = 1 t = [14, 23] # generations of growth in each deme N1 = [5361, 616] G0 = np.exp((np.log(N1[0]) - np.log(N0[0])) / t[0]) G1 = np.exp((np.log(N1[1]) - np.log(N0[1])) / t[1]) g = [] g.append(fwdpy11.SetExponentialGrowth(7, 0, G0)) g.append(fwdpy11.SetExponentialGrowth(33, 1, G1)) g.append(fwdpy11.SetExponentialGrowth(33 + t[1], 1, fwdpy11.NOGROWTH)) # Cut off the growth in deme 0 after a few generations, # and manually set the new deme size to 100 w/no growth p = [fwdpy11.SetDemeSize(11, 0, 100)] d = fwdpy11.DiscreteDemography(set_deme_sizes=p, set_growth_rates=g) ddr.DiscreteDemography_roundtrip(self.rng, self.pop, d, 100) md = np.array(self.pop.diploid_metadata, copy=False) deme_sizes = np.unique(md['deme'], return_counts=True) N1 = [100, N1[1]] self.assertEqual(self.pop.N, sum(N1)) for i, j in zip(deme_sizes[1], N1): self.assertEqual(i, j)
def test_single_deme_growth(self): N1 = 3412 t = 111 G = np.exp((np.log(N1) - np.log(self.pop.N)) / t) g = [fwdpy11.SetExponentialGrowth(16, 0, G)] d = fwdpy11.DiscreteDemography(set_growth_rates=g) ddr.DiscreteDemography_roundtrip(self.rng, self.pop, d, 15 + t + 1) self.assertEqual(self.pop.N, N1) self.assertEqual(len(self.pop.diploid_metadata), N1)
def test_two_deme_growth(self): N0 = [90, 10] md = np.array(self.pop.diploid_metadata, copy=False) md['deme'][N0[0]:] = 1 t = [14, 23] # generations of growth in each deme N1 = [5361, 616] G0 = np.exp((np.log(N1[0]) - np.log(N0[0])) / t[0]) G1 = np.exp((np.log(N1[1]) - np.log(N0[1])) / t[1]) g = [] g.append(fwdpy11.SetExponentialGrowth(7, 0, G0)) g.append(fwdpy11.SetExponentialGrowth(7 + t[0], 0, fwdpy11.NOGROWTH)) g.append(fwdpy11.SetExponentialGrowth(33, 1, G1)) g.append(fwdpy11.SetExponentialGrowth(33 + t[1], 1, fwdpy11.NOGROWTH)) d = fwdpy11.DiscreteDemography(set_growth_rates=g) ddr.DiscreteDemography_roundtrip(self.rng, self.pop, d, 100) md = np.array(self.pop.diploid_metadata, copy=False) self.assertEqual(self.pop.N, sum(N1)) deme_sizes = np.unique(md['deme'], return_counts=True) for i, j in zip(deme_sizes[1], N1): self.assertEqual(i, j)
def test_mass_move_with_growth_no_reset(self): """ In generation 5, the mass movement from 0 to 1 """ m = [fwdpy11.move_individuals(5, 0, 1, 0.5, False)] g = [fwdpy11.SetExponentialGrowth(0, 0, 1.1)] d = fwdpy11.DiscreteDemography(mass_migrations=m, set_growth_rates=g) N0 = self.pop.N ddr.DiscreteDemography_roundtrip(self.rng, self.pop, d, 10) md = np.array(self.pop.diploid_metadata) deme_counts = np.unique(md['deme'], return_counts=True) N5 = np.round(N0 * np.power(g[0].G, 5)) N_after_mass_mig_0 = np.round((N5 // 2) * np.power(g[0].G, 5)) N = [N_after_mass_mig_0, N5 - N5 // 2] for i, j in zip(N, deme_counts[1]): self.assertEqual(i, j)
def test_mass_move_with_growth(self): """ In generation 5, the mass movement from 0 to 1 will reset the growth rate in deme 0 to fwdpy11.NOGROWTH This test is also handy b/c growth results in an odd total N by the time the mass migration happens """ m = [fwdpy11.move_individuals(5, 0, 1, 0.5)] g = [fwdpy11.SetExponentialGrowth(0, 0, 1.1)] d = fwdpy11.DiscreteDemography(mass_migrations=m, set_growth_rates=g) N0 = self.pop.N ddr.DiscreteDemography_roundtrip(self.rng, self.pop, d, 10) md = np.array(self.pop.diploid_metadata) deme_counts = np.unique(md['deme'], return_counts=True) N5 = np.round(N0 * np.power(g[0].G, 5)) N_after_mass_mig = [N5 // 2, N5 - N5 // 2] for i, j in zip(deme_counts[1], N_after_mass_mig): self.assertEqual(i, j)
def setUpClass(self): self.seg = fwdpy11.SetExponentialGrowth(0, 1, 0.1)
def test_init_with_two_growth_changes_same_generation(self): g = [fwdpy11.SetExponentialGrowth(0, 1, 0.3)] * 2 with self.assertRaises(ValueError): fwdpy11.DiscreteDemography(set_growth_rates=g)
def test_setting_growth(self): g = [fwdpy11.SetExponentialGrowth(0, 1, 0.3)] fwdpy11.DiscreteDemography(set_growth_rates=g)
def test_invalid_growth_rate(self): with self.assertRaises(ValueError): self.seg = fwdpy11.SetExponentialGrowth(0, 1, np.nan)
def test_invalid_deme(self): with self.assertRaises(ValueError): self.seg = fwdpy11.SetExponentialGrowth(0, -1, 0.1)