Home > NoiseTools > nt_pcarot.m

nt_pcarot

PURPOSE ^

[topcs,eigenvalues]=pcarot(cov,nkeep,threshold,N) - PCA matrix from covariance

SYNOPSIS ^

function [topcs,eigenvalues]=nt_pcarot(cov,nkeep,threshold,N)

DESCRIPTION ^

 [topcs,eigenvalues]=pcarot(cov,nkeep,threshold,N) - PCA matrix from covariance

  topcs: PCA rotation matrix
  eigenvalues: PCA eigenvalues
  
  cov: covariance matrix
  nkeep: number of component to keep
  thresholds: discard components below this threshold
  N: eigs' K parameter (if absent: use eig)

 NoiseTools

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [topcs,eigenvalues]=nt_pcarot(cov,nkeep,threshold,N)
0002 % [topcs,eigenvalues]=pcarot(cov,nkeep,threshold,N) - PCA matrix from covariance
0003 %
0004 %  topcs: PCA rotation matrix
0005 %  eigenvalues: PCA eigenvalues
0006 %
0007 %  cov: covariance matrix
0008 %  nkeep: number of component to keep
0009 %  thresholds: discard components below this threshold
0010 %  N: eigs' K parameter (if absent: use eig)
0011 %
0012 % NoiseTools
0013 
0014 if nargin<4; N=[]; end
0015 if nargin<3; threshold=[]; end
0016 if nargin<2; nkeep=[]; end
0017 
0018 if ~isempty(N); 
0019     [V, S] = eigs(cov,N) ;  
0020 else
0021     [V, S] = eig(cov) ;  
0022 end
0023 
0024 V=real(V);
0025 S=real(S);
0026 [eigenvalues, idx] = sort(diag(S)', 'descend') ;
0027 topcs = V(:,idx);
0028 
0029 % truncate
0030 if ~isempty (threshold)
0031     ii=find(eigenvalues/eigenvalues(1)>threshold);
0032     topcs=topcs(:,ii);
0033     eigenvalues=eigenvalues(ii);
0034 end
0035 
0036 if ~isempty(nkeep)
0037     nkeep=min(nkeep,size(topcs,2));
0038     topcs=topcs(:,1:nkeep);
0039     eigenvalues=eigenvalues(1:nkeep);
0040 end

Generated on Sat 29-Apr-2023 17:15:46 by m2html © 2005