function [] = figure4_human;

%
% function [] = figure4_human;
%
% plots the rightmost column of figure 4 of the paper
%
% Marx, S., Gruenhage, G., Walper, D., Rutishauser, U., Einhäuser,
% W. (2015). Competition with and without priority control: linking
% rivalry to attention through winner-take-all networks with
% memory. Annals of the New York Academy of Sciences. 1339, 138-153.

figure(4);
clf;

% load dominance times (raw durations a button was presssed)
load dataExp1 durationsLeft durationsRight totalDur

% initialize variables
L = nan(5,6,6);
LwoK = nan(5,6,6);
M = nan(5,6,6);
V = nan(5,6,6);
K = nan(5,6,6);
VV =  nan(5,6,6);
norm_DD = cell(5,6,6);
median_norm_DD = nan(5,6,6);

for subNr = 1 : 5 

  current_med = nanmedian([durationsLeft{subNr,6,6};durationsRight{subNr,6,6}]);

  for left = 1 : 6
	
	for right = 1 : 6

	  currentC1 = ...
		  [durationsLeft{subNr,left,right};durationsRight{subNr,right,left}];
	  
	  Sleft = nansum(durationsLeft{subNr,left,right});
	  Sright = nansum(durationsRight{subNr,left,right});
	  
	  % relative dominance
	  VV(subNr,left,right) = (Sright-Sleft)/(Sright+Sleft);
	  
	  % normalized dominance durations
	  norm_DD{subNr,left,right} = [currentC1./current_med]; 
	  median_norm_DD(subNr,left,right) = nanmedian(norm_DD{subNr,left,right});
	  
	  % switches per time
	  L(subNr,left,right) = sum(isfinite(currentC1))/ totalDur(subNr,left,right);

	  % median, variance and kurtosis
	  M(subNr,left,right) = nanmedian(currentC1);
	  V(subNr,left,right) = nanvar(currentC1);
	  K(subNr,left,right) = kurtosis(currentC1(find(isfinite(currentC1))));
          
	end
  end
end

% do the plotting

subplot(3,1,1)
imagesc(squeeze(nanmean(VV)))
xlabel('contrast to right eye')
ylabel('contrast to left eye')
set(gca,'XTick',1:6)
set(gca,'YTick',1:6)
axis square;
co(1) = colorbar;
colormap('hot')
zlab = get(co(1),'ylabel');
set(zlab,'String','relative dominance'); 
caxis([-1 1]);


subplot(3,1,2)
mean_norm_DD = squeeze(nanmean(median_norm_DD));
std_norm_DD = squeeze(nanstd(median_norm_DD));
imagesc(log(mean_norm_DD))
axis square;
co(2) = colorbar;
colormap hot;
zlab = get(co(2),'ylabel');
set(zlab,'String','log dominance durations'); 
set(gca,'XTick',1:6)
set(gca,'YTick',1:6)
caxis([-max(max(abs(log(mean_norm_DD)))) max(max(abs(log(mean_norm_DD))))]);
xlabel('con. contrast')
ylabel('ips. contrast')
zlabel('log. DD')


subplot(3,1,3)
imagesc(squeeze(mean(L)));
xlabel('contrast to right eye')
ylabel('contrast to left eye')
set(gca,'XTick',1:6)
set(gca,'YTick',1:6)
axis square;
co(3) = colorbar;
colormap('hot')
zlab = get(co(3),'ylabel');
set(zlab,'String','switchrate [1/s]'); 

