def test_save_no_sum_stats(history: History): """ Test that what has been stored can be retrieved correctly also when no sum stats are saved. """ particle_list = [] for _ in range(0, 6): particle = Particle( m=0, parameter=Parameter({"th0": np.random.random()}), weight=1.0 / 6, sum_stat={"ss0": np.random.random(), "ss1": np.random.random()}, distance=np.random.random(), ) particle_list.append(particle) population = Population(particle_list) # do not save sum stats # use the attribute first to make sure we have no typo print(history.stores_sum_stats) history.stores_sum_stats = False # test some basic routines history.append_population( t=0, current_epsilon=42.97, population=population, nr_simulations=10, model_names=[""], ) # just call history.get_distribution(0, 0) # test whether weights and distances returned correctly weighted_distances_h = history.get_weighted_distances() weighted_distances = population.get_weighted_distances() assert np.allclose( weighted_distances_h[['distance', 'w']], weighted_distances[['distance', 'w']], ) weights, sum_stats = history.get_weighted_sum_stats(t=0) # all particles should be contained nonetheless assert len(weights) == len(particle_list) for sum_stat in sum_stats: # should be empty assert not sum_stat history.get_population_extended()
def test_population_to_df(history: History): # TODO this test is not very good yet for t in range(3): for m in range(4): history.append_population(t, .23, Population(rand_pop(m)), 234, ["m0", "m1", "m2", "m3"]) df = history.get_population_extended(m=0) df_js = sumstat_to_json(df) assert len(df) == len(df_js)