⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 比较标准的pca算法.txt

📁 kennard-stone选样本算法。。。PLS的迭代算法程序
💻 TXT
字号:
function [score,loading]=apca(raw,centr,max); 


%       [T,P]=apca(raw,0,max); 
% 
%       The Matlab routine perform a pca analysis of the data  
%        
%       Uses singular value decomposition (svd) 
%       raw - data matrix 
%       Data must exist as objects*variables 
%  centr=1, centering data (column by column) 
%       centr=0, data is not centered 
%       max - max number of components to be presented  


[m,n]=size(raw); 

%       Centering the matrix 
gj=mean(raw); 
if centr==1; 
        raw=raw - ones(m,1)*gj; 
end; 

%       Calculation of principal components 
if n<m  % More objects than variables  
   cov=(raw'*raw);      %/m-1;   
   [u,s,v]=svd(cov); 
   temp2=(1:n)'; 
    
else 
   cov=(raw*raw');      %/m-1; 
   [u,s,v]=svd(cov); 
   v=raw'*v;    % Calculate loadings    
   for i=1:m 
      v(:,i)=v(:,i)/norm(v(:,i)); %Normalize the loadings 
   end 
   temp2=(1:m)'; 
    
end 

temp = (diag(s)*100)./(sum(diag(s))); 

ssq = [temp2 diag(s) temp cumsum(temp)]; 

% Remove uninteresting components from the presentation 
info=zeros(max,4); 
for i=1:max 
   info(i,:)=ssq(i,:); 
end 

% Presentation of the calculated components 
disp('  ') 
disp('  Percent explained by the PCA model') 
disp('  ') 
disp(' PC#  Eigenvalues  %Variance  %TotVar') 
disp(info) 

% Ask how many components to be made 
lv=max+1; 

while lv>max 
   input('How many principal components would you like to keep?'); 
   lv=ans; 
end 

% Makes the PCA model by means of the information given above 
loading=v(:,1:lv); 
score=raw*loading; 
loading=loading'; 

% Saving of the interesting components, only  
z=zeros(lv,4); 
for i=1:lv 
   z(i,:)=ssq(i,:); 
end 
info=z; 

% End 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -