i wrote respected coding for my algorithm...is it correct?

2 views (last 30 days)
  1. input: Training examples: x0 =[x1, x2 . . . xk . . .X_l ]^T, Class labels: y = [y1, y2 . . . yk . . . y_l ]^T
  2. Subset of surviving features: s= [1, 2 . . . n]
  3. Feature ranked list: r= [ ]
  4. repeat
  5. Restrict training examples to good feature indices: x = x0(:,s)
  6. Train the classifier: α= SVM-train(x,y)
  7. Compute the weight vector of dimension length(s): W=Σ_k α_k y_k X_k
  8. Compute the ranking criteria: c_i= W_i (m_i^+-m_i^- ),∀i
  9. Find the feature with smallest ranking criterion: f = arg min(c)
  10. Update feature ranked list: r =[s (f), r]
  11. Eliminate the feature with smallest ranking criterion: s = s (1: f-1, f +1: length(s))
  12. until s= = [ ]
  13. return Feature ranked list r........coding is...
X(kk,:)=[reshape(dc_f,1,prod(size(dc_f))),reshape(dc_f1,1,prod(size(dc_f1))),reshape(dc_f2,1,prod(size(dc_f2))),reshape(dc_f3,1,prod(size(dc_f3))),reshape(p3h,1,prod(size(p3h))),reshape(p3v,1,prod(size(p3v))),reshape(p4h,1,prod(size(p4h))),reshape(p4v,1,prod(size(p4v))),reshape(A0h,1,prod(size(A0h))),reshape(A0v,1,prod(size(A0v))),reshape(A01h,1,prod(size(A01h))),reshape(A01v,1,prod(size(A01v))),reshape(dw_f10,1,prod(size(dw_f10))),reshape(dw_f11,1,prod(size(dw_f11))),reshape(dw_f18,1,prod(size(dw_f18))),reshape(dw_f26,1,prod(size(dw_f26))),reshape(dw_f27,1,prod(size(dw_f27))),reshape(dw_f34,1,prod(size(dw_f34))),reshape(dw_f35,1,prod(size(dw_f35))),reshape(dw_f42,1,prod(size(dw_f42))),reshape(dw_f43,1,prod(size(dw_f43))),reshape(dw_f64,1,prod(size(dw_f64))),reshape(dw_f69,1,prod(size(dw_f69)))];
end
X0=[X(1,:);X(2,:);X(3,:);X(4,:);X(5,:);X(6,:);X(7,:);X(8,:);X(9,:);X(10,:)];
yy=[+1 +1 +1 +1 +1 -1 -1 -1 -1 -1];
Y1=yy';
S=[1:50];
r=[];
X50=X0(:,S);
alpha=svmtrain(X50,Y1);
W=(((alpha.Alpha).*(alpha.GroupNames(alpha.SupportVectorIndices))))'* (alpha.SupportVectors);
m_f=alpha.SupportVectors;
tm_f= mean(m_f(1:4,:))-mean(m_f(5:7,:));
for i=1:50
C(i)=W(i)*tm_f(i);
end
f=argmin(C);
r=[S(f),r];
S=S([1:f-1,f+1:length(S)]);
S==[];
return ;
  4 Comments
Jan
Jan on 26 Feb 2013
The shown code is not working, even not until step 11.
Jan
Jan on 28 Feb 2013
Please, prasanna, you are not a newbie in this forum and some of your former questions contain well formatted code already. Did one of the editors fix the formatting of your questions? Anyway, please do this by your own, because currently the code is not readable.

Sign in to comment.

Answers (1)

Jan
Jan on 26 Feb 2013
Edited: Jan on 26 Feb 2013
Nicer and less prone to typos than X0=[X(1,:);X(2,:);X(3,:);X(4,:);X(5,:);X(6,:);X(7,:);X(8,:);X(9,:);X(10,:)] :
X0 = X(1:10, :);
You should omit the useless comparison with an empty matrix, especially when you do not show the result:
S==[];
If you really want to test, if an array is empty, use isempty(S). Currently your code does not contain the test "until s == [ ]".
Use numel(dw_f11) to obtain the number of elements instead of prod(size(dw_f11)), because it is nicer and faster.
Instead of the ugly worm of reshape's, this would be nicer and much easier to debug:
X(kk, :) = transpose([dc_f(:); dc_f1(:); dc_f(:); ...etc ]);
I still do not know what argmin is.
  13 Comments
Dhines
Dhines on 7 Mar 2013
f is the value which takes the position of minmum value of C vector... when i simply run this code i got f value i.e position is 16
Walter Roberson
Walter Roberson on 7 Mar 2013
Edited: Walter Roberson on 7 Mar 2013
According to the code you posted in these comments, above ("Expand comments" to see it) the very first thing you do is
S=S([1:f-1, f+1:length(S)]);
That can only work if "S" and "f" have been defined. As they have not been defined, you are going to get the complaint about "f" being undefined that you indicated was a problem.
If the code posted here is not the actual code, then we need to see the actual code, and you need to tell us which line the message about "f" being undefined is occurring on.

Sign in to comment.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!