Beispiel #1
0
 def setUp(self):
     mean = np.array([-1, 1, 0])
     covariance = np.array([[6, 0.7, 0.2], [0.7, 3, 0.9], [0.2, 0.9, 1]])
     self.test_model = JGD(["x", "y", "z"], mean, covariance)
     self.nuts_sampler = NUTSda(
         model=self.test_model, grad_log_pdf=GradLogPDFGaussian
     )
Beispiel #2
0
 def test_errors(self):
     with self.assertRaises(TypeError):
         NUTS(model=self.test_model, grad_log_pdf=JGD)
     with self.assertRaises(TypeError):
         NUTS(model=self.test_model, grad_log_pdf=None, simulate_dynamics=GradLogPDFGaussian)
     with self.assertRaises(ValueError):
         NUTSda(model=self.test_model, delta=-0.2, grad_log_pdf=None)
     with self.assertRaises(ValueError):
         NUTSda(model=self.test_model, delta=1.1, grad_log_pdf=GradLogPDFGaussian)
     with self.assertRaises(TypeError):
         NUTS(self.test_model, GradLogPDFGaussian).sample(initial_pos={1, 1, 1}, num_samples=1)
     with self.assertRaises(ValueError):
         NUTS(self.test_model, GradLogPDFGaussian).sample(initial_pos=[1, 1], num_samples=1)
     with self.assertRaises(TypeError):
         NUTSda(self.test_model, GradLogPDFGaussian).sample(initial_pos=1, num_samples=1, num_adapt=1)
     with self.assertRaises(ValueError):
         NUTSda(self.test_model, GradLogPDFGaussian).sample(initial_pos=[1, 1, 1, 1], num_samples=1, num_adapt=1)
     with self.assertRaises(TypeError):
         NUTS(self.test_model, GradLogPDFGaussian).generate_sample(initial_pos=0.1, num_samples=1).send(None)
     with self.assertRaises(ValueError):
         NUTS(self.test_model, GradLogPDFGaussian).generate_sample(initial_pos=(0, 1, 1, 1),
                                                                   num_samples=1).send(None)
     with self.assertRaises(TypeError):
         NUTSda(self.test_model, GradLogPDFGaussian).generate_sample(initial_pos=[[1, 2, 3]], num_samples=1,
                                                                     num_adapt=1).send(None)
     with self.assertRaises(ValueError):
         NUTSda(self.test_model, GradLogPDFGaussian).generate_sample(initial_pos=[1], num_samples=1,
                                                                     num_adapt=1).send(None)