Example #1
0
 def test_init_walkers_incorrect_theta_std(self):
     oscN, nH = 4, 3
     theta_init = self.random_theta(oscN, nH)
     theta_std = self.random_theta(oscN, nH + 1)
     mcmc = KurslMCMC(theta_init)
     with self.assertRaises(ValueError) as error:
         mcmc._init_walkers(theta_init, theta_std)
     self.assertTrue("Incorrect shape" in str(error.exception))
Example #2
0
    def test_init_walkers(self):
        theta_init = np.array([
            [115, 0, 3, 0, 1, 2, 0, -1, -3],
            [120, 1, 2, -1, 0, 1, 2, -3, 2],
            [135, 2, 9, -2, -2, -2, 0, -2, 0],
        ],
                              dtype=np.float64)
        oscN, paramN = theta_init.shape
        nH = int((paramN - 3) / (oscN - 1))
        self.assertEqual(nH, 3)
        theta_std = np.random.random((oscN, paramN))

        mcmc = KurslMCMC(theta_init)
        mcmc._init_walkers(theta_init, theta_std)
        nwalkers = mcmc.nwalkers

        self.assertEqual(mcmc.init_pos.shape, (nwalkers, oscN * paramN))
        self.assertTrue(
            np.all(mcmc.init_pos[0] == theta_init.flatten()),
            "First walker should have the same values as passed. "
            "First walkers:\n{}\nPassed:\n{}".format(mcmc.init_pos[0],
                                                     theta_init))