www.pudn.com > RobustSF.zip > compute_projection_matrix_and_classifier_parameters.m, change:2014-07-16,size:2462b


function [UP,G,W] = compute_projection_matrix_and_classifier_parameters( U_hat,Sigma_hat,V_hat,tr_label,lambda) 
 
 
nclass=length(unique(tr_label)); 
mp=length(tr_label); 
HP=zeros(nclass,mp); 
 
for il=1:mp 
    HP(tr_label(il),il)=1; 
end 
 
 
X1= U_hat*Sigma_hat*V_hat'; 
[UP,~,VP]=svd(X1); 
 
 
HSP=HP*VP; 
 
 
C=length(U_hat); 
Sigma=diag(Sigma_hat); 
rrr=length(Sigma); 
Q=zeros(size(HSP)); 
G=C*ones(1,rrr)/rrr; 
 
iter=0; 
converged=false; 
tol=1e-10; 
maxIter=1000; 
preResult=1e-10; 
 
 
PreG=G*1000; 
PreQ=Q*1000; 
 
 
%% Start main loop 
while ~converged 
 
     
    %% update Q 
    for i=1:rrr 
        g=G(i)*G(i); 
        Q(:,i)=g*HSP(:,i)/(g+lambda); 
    end 
     
     
    %% update G 
    beta=zeros(1,rrr); 
    for i = 1:rrr 
       beta(i)=(norm(Q(:,i),'fro'))^(2/3); 
    end 
    ssum=sum(beta); 
    for i = 1:rrr 
        G(i) = C*beta(i)/ssum; 
    end 
     
   %% stopCriterion 
   ls=0; 
   for i=1:rrr 
       if G(i)==0 
           converged = true; 
           break; 
       else 
           ls=ls+(norm(Q(:,i),2)/G(i))^2; 
       end 
   end 
   Result=ls*lambda+(norm(HSP-Q,'inf'))^2; 
%    fprintf('result: %f\n',Result); 
 
     
    stopCriterion =abs(preResult-Result); 
    preResult=Result; 
    if stopCriterion< tol 
        converged = true; 
    end 
     stopCriterion1 =norm(PreG-G,'inf'); 
    PreG=G; 
     stopCriterion2 =norm(PreQ-Q,'inf'); 
    PreQ=Q; 
     if stopCriterion1< tol && stopCriterion2< tol 
        converged = true; 
    end 
    if ~converged && iter >= maxIter 
        disp('Maximum iterations reached') ; 
        converged = true ;        
    end   
   
    iter=iter+1; 
end 
 
%% 计算W 
nclass=length(unique(tr_label)); 
W=zeros(nclass,size(X1,1)); 
for i=1:length(G) 
    W(:,i)=Q(:,i)/G(i); 
end 
KK=zeros(size(G)); 
for i=1:rrr 
    KK(i)=G(i)/Sigma(i); 
end 
 
W=W*UP'; 
G=KK; 
UP=UP(:,1:length(KK)); 
% Z2=U_hat*(U_hat'*X2); 
% Z2=UP(:,1:length(KK))*diag(KK)*UP(:,1:length(KK))'*Z2; 
% WW=W*Z2; 
% [CC,C]=max(WW); 
%  
% %% ------------------------------------------------------------------------- 
% %Step6.计算预测的准确率 
% acc = zeros(nclass, 1); 
% for jj = 1 : nclass, 
%         c = jj; 
%         idx = find(ts_label == c); 
%         curr_pred_label = C(idx); 
%         curr_gnd_label = ts_label(idx)'; 
%         acc(jj) = length(find(curr_pred_label == curr_gnd_label));%/length(idx); 
% end;  
% acc= sum(acc)/length(ts_label); 
% fprintf('\nW:%f\n',acc); 
end