Beispiel #1
0
    def lowr_comp(self, x):
        """Calculate low-rank component of the cost

        This method returns the nuclear norm error of the deconvolved data in
        matrix form

        Parameters
        ----------
        x : np.ndarray
            Deconvolved data array

        Returns
        -------
        float low-rank cost component

        """

        x_prime = cube2matrix(x)

        nuc_norm = nuclear_norm(x_prime)

        if self.verbose:
            print(' - NUCLEAR NORM:', nuc_norm)

        return self.lambda_lowr * nuc_norm
Beispiel #2
0
        def func(x):

            HX = cube2matrix(self.H_op(x))

            StSHX = self._St.dot(self._S.dot(HX))

            return (self.Ht_op(self.H_op(x)) + self.lambda_reg *
                    self.Ht_op(matrix2cube(StSHX, x[0].shape)))
def svd_thresh_coef(data, operator, threshold, thresh_type='hard'):
    """Threshold the singular values coefficients

    This method thresholds the input data using singular value decomposition

    Parameters
    ----------
    data : np.ndarray
        Input data array
    operator : class
        Operator class instance
    threshold : float, optional
        Threshold value
    threshold_type : str {'hard', 'soft'}
        Type of noise to be added (default is 'hard')

    Returns
    -------
    np.ndarray thresholded data

    Raises
    ------
    ValueError
        For invalid string entry for n_pc

    """

    # Convert data cube to matrix.
    data_matrix = cube2matrix(data)

    # Get SVD of data matrix.
    u, s, v = np.linalg.svd(data_matrix, full_matrices=False)

    # Compute coefficients.
    a = np.dot(np.diag(s), v)

    # Compute threshold matrix.
    u_cube = matrix2cube(u, data.shape[1:])
    ti = np.array([np.linalg.norm(x) for x in operator(u_cube)])
    ti = np.repeat(ti, a.shape[1]).reshape(a.shape)
    threshold *= ti

    # Remove noise from coefficients.
    a_new = thresh(a, threshold, thresh_type)

    # Return the thresholded image.
    return np.dot(u, a_new)
Beispiel #4
0
    def _calc_shape_grad(self, x):
        """Get the gradient of the shape constraint component

        This method calculates the gradient value of the shape constraint
        component

        Parameters
        ----------
        x : np.ndarray
            Input data array, an array of recovered 2D images

        """

        HXY = cube2matrix(self.H_op(x) - self._y)

        StSHXY = self._St.dot(self._S.dot(HXY))

        return self.Ht_op(matrix2cube(StSHXY, x[0].shape))
Beispiel #5
0
    def __init__(self, data, psf, psf_type='fixed', lambda_reg=1):

        self.grad_type = 'shape'
        self._y = np.copy(data)
        self._psf = np.copy(psf)
        self._psf_type = psf_type
        self.lambda_reg = lambda_reg
        self._St = cube2matrix(shape_project(data.shape[1:]))
        self._S = self._St.T

        def func(x):

            HX = cube2matrix(self.H_op(x))

            StSHX = self._St.dot(self._S.dot(HX))

            return (self.Ht_op(self.H_op(x)) + self.lambda_reg *
                    self.Ht_op(matrix2cube(StSHX, x[0].shape)))

        PowerMethod.__init__(self, func, self._y.shape)