Example #1
0
 def test_chain_not_accepted_within_bounds(self):
     accept = 0
     outsidebounds = 0
     CL = {
         'theta': np.array([1.0, 2.0]),
         'ss': 1.0,
         'prior': 0.0,
         'sigma2': 0.0
     }
     parset = ParameterSet(theta=CL['theta'],
                           ss=CL['ss'],
                           prior=CL['prior'],
                           sigma2=CL['sigma2'])
     mcstat = gf.setup_initialize_chains(CL)
     mcstat._MCMC__rejected = {
         'total': 10,
         'in_adaptation_interval': 4,
         'outside_bounds': 1
     }
     mcstat._MCMC__update_chain(accept=accept,
                                new_set=parset,
                                outsidebounds=outsidebounds)
     self.assertTrue(np.array_equal(mcstat._MCMC__chain[-1, :],
                                    mcstat._MCMC__old_set.theta),
                     msg=str('theta added to end of chain - {}'.format(
                         mcstat._MCMC__chain[-1, :])))
Example #2
0
 def test_initialize_chain_updatesigma_1_nsos_2(self):
     CL = self.setup_CL()
     mcstat = gf.setup_initialize_chains(CL, nsos=2)
     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, 2),
                      msg=str('Shape should be (nsimu,2) -> {}'.format(
                          mcstat._MCMC__sschain.shape)))
     self.assertEqual(mcstat._MCMC__s2chain.shape,
                      (mcstat.simulation_options.nsimu, 2),
                      msg=str('Shape should be (nsimu,2) -> {}'.format(
                          mcstat._MCMC__s2chain.shape)))
Example #3
0
 def test_initialize_chain_updatesigma_0(self):
     CL = self.setup_CL()
     mcstat = gf.setup_initialize_chains(CL, updatesigma=False)
     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,
                      None,
                      msg=str('s2chain should be None -> {}'.format(
                          mcstat._MCMC__s2chain)))
Example #4
0
 def test_expand_chain_updatesigma_1_nsos_2(self):
     CL = self.setup_CL()
     mcstat = gf.setup_initialize_chains(CL, nsos=2)
     mcstat._MCMC__expand_chains(
         nsimu=mcstat.simulation_options.nsimu,
         npar=mcstat.parameters.npar,
         nsos=mcstat.model_settings.nsos,
         updatesigma=mcstat.simulation_options.updatesigma)
     self.assertEqual(mcstat._MCMC__chain.shape,
                      (mcstat.simulation_options.nsimu * 2 - 1, 2),
                      msg=str('Shape should be (nsimu,2) -> {}'.format(
                          mcstat._MCMC__chain.shape)))
     self.assertEqual(mcstat._MCMC__sschain.shape,
                      (mcstat.simulation_options.nsimu * 2 - 1, 2),
                      msg=str('Shape should be (nsimu,2) -> {}'.format(
                          mcstat._MCMC__sschain.shape)))
     self.assertEqual(mcstat._MCMC__s2chain.shape,
                      (mcstat.simulation_options.nsimu * 2 - 1, 2),
                      msg=str('Shape should be (nsimu,2) -> {}'.format(
                          mcstat._MCMC__s2chain.shape)))
Example #5
0
 def test_chain_accepted(self):
     accept = 1
     outsidebounds = 0
     CL = {
         'theta': np.array([1.0, 2.0]),
         'ss': 1.0,
         'prior': 0.0,
         'sigma2': 0.0
     }
     parset = ParameterSet(theta=CL['theta'],
                           ss=CL['ss'],
                           prior=CL['prior'],
                           sigma2=CL['sigma2'])
     mcstat = gf.setup_initialize_chains(CL)
     mcstat._MCMC__update_chain(accept=accept,
                                new_set=parset,
                                outsidebounds=outsidebounds)
     self.assertTrue(np.array_equal(mcstat._MCMC__chain[-1, :],
                                    parset.theta),
                     msg=str('theta added to end of chain - {}'.format(
                         mcstat._MCMC__chain[-1, :])))
     self.assertEqual(mcstat._MCMC__old_set,
                      parset,
                      msg='old_set updated to new set')