Skip to content

Commit

Permalink
update demo files
Browse files Browse the repository at this point in the history
  • Loading branch information
Junpeng Lao committed Jan 22, 2016
1 parent 9a28200 commit 9855d75
Show file tree
Hide file tree
Showing 128 changed files with 450 additions and 48 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
29 changes: 11 additions & 18 deletions Data_Sample_with_codes/imap_DEMO.m
Original file line number Diff line number Diff line change
Expand Up @@ -106,22 +106,15 @@
if isempty(indx1)
indx(ii)=1;
else
indxtf=sub2ind([ySize, xSize],coordX(indx1),coordY(indx1)); % index each fixation location,

unindx = unique(indxtf);% find unique fixation
[cotind,whe] = histc(indxtf,unindx); % cumulate fixation with same coordinates.
durind=zeros(size(cotind));
for iw=1:length(cotind);durind(iw)=sum(intv(whe==iw));end % calculate duration
rawmap(unindx(durind>0))=durind(durind>0);

f_mat = fft2(rawmap); % 2D fourrier transform on the points matrix
filtered_mat = f_mat .* f_fil;

smoothpic = real(fftshift(ifft2(filtered_mat)));
isfixmap(it,:,:)=imresize(smoothpic,scale);
israwmap(it,:,:)=imresize(rawmap,scale);
stDur(it)=sum(durind);
stRate(it)=srate(selected2(1));
rawmap=full(sparse(coordX(indx1),coordY(indx1),intv(indx1),ySize,xSize));
f_mat = fft2(rawmap); % 2D fourrier transform on the points matrix
filtered_mat = f_mat .* f_fil;

smoothpic = real(fftshift(ifft2(filtered_mat)));
isfixmap(it,:,:)=imresize(smoothpic,scale);
israwmap(it,:,:)=imresize(rawmap,scale);
stDur(it)=sum(durind);
stRate(it)=srate(selected2(1));
end
end
Subject{ii,1}=subjlist{is};
Expand Down Expand Up @@ -177,8 +170,8 @@
%% LMMmap structure
% impLMM will output a structure called LMMmap with all the information
% from the linear mixed model fitting:
% LMMmap =
%
% LMMmap =
%
% runopt: [1x1 struct]
% VariableInfo: [6x4 dataset]
% Variables: [118x6 dataset]
Expand Down
134 changes: 123 additions & 11 deletions Data_Sample_with_codes/imap_DEMO_ST1.m
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,10 @@
gaussienne = (gaussienne - min(gaussienne(:))) / (max(gaussienne(:)) - min(gaussienne(:)));
f_fil = fft2(gaussienne);
% fixation matrix
rawmap = zeros(ySize, xSize);
coordX = round(Y(:,2));
coordY = round(Y(:,1));
indx1=coordX>0 & coordY>0 & coordX<xSize & coordY<ySize;
indxtf=sub2ind([ySize, xSize],coordX(indx1),coordY(indx1)); % index each fixation location,
unindx = unique(indxtf);% find unique fixation
[cotind,whe] = histc(indxtf,unindx); % cumulate fixation with same coordinates.
rawmap(unindx)=cotind;% number of fixation
rawmap=full(sparse(coordX(indx1),coordY(indx1),ones(size(coordY(indx1))),ySize,xSize));
f_mat = fft2(rawmap); % 2D fourrier transform on the points matrix
filtered_mat = f_mat .* f_fil;
smoothpic = real(fftshift(ifft2(filtered_mat)));
Expand All @@ -151,6 +147,7 @@
RawMap=FixMap;
Nfixbase=2; % number of fixations for each trials is the multiple of Nfixbase
item=0;
DataM=[];
for is=1:Ns
for itrial=1:n
item=item+1;
Expand All @@ -165,14 +162,10 @@
Ytmp2= [randi(xSize,10,1) randi(ySize,10,1)];% 10 random fixations
% fixation matrix
Y=[Ytmp;Ytmp2];
rawmap = zeros(ySize, xSize);
coordX = round(Y(:,2));
coordY = round(Y(:,1));
indx1=coordX>0 & coordY>0 & coordX<xSize & coordY<ySize;
indxtf=sub2ind([ySize, xSize],coordX(indx1),coordY(indx1)); % index each fixation location,
unindx = unique(indxtf);% find unique fixation
[cotind,whe] = histc(indxtf,unindx); % cumulate fixation with same coordinates.
rawmap(unindx)=cotind;% number of fixation
rawmap=full(sparse(coordX(indx1),coordY(indx1),ones(size(coordY(indx1))),ySize,xSize));
f_mat = fft2(rawmap); % 2D fourrier transform on the points matrix
filtered_mat = f_mat .* f_fil;
smoothpic = real(fftshift(ifft2(filtered_mat)));
Expand All @@ -183,12 +176,20 @@
Subject(item)=is;
Rating(item)=Xall(is,itrial);
fixNb(item)=Nfix;
Yk=cotind;
Yk(:,2:3)=unique([coordX(indx1),coordY(indx1)],'rows');
Yk(:,4)=Xall(is,itrial);
Yk(:,5)=is;
DataM=[DataM;Yk];
end
end
% figure;imagesc(squeeze(mean(FixMap,1)))
Mask=squeeze(mean(FixMap,1)>.25);
% figure;imagesc(Mask)
PredictorM=dataset(Rating,fixNb,Subject);
ds=mat2dataset(DataM);
ds=set(ds,'VarNames',{'fixN','rl','cl','rating','is'});
export(ds,'File','STrate.csv','Delimiter',',');
%% Linear Mixed Modeling with imapLMM
tic
opt.singlepredi=0;
Expand Down Expand Up @@ -221,4 +222,115 @@
% perform multiple comparison correction
[StatMap_c]=imapLMMmcc(StatMap,LMMmap,mccopt,FixMap);
% output figure;
imapLMMdisplay(StatMap_c,0)
imapLMMdisplay(StatMap_c,0)
%% Region dependent threshold
ResampStat=StatMap_c.resampMat;
nboot=mccopt.nboot;
alpha=.05;
Pmask=zeros(size(squeeze(StatMap_c.Pmask(2,:,:))));
Pmap=StatMap.Pmap;
mapvalue=StatMap.map;
Maskall=zeros(size(Pmask));
Maskall(16:135,16:135)=kron(reshape(1:16,4,4),ones(30,30));
bootopt=1;

