Exemplo n.º 1
0
 def test_errors(self):
     with self.assertRaises(TypeError):
         LeapFrog(
             model=self.test_model,
             position=1,
             momentum=[1, 1],
             stepsize=0.1,
             grad_log_pdf=GradLogPDFGaussian,
         )
     with self.assertRaises(TypeError):
         LeapFrog(
             model=self.test_model,
             position=[1, 1],
             momentum=1,
             stepsize=0.1,
             grad_log_pdf=GradLogPDFGaussian,
         )
     with self.assertRaises(ValueError):
         LeapFrog(
             model=self.test_model,
             position=[1, 1],
             momentum=[1],
             stepsize=0.1,
             grad_log_pdf=GradLogPDFGaussian,
         )
     with self.assertRaises(TypeError):
         LeapFrog(
             model=self.test_model,
             position=[1],
             momentum=[1],
             stepsize=0.1,
             grad_log_pdf=1,
         )
     with self.assertRaises(ValueError):
         LeapFrog(
             model=self.test_model,
             position=[1, 1],
             momentum=[1, 1],
             stepsize=0.1,
             grad_log_pdf=GradLogPDFGaussian,
         )
     with self.assertRaises(TypeError):
         LeapFrog(
             model=self.test_model,
             position=[1, 1, 1],
             momentum=[1, 1, 1],
             stepsize=0.1,
             grad_log_pdf=GradLogPDFGaussian,
             grad_log_position=1,
         )
     with self.assertRaises(ValueError):
         LeapFrog(
             model=self.test_model,
             position=[1, 1, 1],
             momentum=[1, 1, 1],
             stepsize=0.1,
             grad_log_pdf=GradLogPDFGaussian,
             grad_log_position=[1, 1],
         )
Exemplo n.º 2
0
 def setUp(self):
     mean = np.array([-1, 1, -1])
     covariance = np.array([[1, 0.6, 0.5], [0.6, 2, 0.3], [0.5, 0.3, 1]])
     self.test_model = JGD(['x', 'y', 'z'], mean, covariance)
     position = [0, 0, 0]
     momentum = [-1, -1, -1]
     self.test_with_grad_log = LeapFrog(model=self.test_model,
                                        position=position,
                                        momentum=momentum,
                                        stepsize=0.3,
                                        grad_log_pdf=GradLogPDFGaussian,
                                        grad_log_position=None)
     grad_log_position, _ = GradLogPDFGaussian(
         position, self.test_model).get_gradient_log_pdf()
     self.test_without_grad_log = LeapFrog(
         model=self.test_model,
         position=position,
         momentum=momentum,
         stepsize=0.4,
         grad_log_pdf=GradLogPDFGaussian,
         grad_log_position=grad_log_position)