function [] = figure3;

%
% function [] = figure3;
%
% plots parts of figure 3 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


% initialize all values
AUCall = nan(72,101);
AUCmult= nan(72,1);
  
for imIdx = 1 : 72
  
  % complement
  otherImages = 1:72;
  otherImages(imIdx)=[];
  
  ix=find(condition(imIdx,:)==0);
  
  % positive set (all images)
  xPositive = xFix(imIdx,ix,2:end);
  yPositive = yFix(imIdx,ix,2:end);
  
  xNegative=[];
  yNegative=[];
	  
  for k2 = otherImages
	
	ix=find(condition(k2,:)==0);
	% negative set (all other images)
	xNegative = [xNegative,xFix(k2,ix,2:end)];
	yNegative = [yNegative,yFix(k2,ix,2:end)];
	
  end
  
  % load the maps
  load(sprintf('maps_%2.2d',imIdx),'AWS','PVL');

  count = 0;
  for alph = 0:0.01:1
  
	count = count+1;
	fprintf('Processing %3.3d %3.3d\n',imIdx,count);
	M = AWS/sum(AWS(:))*alph+PVL/sum(PVL(:))*(1-alph);
  
	valPos = computeValsAtFixation(xPositive(:),yPositive(:),M);
	valNeg = computeValsAtFixation(xNegative(:),yNegative(:),M);
  
	AUCall(imIdx,count) =  computeROC(valNeg,valPos);
  end
  
  % multiplicative
  M = (AWS/sum(AWS(:))).*(PVL/sum(PVL(:)));
  
  valPos = computeValsAtFixation(xPositive(:),yPositive(:),M);
  valNeg = computeValsAtFixation(xNegative(:),yNegative(:),M);
  AUCmult(imIdx) =  computeROC(valNeg,valPos);
  

end

plot([0:0.01:1],mean(AUCall-.5),'k');
hold on;
plot([0:0.01:1],mean(AUCall-.5)+std(AUCall)/sqrt(72),'Color',[.5 .5 .5]);
plot([0:0.01:1],mean(AUCall-.5)-std(AUCall)/sqrt(72),'Color',[.5 .5 .5]);
axis([-0.1 1.4 0.0 0.25]);

[MX,iMX] = max(mean(AUCall));


set(gca,'YTick',[0.5 MX .7 .75]-.5);
set(gca,'YTickLabel',[0.5 MX .7 .75]);
set(gca,'XTick',[0 iMX/100 1]);

MMM=mean(max(AUCall'));
MMS=std(max(AUCall'));

TMM = mean(AUCmult);
TMS = std(AUCmult);



bar([0 1 1.2 1.3],[mean(AUCall(:,1)),mean(AUCall(:,101)),MMM,TMM]-.5,'barWidth',0.8);
errorbar([0 1 1.2 1.3],[mean(AUCall(:,1)),mean(AUCall(:,101)),MMM,TMM]-.5,[std(AUCall(:,1)),std(AUCall(:,101)),MMS,TMS]/sqrt(72),'.');



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



