def test_setup_simu_use_json_file(self, mock_json_object): mcstat = gf.setup_mcmc_case_cp(initialize=False) mcstat.simulation_options.json_restart_file = 1 mcstat._MCMC__setup_simulator(use_previous_results=False) self.assertTrue(np.array_equal( mcstat.simulation_options.qcov, np.array([[0.2, 0.1, 0.05], [0.1, 0.4, 0.02], [0.05, 0.02, 0.6]])), msg='Expect arrays to match') self.assertEqual(mcstat.parameters.parameters[0]['theta0'], 0.2, msg='Expect theta0 = 0.2') self.assertEqual(mcstat.parameters.parameters[1]['theta0'], -5.0, msg='Expect theta0 = -5.0 because sample = 0') self.assertEqual(mcstat.parameters.parameters[2]['theta0'], 0.7, msg='Expect theta0 = 0.7') self.assertEqual(mcstat._MCMC__chain_index, 0, msg='Chain index should be 0') self.assertEqual(mcstat._MCMC__chain.shape, (mcstat.simulation_options.nsimu, 2), msg=str('Shape should be (nsimu,2) -> {}'.format( mcstat._MCMC__chain.shape))) self.assertEqual(mcstat._MCMC__sschain.shape, (mcstat.simulation_options.nsimu, 1), msg=str('Shape should be (nsimu,1) -> {}'.format( mcstat._MCMC__sschain.shape))) self.assertEqual(mcstat._MCMC__s2chain.shape, (mcstat.simulation_options.nsimu, 1), msg=str('Shape should be (nsimu,1) -> {}'.format( mcstat._MCMC__s2chain.shape)))
def test_standard_print(self): mcstat = gf.setup_mcmc_case_cp() capturedOutput = io.StringIO() # Create StringIO object sys.stdout = capturedOutput # and redirect stdout. mcstat.display_current_mcmc_settings() sys.stdout = sys.__stdout__ # Reset redirect. self.assertTrue(isinstance(capturedOutput.getvalue(), str), msg='Caputured string')
def common_setup(cls): mcstat = gf.setup_mcmc_case_cp() rejectedin = { 'total': 10, 'in_adaptation_interval': 4, 'outside_bounds': 1 } mcstat._MCMC__rejected = rejectedin.copy() return mcstat, rejectedin
def setup_pseudo_results(initialize=True): mcstat = gf.setup_mcmc_case_cp(initialize=initialize) rejectedin = { 'total': 10, 'in_adaptation_interval': 4, 'outside_bounds': 1 } mcstat._MCMC__rejected = rejectedin.copy() mcstat._MCMC__simulation_time = 0.1 return mcstat
def test_cpwe_creation_with_txt(self): mcstat = gf.setup_mcmc_case_cp() mcstat.simulation_options.savedir = 'test' chainfile, s2chainfile, sschainfile, covchainfile = CP._create_path_with_extension_for_all_logs( options=mcstat.simulation_options, extension='txt') self.assertEqual(chainfile, 'test/chainfile.txt', msg='Expect matching string') self.assertEqual(s2chainfile, 'test/s2chainfile.txt', msg='Expect matching string') self.assertEqual(sschainfile, 'test/sschainfile.txt', msg='Expect matching string') self.assertEqual(covchainfile, 'test/covchainfile.txt', msg='Expect matching string')
def test_setup_simu_use_prev_false(self): mcstat = gf.setup_mcmc_case_cp(initialize=False) mcstat._MCMC__setup_simulator(use_previous_results=False) self.assertEqual(mcstat._MCMC__chain_index, 0, msg='Chain index should be 0') self.assertEqual(mcstat._MCMC__chain.shape, (mcstat.simulation_options.nsimu, 2), msg=str('Shape should be (nsimu,2) -> {}'.format( mcstat._MCMC__chain.shape))) self.assertEqual(mcstat._MCMC__sschain.shape, (mcstat.simulation_options.nsimu, 1), msg=str('Shape should be (nsimu,1) -> {}'.format( mcstat._MCMC__sschain.shape))) self.assertEqual(mcstat._MCMC__s2chain.shape, (mcstat.simulation_options.nsimu, 1), msg=str('Shape should be (nsimu,1) -> {}'.format( mcstat._MCMC__s2chain.shape)))
def test_setup_simu_use_prev_true_causes_error(self): mcstat = gf.setup_mcmc_case_cp(initialize=False) with self.assertRaises(SystemExit, msg='No previous results exist'): mcstat._MCMC__setup_simulator(use_previous_results=True)