Beispiel #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
Beispiel #2
0
 def __init__(self, surrogate, target, momentum, num_steps_min=10, num_steps_max=100, step_size_min=0.05,
              step_size_max=0.3, adaptation_schedule=None, acc_star=0.7):
     """
     """
     HMCBase.__init__(self, target, momentum, num_steps_min, num_steps_max, step_size_min, step_size_max,
                      adaptation_schedule, acc_star)
     
     assert_implements_log_pdf_and_grad(surrogate)
     
     self.surrogate = surrogate
     self.target = surrogate
     self.orig_target = target
Beispiel #3
0
    def __init__(self, target, D, step_size, adaptation_schedule, acc_star):
        self.target = target
        self.D = D
        self.step_size = step_size
        self.adaptation_schedule = adaptation_schedule
        self.acc_star = acc_star

        self.t = 0

        # some sanity checks
        assert acc_star is None or acc_star > 0 and acc_star < 1
        if adaptation_schedule is not None:
            lmbdas = np.array([adaptation_schedule(t) for t in np.arange(100)])
            assert np.all(lmbdas >= 0)
            assert np.allclose(np.sort(lmbdas)[::-1], lmbdas)

        assert_implements_log_pdf_and_grad(target, assert_grad=False)
Beispiel #4
0
 def __init__(self, target, D, step_size, adaptation_schedule, acc_star):
     self.target = target
     self.D = D
     self.step_size = step_size
     self.adaptation_schedule = adaptation_schedule
     self.acc_star = acc_star
     
     self.t = 0
     
     # some sanity checks
     assert acc_star is None or acc_star > 0 and acc_star < 1
     if adaptation_schedule is not None:
         lmbdas = np.array([adaptation_schedule(t) for t in  np.arange(100)])
         assert np.all(lmbdas >= 0)
         assert np.allclose(np.sort(lmbdas)[::-1], lmbdas)
 
     assert_implements_log_pdf_and_grad(target, assert_grad=False)
Beispiel #5
0
    def __init__(self,
                 surrogate,
                 target,
                 momentum,
                 num_steps_min=10,
                 num_steps_max=100,
                 step_size_min=0.05,
                 step_size_max=0.3,
                 adaptation_schedule=None,
                 acc_star=0.7):
        """
        """
        HMCBase.__init__(self, target, momentum, num_steps_min, num_steps_max,
                         step_size_min, step_size_max, adaptation_schedule,
                         acc_star)

        assert_implements_log_pdf_and_grad(surrogate)

        self.surrogate = surrogate
        self.target = surrogate
        self.orig_target = target
Beispiel #6
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