Home > NoiseTools > nt_pca_nodemean.m

nt_pca_nodemean

PURPOSE ^

[z,idx]=nt_pca_nodemean(x,shifts,keep,threshold,w) - time-shift pca

SYNOPSIS ^

function [z,idx]=nt_pca_nodemean(x,shifts,keep,threshold,w)

DESCRIPTION ^

[z,idx]=nt_pca_nodemean(x,shifts,keep,threshold,w) - time-shift pca

  z: pcs
  idx: x(idx) maps to z

  x: data matrix
  shifts: array of shifts to apply
  keep: number of components shifted regressor PCs to keep (default: all)
  threshold: discard PCs with eigenvalues below this (default: 0)
  w: ignore samples with absolute value above this

 mean is NOT removed prior to processing

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [z,idx]=nt_pca_nodemean(x,shifts,keep,threshold,w)
0002 %[z,idx]=nt_pca_nodemean(x,shifts,keep,threshold,w) - time-shift pca
0003 %
0004 %  z: pcs
0005 %  idx: x(idx) maps to z
0006 %
0007 %  x: data matrix
0008 %  shifts: array of shifts to apply
0009 %  keep: number of components shifted regressor PCs to keep (default: all)
0010 %  threshold: discard PCs with eigenvalues below this (default: 0)
0011 %  w: ignore samples with absolute value above this
0012 %
0013 % mean is NOT removed prior to processing
0014 
0015 % TODO: reimplement using nt_pca0
0016 
0017 if nargin<1; error('!'); end
0018 if nargin<2||isempty(shifts); shifts=[0]; end
0019 if nargin<3; keep=[]; end
0020 if nargin<4; threshold=[]; end
0021 if nargin<5; w=[]; end
0022 
0023 [m,n,o]=size(x);
0024 
0025 % offset of z relative to x
0026 offset=max(0,-min(shifts));
0027 shifts=shifts+offset;           % adjust shifts to make them nonnegative
0028 idx=offset+(1:m-max(shifts));   % x(idx) maps to z
0029 
0030 % remove mean
0031 %x=nt_fold(nt_demean(nt_unfold(x),w),m);
0032 
0033 % covariance
0034 if isempty(w);
0035     c=nt_cov(x,shifts);
0036 else
0037     if sum(w(:))==0; error('weights are all zero!'); end
0038     c=nt_cov(x,shifts,w);
0039 end
0040 
0041 % PCA matrix
0042 [topcs,evs]=nt_pcarot(c);
0043 
0044 % truncate
0045 if ~isempty(keep)
0046     topcs=topcs(:,1:keep);
0047     evs=evs(1:keep);
0048 end
0049 if ~isempty (threshold)
0050     ii=find(evs/evs(1)>threshold);
0051     topcs=topcs(:,ii);
0052     evs=evs(ii);
0053 end
0054 
0055 %clf; plot(evs); set(gca,'yscale','log'); pause
0056 
0057 % apply PCA matrix to time-shifted data
0058 z=zeros(numel(idx),size(topcs,2),o);
0059 for k=1:o
0060     z(:,:,k)=nt_multishift(x(:,:,k),shifts)*topcs;
0061 end
0062 
0063

Generated on Mon 28-Nov-2016 20:12:47 by m2html © 2005