i wrote respected coding for my algorithm...is it correct?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
- input: Training examples: x0 =[x1, x2 . . . xk . . .X_l ]^T, Class labels: y = [y1, y2 . . . yk . . . y_l ]^T
- Subset of surviving features: s= [1, 2 . . . n]
- Feature ranked list: r= [ ]
- repeat
- Restrict training examples to good feature indices: x = x0(:,s)
- Train the classifier: α= SVM-train(x,y)
- Compute the weight vector of dimension length(s): W=Σ_k α_k y_k X_k
- Compute the ranking criteria: c_i= W_i (m_i^+-m_i^- ),∀i
- Find the feature with smallest ranking criterion: f = arg min(c)
- Update feature ranked list: r =[s (f), r]
- Eliminate the feature with smallest ranking criterion: s = s (1: f-1, f +1: length(s))
- until s= = [ ]
- 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 comentarios
Jan
el 28 de Feb. de 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.
Respuestas (1)
Jan
el 26 de Feb. de 2013
Editada: Jan
el 26 de Feb. de 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 comentarios
Walter Roberson
el 7 de Mzo. de 2013
Editada: Walter Roberson
el 7 de Mzo. de 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.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!