0001 function [todss,pwr0,pwr1,todssX,dX,d]=nt_dss1(x,w,keep1,keep2)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 if nargin<4; keep2=10.^-12; end
0020 if nargin<3; keep1=[]; end
0021 if nargin<2; w=[]; end
0022 if nargin<1; error('!'); end
0023
0024 if ndims(x)<3; error('x should be 3D'); end
0025 if ~isa(x,'double'); warning('x is not double precision'); end
0026
0027 x=x(:,:,:);
0028
0029 [m,n,o]=size(x);
0030
0031 if isempty(w)
0032 [c0,nc0]=nt_cov(x);
0033 c0=c0/nc0;
0034 [c1,nc1]=nt_cov(mean(x,3));
0035 c1=c1/nc1;
0036 else
0037
0038 xx=nt_wmean(x,w,3);
0039 ww=min(w,[],2);
0040
0041 [c0,nc0]=nt_cov(x,[],w);
0042 c0=c0/nc0;
0043 [c1,nc1]=nt_cov(xx,[],ww);
0044 c1=c1/nc1;
0045 end
0046
0047
0048 [todss,pwr0,pwr1]=nt_dss0(c0,c1,keep1,keep2);
0049
0050
0051 if nargout>3
0052 if nargin>1; error('!'); end
0053 [nsamples,nchans,ntrials]=size(x);
0054
0055 CC=zeros(nchans,nchans,ntrials);
0056 for iTrial=1:ntrials
0057 CC(:,:,iTrial)=nt_cov(x(:,:,iTrial));
0058 end
0059
0060 todssX=zeros(nchans,nchans,ntrials);
0061 dX=zeros(nchans,ntrials);
0062 for iTrial=1:ntrials
0063 others=setdiff(1:ntrials,iTrial);
0064 C0=sum(CC(:,:,others),3)/nsamples/(ntrials-1);
0065 C1=nt_cov(mean(x(:,:,others),3))/nsamples;
0066 todssX(:,:,iTrial)=nt_dss0(C0,C1);
0067 z=nt_mmat(x,todssX(:,:,iTrial));
0068 tmp=mean(z(:,:,others),3);
0069 dX(:,iTrial)=mean( (nt_normcol(z(:,:,iTrial))-nt_normcol(tmp)).^2 );
0070 end
0071 d=zeros(nchans,ntrials);
0072 z=nt_mmat(x,todss);
0073 d=squeeze(mean(bsxfun(@minus,nt_normcol(z),nt_normcol(mean(z,3))).^2));
0074 end
0075
0076
0077 if nargout==0
0078 figure(100); clf;
0079 subplot 221;
0080 plot(pwr1./pwr0,'.-');
0081 xlabel('component'); ylabel('score');
0082 z=nt_mmat(x,todss(:,1:3));
0083 for iComp=1:3
0084 subplot(2,2,iComp+1);
0085 nt_bsplot(z(:,iComp,:));
0086 title(iComp);
0087 xlabel('sample');
0088 end
0089
0090 clear todss pwr0 pwr1
0091 end
0092