for imask=1:16
region=Maskall==imask;
for ic=2
Fboot=squeeze(ResampStat.resFvalue(:,ic,region));
Pboot=squeeze(ResampStat.resPvalue(:,ic,region));
Betabt=squeeze(ResampStat.resBeta(:,ic,region));
Fboot=reshape(Fboot,1000,30,30);
Pboot=reshape(Pboot,1000,30,30);
Betabt=reshape(Betabt,1000,30,30);
% output estimated bootstrap distribution (cluster test)
maxclust=zeros(nboot,3);
for ib=1:nboot
Ftmp=squeeze(Fboot(ib,:,:));
[bmasktmp,bnum]=bwlabel(squeeze(Pboot(ib,:,:))<alpha);
if bnum>0
maxtmp=zeros(bnum,3);
for icluster=1:bnum
maxtmp(icluster,1)=nansum(nansum(Ftmp(bmasktmp==icluster)));
maxtmp(icluster,2)=sum(sum(bmasktmp==icluster));
maxtmp(icluster,3)=maxtmp(icluster,1)./maxtmp(icluster,2);
end
maxclust(ib,1)=max(maxtmp(:,1));
maxclust(ib,2)=max(maxtmp(:,2));
maxclust(ib,3)=max(maxtmp(:,3));
end
end
distmp=sort(maxclust,1);
% output cluster mass and size threshold at alpha
clthres=distmp(round(nboot*(1-alpha)),:);
% output new Pmask: 1 cluster mass, 2 cluster size, 3 both,
% 4 cluster dense
mapvalue1=reshape(squeeze(mapvalue(ic,region)),30,30);
Pmap1=reshape(squeeze(Pmap(ic,region)),30,30);
switch bootopt
case 1
Pmask(region)=clustertest2D(mapvalue1, ...
Pmap1,alpha,clthres(1),[],[]);
case 2
Pmask(region)=clustertest2D(mapvalue1, ...
Pmap1,alpha,[],clthres(2),[]);
case 3
Pmask(region)=clustertest2D(mapvalue1, ...
Pmap1,alpha,clthres(1),clthres(2),[]);
case 4
Pmask(region)=clustertest2D(mapvalue1, ...
Pmap1,alpha,[],[],clthres(3));
end
end
end
figure;imagesc(Pmask);axis square off
%% plot fixed effec(anova and beta) - using permutation
% close all
opt=struct;% clear structure
opt.type='model beta';
opt.alpha=.05;
% perform contrast
[StatMap]=imapLMMcontrast(LMMmap,opt);
% imapLMMdisplay(StatMap,1)

