-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathOMPerr.m
39 lines (38 loc) · 1.02 KB
/
OMPerr.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
37
38
39
function [A]=OMPerr(D,X,errorGoal);
%=============================================
% Sparse coding of a group of signals based on a given
% dictionary and specified number of atoms to use.
% input arguments: D - the dictionary
% X - the signals to represent
% errorGoal - the maximal allowed representation error for
% each siganl.
% output arguments: A - sparse coefficient matrix.
%=============================================
[n,P]=size(X);
[n,K]=size(D);
E2 = errorGoal^2*n;
maxNumCoef = n/2;
A = sparse(size(D,2),size(X,2));
for k=1:1:P,
a=[];
x=X(:,k);
residual=x;
indx = [];
a = [];
currResNorm2 = sum(residual.^2);
j = 0;
while currResNorm2>E2 & j < maxNumCoef,
j = j+1;
proj=D'*residual;
pos=find(abs(proj)==max(abs(proj)));
pos=pos(1);
indx(j)=pos;
a=pinv(D(:,indx(1:j)))*x;
residual=x-D(:,indx(1:j))*a;
currResNorm2 = sum(residual.^2);
end;
if (length(indx)>0)
A(indx,k)=a;
end
end;
return;