Esempio n. 1
0
 def __init__(self, target, momentum, num_steps_min=10, num_steps_max=100, step_size_min=0.05,
              step_size_max=0.3, adaptation_schedule=standard_sqrt_schedule, acc_star=0.7):
     
     if not isinstance(momentum, GaussianBase):
         raise TypeError("Momentum (%s) must be subclass of %s" % \
                         (str(type(momentum)), str(GaussianBase)))
     assert_implements_log_pdf_and_grad(target)
     assert_implements_log_pdf_and_grad(momentum)
     assert_inout_log_pdf_and_grad(target, momentum.D, assert_grad=False)
         
     assert_positive_int(num_steps_min)
     assert_positive_int(num_steps_max)
     if not num_steps_min<=num_steps_max:
         raise ValueError("Minimum number of leapfrog steps (%d) must be larger than maximum number (%d)." % \
                          (num_steps_min, num_steps_max))
     
     assert_positive_float(step_size_min)
     assert_positive_float(step_size_max)
     if not num_steps_min<=num_steps_max:
         raise ValueError("Minimum size of leapfrog steps (%d) must be larger than maximum size (%d)." % \
                          (step_size_min, step_size_max))
     
     step_size = np.array([step_size_min, step_size_max])
     ProposalBase.__init__(self, target, momentum.D, step_size, adaptation_schedule, acc_star)
     
     self.momentum = momentum
     self.num_steps_min = num_steps_min
     self.num_steps_max = num_steps_max
Esempio n. 2
0
    def __init__(self,
                 target,
                 momentum,
                 num_steps_min=10,
                 num_steps_max=100,
                 step_size_min=0.05,
                 step_size_max=0.3,
                 adaptation_schedule=standard_sqrt_schedule,
                 acc_star=0.7):

        if not isinstance(momentum, GaussianBase):
            raise TypeError("Momentum (%s) must be subclass of %s" % \
                            (str(type(momentum)), str(GaussianBase)))
        assert_implements_log_pdf_and_grad(target)
        assert_implements_log_pdf_and_grad(momentum)
        assert_inout_log_pdf_and_grad(target, momentum.D, assert_grad=False)

        assert_positive_int(num_steps_min)
        assert_positive_int(num_steps_max)
        if not num_steps_min <= num_steps_max:
            raise ValueError("Minimum number of leapfrog steps (%d) must be larger than maximum number (%d)." % \
                             (num_steps_min, num_steps_max))

        assert_positive_float(step_size_min)
        assert_positive_float(step_size_max)
        if not num_steps_min <= num_steps_max:
            raise ValueError("Minimum size of leapfrog steps (%d) must be larger than maximum size (%d)." % \
                             (step_size_min, step_size_max))

        step_size = np.array([step_size_min, step_size_max])
        ProposalBase.__init__(self, target, momentum.D, step_size,
                              adaptation_schedule, acc_star)

        self.momentum = momentum
        self.num_steps_min = num_steps_min
        self.num_steps_max = num_steps_max
Esempio n. 3
0
 def __init__(self, D=1):
     assert_positive_int(D)
     self.D = D