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)
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))