def wcosamp(Operator, y, w, s, eta, maxiter): x = np.zeros(Operator.n) u = np.zeros(Operator.n) U_old = [] last_norm = np.inf k = 0 while k < s: if k > maxiter: print("WCoSaMP did not converge after {0} iterations.".format(k)) break x, S = weighted_quasi_abslargest(u, 3 * s, w) U = list(set(S).union(weighted_quasi_abslargest(Operator.apply_adj(y - Operator.apply(x)), 2 * (3 * s), w)[1])) if set(U) == set(U_old): break SubMatrix = Operator.genSubMatrix(U) u = np.zeros(Operator.n) u[U] = np.linalg.lstsq(SubMatrix, y)[0] U_old = U k = k + 1 return Result(x, k, "Weighted CoSaMP")
def whtp(Operator, y, w, s, eta, maxiter): x = np.zeros(Operator.n) S_old = np.array([]) k = 0 while True: if k > maxiter: print('WHTP did not converge after {0} iterations.'.format(k)) break dummy, S = weighted_quasi_abslargest(x + Operator.apply_adj(y - Operator.apply(x)), 3 * s, w) print('Norm of the error {0}, while the objective norm is {1} and the ratio is {2}'.format(np.linalg.norm(Operator.apply(x) - y),np.linalg.norm(y),np.linalg.norm(Operator.apply(x) - y)/np.linalg.norm(y))) if set(S) == set(S_old) or np.linalg.norm(Operator.apply(x) - y)/np.linalg.norm(y) <= eta: print('WHTP Converged after {0} iterations. Norm of residual {1}'.format(k,np.linalg.norm(Operator.apply(x) - y))) break SubMatrix = Operator.genSubMatrix(S) x = np.zeros(Operator.n) x[S] = np.linalg.lstsq(SubMatrix, y)[0] S_old = S k = k + 1 return Result(x, k, 'Weighted HTP')
def wiht(Operator, y, w, s, eta, maxiter): x = np.zeros(Operator.n) last_norm = 0 k = 0 while np.linalg.norm(Operator.apply(x) - y) > eta: residuum = y - Operator.apply(x) cur_norm = np.linalg.norm(residuum) x, dummy = weighted_quasi_abslargest(x + Operator.apply_adj(residuum), 3 * s, w) last_norm = cur_norm k = k + 1 if k > maxiter: print('WIHT did not converge after {0} iterations.'.format(k)) break return Result(x, k, 'Weighted Iterative Hard Thresholding')