i wrote respected coding for my algorithm...is it correct?
이전 댓글 표시
- 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
Azzi Abdelmalek
2013년 2월 26일
편집: Azzi Abdelmalek
2013년 2월 26일
If your code is not working, show us the error message.
Dhines
2013년 2월 26일
Jan
2013년 2월 26일
The shown code is not working, even not until step 11.
Jan
2013년 2월 28일
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.
답변 (1개)
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
Dhines
2013년 2월 26일
Jan
2013년 2월 27일
@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.
Dhines
2013년 2월 28일
Walter Roberson
2013년 2월 28일
while ~isempty(S)
Dhines
2013년 2월 28일
Walter Roberson
2013년 2월 28일
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
Dhines
2013년 2월 28일
편집: Walter Roberson
2013년 2월 28일
Walter Roberson
2013년 2월 28일
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)]); ?
Jan
2013년 2월 28일
@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.
Dhines
2013년 3월 7일
Walter Roberson
2013년 3월 7일
Your line
S=S([1:f-1, f+1:length(S)]);
is before you have given any value to "f".
Dhines
2013년 3월 7일
Walter Roberson
2013년 3월 7일
편집: Walter Roberson
2013년 3월 7일
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.
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!