-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathiterative_hardthresholding.m
37 lines (36 loc) · 1.36 KB
/
iterative_hardthresholding.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
% Function:
% - solve the equations with iterative hardthresholding algorithm
%
% InputArg(s):
% - sparseCardinality: number of non-zero values in sparse solution x
% - a: observation matrix
% - y: observation vector with insufficient samples
% - normalizedErrorBound: the maximum tolerable error
%
% OutputArg(s):
% - xIterativeHardthresholding: sparse solution by IHT algorithm
%
% Comments:
% - simply iterate to approach the solution and truncate the result -
% inefficient
%
% Author & Date: Yang (i@snowztail.com) - 02 Nov 18
function [xIterativeHardthresholding] = iterative_hardthresholding(sparseCardinality, a, y, normalizedErrorBound)
xIterativeHardthresholding = zeros(size(a, 2), 1);
yResidue = y;
doTerminate = 0;
normalizedError = 1;
while (~ doTerminate)
normalizedErrorLast = normalizedError;
xPreSparse = xIterativeHardthresholding + a' * yResidue;
sparseSupport = hard_threshold(xPreSparse, sparseCardinality);
xIterativeHardthresholding = zeros(size(a, 2), 1);
xIterativeHardthresholding(sparseSupport) = xPreSparse(sparseSupport);
yResidue = y - a * xIterativeHardthresholding;
% terminate conditions
normalizedError = norm(yResidue) / norm(y);
isTolerable = normalizedError <= normalizedErrorBound;
isDivergent = normalizedError >= normalizedErrorLast;
doTerminate = (isDivergent || isTolerable);
end
end