def test_history_file_loading(self): """Test that when a history file is provided it is loaded and appended to the new history.""" self.param, self.like = onedmodel() model = Model(self.like, self.param) step = Dream(model=model) old_history = np.array([1, 3, 5, 7, 9, 11]) step.save_history_to_disc(old_history, 'testing_history_load_') sampled_params, logps = run_dream(self.param, self.like, niterations=3, nchains=3, history_thin=1, history_file='testing_history_load_DREAM_chain_history.npy', save_history=True, model_name='test_history_loading', verbose=False) new_history = np.load('test_history_loading_DREAM_chain_history.npy') self.assertEqual(len(new_history), (len(old_history.flatten())+(3*step.total_var_dimension*3))) new_history_seed = new_history[:len(old_history.flatten())] new_history_seed_reshaped = new_history_seed.reshape(old_history.shape) self.assertIs(np.array_equal(old_history, new_history_seed_reshaped), True) added_history = new_history[len(old_history.flatten())::] sorted_history = np.sort(added_history) sorted_sampled_params = np.sort(np.array(sampled_params).flatten()) for sampled_param, history_param in zip(sorted_history, sorted_sampled_params): self.assertEqual(sampled_param, history_param) remove('testing_history_load_DREAM_chain_history.npy') remove('testing_history_load_DREAM_chain_adapted_crossoverprob.npy') remove('testing_history_load_DREAM_chain_adapted_gammalevelprob.npy') remove('test_history_loading_DREAM_chain_adapted_crossoverprob.npy') remove('test_history_loading_DREAM_chain_adapted_gammalevelprob.npy') remove('test_history_loading_DREAM_chain_history.npy')
def test_history_saving_to_disc_sanitycheck(self): """Test that history when saved to disc and reloaded matches.""" self.param, self.like = multidmodel() model = Model(self.like, self.param) step = Dream(model=model) history = np.array([[5, 8, 10, 12], [13, 18, 20, 21], [1, .5, 9, 1e9]]) step.save_history_to_disc(history, 'testing_history_save_') history_saved = np.load('testing_history_save_DREAM_chain_history.npy') self.assertIs(np.array_equal(history, history_saved), True) remove('testing_history_save_DREAM_chain_history.npy') remove('testing_history_save_DREAM_chain_adapted_crossoverprob.npy') remove('testing_history_save_DREAM_chain_adapted_gammalevelprob.npy')