Ejemplo n.º 1
0
    def test_method(self):

        # Create mcmc
        x0 = self.real_parameters * 1.1
        mcmc = pints.RaoBlackwellACMC(x0)

        # Configure
        mcmc.set_target_acceptance_rate(0.3)
        mcmc.set_initial_phase(True)

        # Perform short run
        rate = []
        chain = []
        for i in range(100):
            x = mcmc.ask()
            fx = self.log_posterior(x)
            sample = mcmc.tell(fx)
            if i == 20:
                mcmc.set_initial_phase(False)
            if i >= 50:
                chain.append(sample)
            rate.append(mcmc.acceptance_rate())
            if np.all(sample == x):
                self.assertEqual(mcmc.current_log_pdf(), fx)

        chain = np.array(chain)
        rate = np.array(rate)
        self.assertEqual(chain.shape[0], 50)
        self.assertEqual(chain.shape[1], len(x0))
        self.assertEqual(rate.shape[0], 100)
Ejemplo n.º 2
0
    def test_method(self):

        # Create mcmc
        x0 = self.real_parameters * 1.1
        mcmc = pints.RaoBlackwellACMC(x0)

        # Configure
        mcmc.set_target_acceptance_rate(0.3)
        mcmc.set_initial_phase(True)

        # Perform short run
        rate = []
        chain = []
        for i in range(100):
            x = mcmc.ask()
            fx = self.log_posterior(x)
            y, fy, ac = mcmc.tell(fx)
            if i == 20:
                mcmc.set_initial_phase(False)
            if i >= 50:
                chain.append(y)
            rate.append(mcmc.acceptance_rate())
            self.assertTrue(isinstance(ac, bool))
            if ac:
                self.assertTrue(np.all(x == y))
                self.assertEqual(fx, fy)

        chain = np.array(chain)
        rate = np.array(rate)
        self.assertEqual(chain.shape[0], 50)
        self.assertEqual(chain.shape[1], len(x0))
        self.assertEqual(rate.shape[0], 100)
Ejemplo n.º 3
0
 def test_name(self):
     # Test name method
     mcmc = pints.RaoBlackwellACMC(self.real_parameters)
     self.assertEqual(mcmc.name(), 'Rao-Blackwell adaptive covariance MCMC')
Ejemplo n.º 4
0
 def test_hyperparameters(self):
     # Hyperparameters unchanged from base class
     mcmc = pints.RaoBlackwellACMC(self.real_parameters)
     self.assertEqual(mcmc.n_hyper_parameters(), 1)