def test_svd_thresh_coef(self): """Test svd_thresh_coef.""" npt.assert_almost_equal( svd.svd_thresh_coef(self.data1, lambda x_val: x_val, 0), self.data1, err_msg='Incorrect SVD coefficient tresholding', ) npt.assert_raises(TypeError, svd.svd_thresh_coef, self.data1, 0, 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:])
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:])