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:])
def test_svd_thresh(self): """Test svd_thresh.""" npt.assert_almost_equal( svd.svd_thresh(self.data1), self.data4, err_msg='Incorrect SVD tresholding', ) npt.assert_almost_equal( svd.svd_thresh(self.data1, n_pc=1), self.data5, err_msg='Incorrect SVD tresholding', ) npt.assert_almost_equal( svd.svd_thresh(self.data1, n_pc='all'), self.data1, err_msg='Incorrect SVD tresholding', ) npt.assert_raises(TypeError, svd.svd_thresh, 1) npt.assert_raises(ValueError, svd.svd_thresh, self.data1, n_pc='bla')
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:])