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

  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

If your code is not working, show us the error message.
my code is working upto step 11. after steps my initialized process is it correct?
The shown code is not working, even not until step 11.
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

one more thing...in my code 4th step is repeat ...its going until get S is empty. can i use this in for loop
@prasanna: I do not see the relation between the list of 13 points and the code. Therefore I do not understand, what you are asking for.
ok sir. simply to ask. i want to apply "repeat" and end of the condition until S==[]. i need e.g for repeat function. i applied repeat function in my steps. its shows repeat is undefined variable. what i will do?
no sir...want e.g for repeat .... .... ... ... unitl condition.
MATLAB does not have a "repeat until" construct.
To convert
repeat A until B
you can either use
A; while ~B; A; end
or you can use
while true; A; if B; break; end; end
here 'argmin' is the function. i defined another .m file and cal it to my main code.
S=S([1:f-1, f+1:length(S)]);
while ~isemplty(S)
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];
%here tel me how to return the value to r,
is crct retrun (r);
end..
and also shows error..when i execute argmin function inside of while loop its not takes to implemnet. shows undefined variable 'f'.
You need to show us the code for argmin.
You do not assign any value to S inside your while loop, so the body of the loop will either not be executed at all (in which case f will not be assigned a value) or else the body will be run infinitely.
Is there a reason why you did not use my earlier code suggestion of
S(f) = [];
instead of S=S([1:f-1, f+1:length(S)]); ?
@prasanna: The code is not readable due to the missing formatting. If you want others to assist you, it is a good idea to improve the readability of your messages. Code formatting has been explain such frequently, that you will surely find the instructions very fast, when you search for it.
walter roberson sir, here your information for argmin.
function f = argmin(C)
[m i] = min(C(:));
if isvector(C)
f = i;
else
f = ind2subv(sizePMTK(C), i);
end
Your line
S=S([1:f-1, f+1:length(S)]);
is before you have given any value to "f".
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
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.

Categories

Tags

Asked:

on 26 Feb 2013

Community Treasure Hunt

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

Start Hunting!