示例#1
0
    def _op_method(self, input_data, extra_factor=1.0, rank=None):
        """Operator.

        This method returns the input data after the singular values have been
        thresholded.

        Parameters
        ----------
        input_data : numpy.ndarray
            Input data array
        extra_factor : float
            Additional multiplication factor (default is ``1.0``)
        rank: int, optional
            Estimation of the rank to save computation time in standard mode,
            if not set an internal estimation is used.

        Returns
        -------
        numpy.ndarray
            SVD thresholded data

        Raises
        ------
        ValueError
            if lowr_type is not in ``{'standard', 'ngole'}``
        """
        # Update threshold with extra factor.
        threshold = self.thresh * extra_factor
        if self.lowr_type == 'standard' and self.rank is None and rank is None:
            data_matrix = svd_thresh(
                cube2matrix(input_data),
                threshold,
                thresh_type=self.thresh_type,
            )
        elif self.lowr_type == 'standard':
            data_matrix, update_rank = svd_thresh_coef_fast(
                cube2matrix(input_data),
                threshold,
                n_vals=rank or self.rank,
                extra_vals=5,
                thresh_type=self.thresh_type,
            )
            self.rank = update_rank  # save for future use

        elif self.lowr_type == 'ngole':
            data_matrix = svd_thresh_coef(
                cube2matrix(input_data),
                self.operator,
                threshold,
                thresh_type=self.thresh_type,
            )
        else:
            raise ValueError('lowr_type should be standard or ngole')

        # Return updated data.
        return matrix2cube(data_matrix, input_data.shape[1:])
示例#2
0
 def test_cube2matrix(self):
     """Test cube2matrix."""
     npt.assert_array_equal(
         transform.cube2matrix(self.cube),
         self.matrix,
         err_msg='Incorrect transformation: cube2matrix',
     )
示例#3
0
    def _cost_method(self, *args, **kwargs):
        """Calculate low-rank component of the cost.

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

        Parameters
        ----------
        args : interable
            Positional arguments
        kwargs : dict
            Keyword arguments

        Returns
        -------
        float
            Low-rank cost component

        """
        cost_val = self.thresh * nuclear_norm(cube2matrix(args[0]))

        if 'verbose' in kwargs and kwargs['verbose']:
            print(' - NUCLEAR NORM (X):', cost_val)

        return cost_val
示例#4
0
    def _op_method(self, input_data, extra_factor=1.0):
        """Operator.

        This method returns the input data after the singular values have been
        thresholded.

        Parameters
        ----------
        input_data : numpy.ndarray
            Input data array
        extra_factor : float
            Additional multiplication factor (default is ``1.0``)

        Returns
        -------
        numpy.ndarray
            SVD thresholded data

        """
        # Update threshold with extra factor.
        threshold = self.thresh * extra_factor

        if self.lowr_type == 'standard':
            data_matrix = svd_thresh(
                cube2matrix(input_data),
                threshold,
                thresh_type=self.thresh_type,
            )

        elif self.lowr_type == 'ngole':
            data_matrix = svd_thresh_coef(
                cube2matrix(input_data),
                self.operator,
                threshold,
                thresh_type=self.thresh_type,
            )

        # Return updated data.
        return matrix2cube(data_matrix, input_data.shape[1:])
示例#5
0
    def _cost_method(self, *args, **kwargs):
        """Calculate low-rank component of the cost

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

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

        """

        cost_val = self.thresh * nuclear_norm(cube2matrix(args[0]))

        if 'verbose' in kwargs and kwargs['verbose']:
            print(' - NUCLEAR NORM (X):', cost_val)

        return cost_val