def isotropic_gaussian(shape, scale):
        """
        Isotropic Gaussian with SD `scale`.

        Parameters
        ----------

        shape : tuple
            Shape of noise.

        scale : float
            SD of noise.
        """
        rv = ndist(scale=scale, loc=0.)
        density = lambda x: np.product(rv.pdf(x))
        grad_negative_log_density = lambda x: x / scale**2
        sampler = lambda size: rv.rvs(size=shape + size)

        p = np.product(shape)
        constant = -0.5 * p * np.log(2 * np.pi * scale**2)
        return randomization(shape, 
                             density, 
                             grad_negative_log_density, 
                             sampler, 
                             lipschitz=1./scale**2,
                             log_density = lambda x: -0.5 * (np.atleast_2d(x)**2).sum(1) / scale**2 + constant)
Beispiel #2
0
 def isotropic_gaussian(shape, scale):
     rv = ndist(scale=scale, loc=0.)
     density = lambda x: rv.pdf(x)
     grad_negative_log_density = lambda x: x / scale**2
     sampler = lambda size: rv.rvs(size=shape + size)
     return randomization(shape, density, grad_negative_log_density,
                          sampler)
Beispiel #3
0
    def __init__(self, initial_condition, gradient_map, projection_map,
                 stepsize):

        (self.state, self.gradient_map, self.projection_map,
         self.stepsize) = (np.copy(initial_condition), gradient_map,
                           projection_map, stepsize)
        self._shape = self.state.shape[0]
        self._sqrt_step = np.sqrt(self.stepsize)
        self._noise = ndist(loc=0, scale=1)
    def __init__(self, initial_condition, gradient_map, proposal_scale,
                 stepsize, scaling):

        (self.state, self.gradient_map,
         self.stepsize) = (np.copy(initial_condition), gradient_map, stepsize)
        self.proposal_scale = proposal_scale
        self._shape = self.state.shape[0]
        self._sqrt_step = np.sqrt(self.stepsize)
        self._noise = ndist(loc=0, scale=1)
        self.sample = np.copy(initial_condition)
        self.scaling = scaling

        self.proposal_sqrt = fractional_matrix_power(self.proposal_scale, 0.5)
    def isotropic_gaussian(shape, scale):
        """
        Isotropic Gaussian with SD `scale`.
        Parameters
        ----------
        shape : tuple
            Shape of noise.
        scale : float
            SD of noise.
        """
        if type(shape) == type(1):
            shape = (shape, )
        rv = ndist(scale=scale, loc=0.)
        p = np.product(shape)
        density = lambda x: np.product(rv.pdf(x))
        cdf = lambda x: rv.cdf(x)
        pdf = lambda x: rv.pdf(x)
        derivative_log_density = lambda x: -x / (scale**2)
        grad_negative_log_density = lambda x: x / scale**2
        sampler = lambda size: rv.rvs(size=shape + size)
        CGF = isotropic_gaussian_CGF(shape, scale)
        CGF_conjugate = isotropic_gaussian_CGF_conjugate(shape, scale)

        p = np.product(shape)
        constant = 0  # -0.5 * p * np.log(2 * np.pi * scale**2)
        return randomization(
            shape,
            density,
            cdf,
            pdf,
            derivative_log_density,
            grad_negative_log_density,
            sampler,
            lipschitz=1. / scale**2,
            log_density=lambda x: -0.5 *
            (np.atleast_2d(x)**2).sum(1) / scale**2 + constant,
            CGF=CGF,
            CGF_conjugate=CGF_conjugate,
            cov_prec=(scale**2, 1. / scale**2))