Orthogonal matching pursuit

帮别人做的问题:

Orthogonal matching pursuit_第1张图片

自己写的程序:

% --------- The input ---------------
D = zeros(10, 10);
for ii=1:10,
    for jj=1:10,
        D(ii, jj) = sin(ii+jj);
    end
end
A = D + eye(10);

b = [-2 -6 -9 1 8 10 1 -9 -4 -3]';
S = 3;
% -----------------------------------
normA = normc(A);
residual = b;
len = size(A, 2);
index = zeros(len, 1);
for ii = 1:S,
    % Compute the inner product
    proj = normA'*residual;
    
    %find the max value and its index
    [~, pos] = max(abs(proj));
    
    % store the index
    index(ii) = pos(1);
    
    %solve the least squares problem
    a = pinv(A(:,index(1:ii)))*b;
    
    % compute the residual in the new dictionary
    residual = b-A(:, index(1:ii))*a;

end
x = zeros(length(b), 1);
x(index(1:ii)) = a;

% ------- the result ---------
norm(A*x-b)
norm(x)


参考:

【1】MP算法和OMP算法及其思想 http://blog.csdn.net/scucj/article/details/7467955

你可能感兴趣的:(Orthogonal matching pursuit)