Matlab 残差与所选原子的跨度不正交

Matlab 残差与所选原子的跨度不正交,matlab,statistics,sparse-matrix,approximation,Matlab,Statistics,Sparse Matrix,Approximation,我正在尝试实现正交匹配追踪算法。算法可以在这里找到 它说残差与选定原子的跨度正交,但我只得到第一个选定原子与残差正交。后来选定的原子不会与剩余原子正交。请检查代码并解释我哪里做错了 clc,clear; dictionary = [1 0; 1/2 sqrt(3)/2; -1/sqrt(2) -1/sqrt(2)]'; t=5; s=[1;1/2]; r=s; atoms=zeros(size(dictionary,1),size(dictionary,2)); coefs=zeros(

我正在尝试实现正交匹配追踪算法。算法可以在这里找到

它说残差与选定原子的跨度正交,但我只得到第一个选定原子与残差正交。后来选定的原子不会与剩余原子正交。请检查代码并解释我哪里做错了

clc,clear;

dictionary = [1 0; 1/2 sqrt(3)/2; -1/sqrt(2) -1/sqrt(2)]';

t=5;
s=[1;1/2];

r=s;
atoms=zeros(size(dictionary,1),size(dictionary,2));
coefs=zeros(size(dictionary,2),1);

%Normalize the dictionary 
for index=1:size(dictionary,2)
   dictionary(:,index)=dictionary(:,index)./norm(dictionary(:,index)); 
end
D=dictionary;

index=[];
while(t>1e-15 && sum(dictionary(:)~=0))%Process while (Eucledian norm > 10^-15)
    inner_product=dictionary'*r; %Dot Product
    [m,ind]=max(abs(inner_product));
    index=[index ind];
    atoms(:,ind)=dictionary(:,ind); %Select atom which has maximum inner product
    x=(atoms(:,ind)'*atoms(:,ind))\(atoms(:,ind)'*r);
    coefs(ind)=x;
    r=r-atoms(:,ind)*x;  

    t=power(norm(r),2);


end
更多链接: 包含不同论文中相同算法的屏幕截图: