function [] = figure4;

%
% function [] = figure4;
%
% plots parts of figure 4 of the paper
%
% Stoll, J., Thrun, M., Nuthmann, A., & Einhäuser, W. (2015). Overt
% attention in natural scenes: Objects dominate features. Vision
% Research, 107, 36-48. doi: 10.1016/j.visres.2014.11.006 
%


% load fixations of experiment 1
load exp1_fixations xFix yFix durFix condition

maxFix = 11;

AUC_PVL = nan(72,maxFix);
AUC_AWS = nan(72,maxFix);


for imIdx = 1 : 72
  
  fprintf('Processing %3.3d\n',imIdx);

  % load the maps
  load(sprintf('maps_%2.2d',imIdx),'AWS','PVL');

  % complement
  otherImages = 1:72;
  otherImages(imIdx)=[];
  
  for k =1:maxFix
  

	ix=find(condition(imIdx,:)==0);
	
	% positive set (all images)
	xPositive = xFix(imIdx,ix,k);
	yPositive = yFix(imIdx,ix,k);
	
	xNegative=[];
	yNegative=[];
	
	for k2 = otherImages
	
	  ix=find(condition(k2,:)==0);
	  % negative set (all other images)
	  xNegative = [xNegative,xFix(k2,ix,k)];
	  yNegative = [yNegative,yFix(k2,ix,k)];
	  
	end
  
	
	
	% AWS
	valPos = computeValsAtFixation(xPositive(:),yPositive(:),AWS);
	valNeg = computeValsAtFixation(xNegative(:),yNegative(:),AWS);
	AUC_AWS(imIdx,k) = computeROC(valNeg,valPos);
	
	% PVL
	valPos = computeValsAtFixation(xPositive(:),yPositive(:),PVL);
	valNeg = computeValsAtFixation(xNegative(:),yNegative(:),PVL);
	AUC_PVL(imIdx,k) = computeROC(valNeg,valPos);
  end
 
end

figure(4);
clf;

errorbar([0:10]+.1,nanmean(AUC_AWS),nanstd(AUC_AWS)./sqrt(sum(isfinite(AUC_AWS))),'k.');
hold on;
errorbar([0:10]-.1,nanmean(AUC_PVL),nanstd(AUC_PVL)./sqrt(sum(isfinite(AUC_PVL))),'r.');
sum(isfinite(AUC_AWS))
axis([-.5 10.5 .45 .75]);
line([-.5 10.5],[.5 .5]);
set(gca,'YTick',[.45 .75]);
set(gca,'XTick',[0 10]);
xlabel('fixation #');
ylabel('AUC');


function [valsAtFixation]=computeValsAtFixation(x,y,map);

ixBad = find(isnan(x)|isnan(y));
x(ixBad)=[];
y(ixBad)=[];

[yS,xS] = size(map);

ixBad = find((x<1)|(x>xS)|(y<1)|(y>yS));
x(ixBad)=[];
y(ixBad)=[];

valsAtFixation = nan(1,length(x));

for k = 1 : length(x)
  
  valsAtFixation(k)=map(y(k),x(k));
  
end
