// step3 CLAFIC?????????? r=30; // ?????????????¦Ï? ????100 if exists('W')==0 // ????????????? // ?????????????¦´???????????? // D?????????????????????¦É???, trai_label ????????????¦´??? // Q?????????????????????¦É???, test_label????¦´?????¦´??? D=fscanfMat('./USPS/trai_data.txt');, trai_label=fscanfMat('./USPS/trai_label.txt'); Q=fscanfMat('./USPS/test_data.txt');, test_label=fscanfMat('./USPS/test_label.txt'); // Dim??????????xx_num????????? [Dim,trai_num]=size(D);,[Dim,test_num]=size(Q); // ????????¦´¦´???1???????? for i = 1 : trai_num, D(:,i)=D(:,i)./norm(D(:,i));, end for i = 1 : test_num, Q(:,i)=Q(:,i)./norm(Q(:,i));, end // ????ð›????????????? W=zeros(Dim,100,10); // ????ð›???????? ????????????????ð›?? for j = 0 : 9 X=D(:,find(trai_label==j)); // ????j?¦Ç???????????X???? C=X*X'; // ????????????? [eig_vec, eig_val]=spec(C); // ????????????????? [value index]=sort(diag(eig_val)); // ??????????¡è???? W(:,:,j+1)=eig_vec(:,index(1:100)); // ???????µ]?????100????§Ò??????????????W???? printf('class %d ... OK\n',j); end end // if exists('W')==0 // CLAFIC??????? S=zeros(10,1); CONF=zeros(10,10); tic(); for i = 1 : test_num for j = 0 : 9, S(j+1)=sum((W(:,1:r,j+1)'*Q(:,i)).^2);, end [value index]=max(S); CONF(test_label(i)+1,index)=CONF(test_label(i)+1,index)+1; printf('test data %d\n',i); end printf('computation time: %3.5f seconds.\n',toc()); accuracy=(sum(diag(CONF))./test_num).*100; printf('accuracy=%3.2f\n',accuracy);