def test_run_iteration_with_graveyard(tmp_path): pf = ParticleFilter(func, 10, initial_width=0.00001, boundaries=np.array([[0, 1], [0, 1]]), kill_controller=get_kill_controller(0.2, False)) graveyard = str(tmp_path) + "/graveyard.csv" x = np.random.rand(100, 2) y = np.arange(100) pf.set_seed(x, y) pf.initialise_run(graveyard) pf.run_iteration() assert os.path.exists(graveyard) os.remove(graveyard) assert not os.path.exists(graveyard) pf.change_graveyard(None) pf.run_iteration() assert not os.path.exists(graveyard) pf.change_graveyard(graveyard) pf.run_iteration() assert os.path.exists(graveyard) pf.end_run()
def test_calculate_procreation_rates_1(): pf = ParticleFilter(func, 100) x = np.random.rand(10, 2) y = np.arange(10) pf.set_seed(x, y) rates = pf._calculate_procreation_rates(y, 10000) rates[:-1] = rates[:-1] - rates[1:] positive = np.sum(rates[:-1] > 0) assert positive == len(y) - 1
def test_run_iteration(): pf = ParticleFilter(func, 10, initial_width=0.00001, boundaries=np.array([[0, 1], [0, 1]]), kill_controller=get_kill_controller(0.2, False)) x = np.random.rand(100, 2) y = np.arange(100) pf.set_seed(x, y) pf.initialise_run() pf.run_iteration() pf.end_run()
def test_calculate_procreation_rates_2(): pf = ParticleFilter(func, 100) x = np.random.rand(10, 2) y = np.ones(10) pf.set_seed(x, y) rates = pf._calculate_procreation_rates(y, 10000) assert len(np.unique(rates)) == 1 assert rates[0] > 0 rates = pf._calculate_procreation_rates(y, 13) assert len(np.unique(rates)) == 2 assert np.amax(rates) - np.amin(rates) == 1 assert np.sum(rates) == 13
def test_end_iteration_with_graveyard(tmp_path): pf = ParticleFilter(func, 100, initial_width=0.00001, boundaries=np.array([[0, 1], [0, 1]]), kill_controller=get_kill_controller(0.2, False)) graveyard = str(tmp_path) + "/graveyard.csv" x = np.random.rand(100, 2) y = np.arange(100) pf.set_seed(x, y) pf.initialise_run(graveyard) pf.run_iteration() pf.end_run() graveyard = np.genfromtxt(graveyard, delimiter=',', skip_header=1) assert graveyard.shape == (200, 5)