mccopt=struct;
mccopt.methods='permutation';
mccopt.nboot=1000;
mccopt.bootopt=1;
mccopt.tfce=0;
% perform multiple comparison correction
[StatMap_c]=imapLMMmcc(StatMap,LMMmap,mccopt,FixMap);
% output figure;
imapLMMdisplay(StatMap_c,0)
%% Region dependent threshold
ResampStat=StatMap_c.resampMat;
nboot=mccopt.nboot;
alpha=.05;
Pmask=zeros(size(squeeze(StatMap_c.Pmask(2,:,:))));
Pmap=StatMap.Pmap;
mapvalue=StatMap.map;
Maskall=zeros(size(Pmask));
Maskall(16:135,16:135)=kron(reshape(1:16,4,4),ones(30,30));
bootopt=1;
Pmapnew2=Maskall;
for imask=1:16
region=Maskall==imask;
for ic=2
Fboot=squeeze(ResampStat.resFvalue(:,ic,region));
Fboot=reshape(Fboot,1000,30,30);
% output new Pmask
origFmap=squeeze(StatMap.map(ic,region));
origFmap=reshape(origFmap,30,30);
orFmat=permute(repmat(origFmap,[1,1,nboot]),[3,1,2]);
Fboot2=repmat(max(Fboot(:,:),[],2),[1,size(Fboot,2),size(Fboot,3)]);
Pmapnew2(region)=(sum(Fboot2>=orFmat,1)+1)./(nboot+1);
end
end
Pmapnew2(Mask==0)=1;
figure;
subplot(1,3,1);
imagesc(squeeze(StatMap_c.Pmap(ic,:,:)));axis square off
subplot(1,3,2);
imagesc(Pmapnew2);axis square off
subplot(1,3,3);
imagesc(Pmapnew2<alpha);axis square off
21 changes: 2 additions & 19 deletions Data_Sample_with_codes/imap_DEMO_ST2.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,11 @@
gaussienne = (gaussienne - min(gaussienne(:))) / (max(gaussienne(:)) - min(gaussienne(:)));
f_fil = fft2(gaussienne);
% fixation matrix
rawmap = zeros(ySize, xSize);
coordX = round(Y(:,2));
coordY = round(Y(:,1));
intv=normrnd(0.4,.085,length(Y),1);
indx1=coordX>0 & coordY>0 & coordX<xSize & coordY<ySize;
indxtf=sub2ind([ySize, xSize],coordX(indx1),coordY(indx1)); % index each fixation location,
unindx = unique(indxtf);% find unique fixation
[cotind,whe] = histc(indxtf,unindx); % cumulate fixation with same coordinates.
% number of fixation
% rawmap(unindx)=cotind;
% fixation duration
durind=zeros(size(cotind));
for iw=1:length(cotind);durind(iw)=sum(intv(whe==iw));end % calculate duration
rawmap(unindx(durind>0))=durind(durind>0);
rawmap=full(sparse(coordX(indx1),coordY(indx1),intv(indx1),ySize,xSize));

f_mat = fft2(rawmap); % 2D fourrier transform on the points matrix
filtered_mat = f_mat .* f_fil;
Expand Down Expand Up @@ -160,15 +151,7 @@
pathlength=diag(squareform(pdist([coordY,coordX])),1);
intv=normrnd(Meandur,Stddur,length(Y),1)*1000;
indx1=coordX>0 & coordY>0 & coordX<xSize & coordY<ySize;
indxtf=sub2ind([ySize, xSize],coordX(indx1),coordY(indx1)); % index each fixation location,
unindx = unique(indxtf);% find unique fixation
[cotind,whe] = histc(indxtf,unindx); % cumulate fixation with same coordinates.
% number of fixation
% rawmap(unindx)=cotind;
% fixation duration
durind=zeros(size(cotind));
for iw=1:length(cotind);durind(iw)=sum(intv(whe==iw));end % calculate duration
rawmap(unindx(durind>0))=durind(durind>0);
rawmap=full(sparse(coordX(indx1),coordY(indx1),intv(indx1),ySize,xSize));

f_mat = fft2(rawmap); % 2D fourrier transform on the points matrix
filtered_mat = f_mat .* f_fil;
Expand Down
Loading

0 comments on commit 9855d75

Please sign in to comment.