www.pudn.com > GaitRecognition.rar > LDA_2D.m, change:2012-11-03,size:1558b


function [dataAfter2DLDA,lda_2D_Vector] = LDA_2D(PCAdata,eachPersonNum) 
tic; 
personNum=length(eachPersonNum);% 
cMean=zeros(size(PCAdata,1),size(PCAdata,2),personNum); 
Si=zeros(size(PCAdata,1),size(PCAdata,1),personNum); 
meanPCAdata=sum(PCAdata,3)/size(PCAdata,3); 
index=1; 
for i=1:personNum 
       clear cSet      
       cLen=eachPersonNum(1,i); 
       cSet=zeros(size(PCAdata,1),size(PCAdata,2),cLen); 
       for j=1:cLen 
           cSet(:,:,j)=PCAdata(:,:,index); 
           index=index+1; 
       end 
       cMean(:,:,i)=sum(cSet,3)/cLen;                     
       S_temp=zeros(size(PCAdata,1),size(PCAdata,1)); 
       for j=1:cLen 
           if j==1 
               S_temp=(cSet(:,:,1)-cMean(:,:,i))*(cSet(:,:,1)-cMean(:,:,i))'; 
           else 
               S_temp=S_temp+(cSet(:,:,j)-cMean(:,:,i))*(cSet(:,:,j)-cMean(:,:,i))'; 
           end 
       end 
       Si(:,:,i)=S_temp;       
       %计算类间散射矩阵Sb 
       if i==1 
           Sb=cLen*(cMean(:,:,1)-meanPCAdata)*(cMean(:,:,1)-meanPCAdata)'; 
       else 
           Sb=Sb+cLen*(cMean(:,:,i)-meanPCAdata)*(cMean(:,:,i)-meanPCAdata)'; 
       end            
end   
   %计算类内散射矩阵Sw 
   Sw=sum(Si,3);    
   %求出特征值与对应的特征向量 
   OPTS.disp=0; 
   [eVectorLDA,eValueLDA]=eigs(Sw\Sb,6,'LM',OPTS); 
   lda_2D_Vector=eVectorLDA';  
   dataAfter2DLDA=zeros(size(eValueLDA,1),size(PCAdata,2),size(PCAdata,3)); 
   for i=1:size(PCAdata,3) 
       dataAfter2DLDA(:,:,i)=lda_2D_Vector*PCAdata(:,:,i);%经LDA后的数据 
   end 
   disp('2DLDA time:'); 
   toc;