Exemplo n.º 1
0
 def __init__(self, neg_log_dens, grad_neg_log_dens=None):
     """
     Args:
         neg_log_dens (Callable[[array], float]): Function which given a
             position array returns the negative logarithm of an
             unnormalised probability density on the position space with
             respect to the Lebesgue measure, with the corresponding
             distribution on the position space being the target
             distribution it is wished to draw approximate samples from.
         grad_neg_log_dens (
                 None or Callable[[array], array or Tuple[array, float]]):
             Function which given a position array returns the derivative of
             the negative logarithm of the unnormalised density specified by
             `neg_log_dens` with respect to the position array argument.
             Optionally the function may instead return a pair of values
             with the first being the array corresponding to the derivative
             and the second being the value of the `neg_log_dens` evaluated
             at the passed position array. If `None` is passed (the default)
             an automatic differentiation fallback will be used to attempt
             to construct the derivative of `neg_log_dens` automatically.
     """
     self._neg_log_dens = neg_log_dens
     self._grad_neg_log_dens = autodiff_fallback(grad_neg_log_dens,
                                                 neg_log_dens,
                                                 'grad_and_value',
                                                 'grad_neg_log_dens')
Exemplo n.º 2
0
 def __init__(self,
              neg_log_dens,
              grad_neg_log_dens=None,
              hess_neg_log_dens=None,
              mtp_neg_log_dens=None,
              softabs_coeff=1.):
     self._hess_neg_log_dens = autodiff_fallback(hess_neg_log_dens,
                                                 neg_log_dens,
                                                 'hessian_grad_and_value',
                                                 'neg_log_dens')
     self._mtp_neg_log_dens = autodiff_fallback(
         mtp_neg_log_dens, neg_log_dens, 'mtp_hessian_grad_and_value',
         'mtp_neg_log_dens')
     super().__init__(neg_log_dens,
                      SoftAbsRegularisedPositiveDefiniteMatrix,
                      self._hess_neg_log_dens,
                      self._mtp_neg_log_dens,
                      grad_neg_log_dens,
                      metric_kwargs={'softabs_coeff': softabs_coeff})
Exemplo n.º 3
0
 def __init__(self,
              neg_log_dens,
              metric_matrix_class,
              metric_func,
              vjp_metric_func=None,
              grad_neg_log_dens=None,
              metric_kwargs=None):
     self._metric_matrix_class = metric_matrix_class
     self._metric_func = metric_func
     self._vjp_metric_func = autodiff_fallback(vjp_metric_func, metric_func,
                                               'vjp_and_value',
                                               'vjp_metric_func')
     self._metric_kwargs = {} if metric_kwargs is None else metric_kwargs
     super().__init__(neg_log_dens, grad_neg_log_dens)
Exemplo n.º 4
0
 def __init__(self,
              neg_log_dens,
              constr,
              metric=None,
              dens_wrt_hausdorff=True,
              grad_neg_log_dens=None,
              jacob_constr=None):
     super().__init__(neg_log_dens=neg_log_dens,
                      metric=metric,
                      grad_neg_log_dens=grad_neg_log_dens)
     self._constr = constr
     self.dens_wrt_hausdorff = dens_wrt_hausdorff
     self._jacob_constr = autodiff_fallback(jacob_constr, constr,
                                            'jacobian_and_value',
                                            'jacob_constr')
Exemplo n.º 5
0
 def __init__(self,
              neg_log_dens,
              constr,
              metric=None,
              dens_wrt_hausdorff=True,
              grad_neg_log_dens=None,
              jacob_constr=None,
              mhp_constr=None):
     super().__init__(neg_log_dens=neg_log_dens,
                      constr=constr,
                      metric=metric,
                      dens_wrt_hausdorff=dens_wrt_hausdorff,
                      grad_neg_log_dens=grad_neg_log_dens,
                      jacob_constr=jacob_constr)
     if not dens_wrt_hausdorff:
         self._mhp_constr = autodiff_fallback(mhp_constr, constr,
                                              'mhp_jacobian_and_value',
                                              'mhp_constr')