コード例 #1
0
    def test_run_default(self):
        _cos = lambda l: l[2] * np.cos(l[0] * t + l[1])
        theta = [
            [15, 0, 1, 0],
            [35, 2, 3, 0],
        ]
        theta_std = [
            [1.0, 0.1, 0.8, 0.01],
            [1.5, 0.1, 1.5, 0.01],
        ]
        theta, theta_std = np.array(theta), np.array(theta_std)
        t = np.linspace(0, 1, 100)
        c1 = _cos(theta[0])
        c2 = _cos(theta[1])
        S = c1 + c2

        theta_init = np.array(theta, dtype=np.float64)
        theta_init[:, 0] += 2 - np.random.random(2) * 0.5
        theta_init[:, 2] += 1 - np.random.random(2) * 0.5
        mcmc = KurslMCMC(theta_init, theta_std, nwalkers=40, niter=200)
        mcmc.set_threshold(0.001)
        mcmc.set_sampler(t, S)
        mcmc.run()

        # After simulation is finished check for correctness
        theta_computed = mcmc.get_theta()
        self.assertTrue(
            np.allclose(theta, theta_computed, atol=0.5),
            "Expected:\n{}\nReceived:\n{}".format(theta, theta_computed))
コード例 #2
0
 def test_set_threshold(self):
     theta_init = self.random_theta(5, 1)
     mcmc = KurslMCMC(theta_init)
     self.assertEqual(mcmc.THRESHOLD, 0.05)
     self.assertEqual(mcmc.model.THRESHOLD, 0.05)
     mcmc.set_threshold(0.1)
     self.assertEqual(mcmc.THRESHOLD, 0.1)
     self.assertEqual(mcmc.model.THRESHOLD, 0.1)