%%%%%%   Fine-grained transition analysis, empirical data,  March 3, 2003
%
% Load workspace PLExp1\S.mat
 trans = PLEtrans_by_sbj(S)         % SUBBLOCK_SIZE = 30
trans = 
      zP320c: [320x13 double]
      zP320i: [320x13 double]
    contextc: [20x13 double]
    contexti: [20x13 double]
      nightc: [20x13 double]
      nighti: [20x13 double]
      blockc: [20x13 double]
      blocki: [20x13 double]

% zc=mean(trans.zP320c,2);zi=mean(trans.zP320i,2);      %zP correct, 320 subblocks, congruent and incongruent stimuli
 cc=mean(trans.contextc,2);ci=mean(trans.contexti,2);  %averaged over the 5 "context" transitions
 nc=mean(trans.nightc,2);ni=mean(trans.nighti,2);      %averaged over the 7 overnight transitions
 bc=mean(trans.blockc,2);bi=mean(trans.blocki,2);      %averaged over the remaining 19 transitions
 cm=(cc+ci)/2;nm=(nc+ni)/2;bm=(bc+bi)/2;    % midlines = d'/2

 t=[-285:30:+285] ;    % the transition point is between 10 and 11

 subplot(3,1,1);plot(t(5:10),bc(5:10),'bs-',t(5:10),bi(5:10),'ro-',t(5:10),bm(5:10),'k.-',t(11:20),bc(11:20),'bs-',t(11:20),bi(11:20),'ro-',t(11:20),bm(11:20),'k.-');
 axis([-180 300 0 1.4]);ylabel('\Phi^{-1}(Pcorrect)');set(gca,'xtick',t(5:20),'ytick',[0:0.2:1.4]);
 hh=line([0 0],[0 1.4]);set(hh,'LineStyle','--','Color','k');title('Baseline block transitions');legend('Congruent','Incongruent',4);

 subplot(3,1,2);plot(t(5:10),cc(5:10),'bs-',t(5:10),ci(5:10),'ro-',t(5:10),cm(5:10),'k.-',t(11:20),cc(11:20),'bs-',t(11:20),ci(11:20),'ro-',t(11:20),cm(11:20),'k.-');
 axis([-180 300 0 1.4]);ylabel('\Phi^{-1}(Pcorrect)');set(gca,'xtick',t(5:20),'ytick',[0:0.2:1.4]);
 hh=line([0 0],[0 1.4]);set(hh,'LineStyle','--','Color','k');title('Context switch transitions');

 subplot(3,1,3);plot(t(5:10),nc(5:10),'bs-',t(5:10),ni(5:10),'ro-',t(5:10),nm(5:10),'k.-',t(11:20),nc(11:20),'bs-',t(11:20),ni(11:20),'ro-',t(11:20),nm(11:20),'k.-');
 axis([-180 300 0 1.4]);xlabel('Trials relative to transition');ylabel('\Phi^{-1}(Pcorrect)');set(gca,'xtick',t(5:20),'ytick',[0:0.2:1.4]);
 hh=line([0 0],[0 1.4]);set(hh,'LineStyle','--','Color','k');title('Overnight transitions');


%%%%%%%%%%%%%%%%%%%%%%%   SUBBLOCK_SIZE = 60   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
 trans = PLEtrans_by_sbj(S)         % SUBBLOCK_SIZE = 60
trans = 
      zP320c: [160x13 double]
      zP320i: [160x13 double]
    contextc: [10x13 double]
    contexti: [10x13 double]
      nightc: [10x13 double]
      nighti: [10x13 double]
      blockc: [10x13 double]
      blocki: [10x13 double]

 t=[-270:60:+270] ;    % the transition point is between 5 and 6

% zc=mean(trans.zP320c,2);zi=mean(trans.zP320i,2);      %zP correct, 160 subblocks, congruent and incongruent stimuli
 cc=mean(trans.contextc,2);ci=mean(trans.contexti,2);  %averaged over the 5 "context" transitions
 nc=mean(trans.nightc,2);ni=mean(trans.nighti,2);      %averaged over the 7 overnight transitions
 bc=mean(trans.blockc,2);bi=mean(trans.blocki,2);      %averaged over the remaining 19 transitions
 cm=(cc+ci)/2;nm=(nc+ni)/2;bm=(bc+bi)/2;    % midlines = d'/2

 subplot(3,1,1);plot(t(3:5),bc(3:5),'bs-',t(3:5),bi(3:5),'ro-',t(3:5),bm(3:5),'k.-',t(6:10),bc(6:10),'bs-',t(6:10),bi(6:10),'ro-',t(6:10),bm(6:10),'k.-');
 axis([-180 300 0 1.4]);ylabel('\Phi^{-1}(Pcorrect)');set(gca,'xtick',t(3:10),'ytick',[0:0.2:1.4]);
 hh=line([0 0],[0 1.4]);set(hh,'LineStyle','--','Color','k');title('Baseline block transitions');legend('Congruent','Incongruent',4);

 subplot(3,1,2);plot(t(3:5),cc(3:5),'bs-',t(3:5),ci(3:5),'ro-',t(3:5),cm(3:5),'k.-',t(6:10),cc(6:10),'bs-',t(6:10),ci(6:10),'ro-',t(6:10),cm(6:10),'k.-');
 axis([-180 300 0 1.4]);ylabel('\Phi^{-1}(Pcorrect)');set(gca,'xtick',t(3:10),'ytick',[0:0.2:1.4]);
 hh=line([0 0],[0 1.4]);set(hh,'LineStyle','--','Color','k');title('Context switch transitions');

 subplot(3,1,3);plot(t(3:5),nc(3:5),'bs-',t(3:5),ni(3:5),'ro-',t(3:5),nm(3:5),'k.-',t(6:10),nc(6:10),'bs-',t(6:10),ni(6:10),'ro-',t(6:10),nm(6:10),'k.-');
 axis([-180 300 0 1.4]);xlabel('Trials relative to transition');ylabel('\Phi^{-1}(Pcorrect)');set(gca,'xtick',t(3:10),'ytick',[0:0.2:1.4]);
 hh=line([0 0],[0 1.4]);set(hh,'LineStyle','--','Color','k');title('Overnight transitions');


 fprintf('%+4d  ',t);fprintf('%4.2f  ',bc)
trial#     -270  -210  -150   -90   -30     +30   +90  +150  +210  +270
-----------------------------------------------------------------------
block_c:   0.82  0.93  0.99  1.01  1.03    0.99  1.00  1.02  1.03  1.01
block_m:   0.65  0.69  0.73  0.74  0.75    0.73  0.74  0.76  0.75  0.75
block_i:   0.48  0.46  0.48  0.47  0.47    0.47  0.47  0.49  0.48  0.48

context_c: 0.75  0.94  1.06  1.05  0.97    0.69  0.76  0.90  0.89  1.02
context_m: 0.64  0.73  0.79  0.73  0.78    0.51  0.57  0.63  0.67  0.67
context_i  0.53  0.52  0.53  0.41  0.58    0.32  0.39  0.36  0.44  0.33

night_c:   0.95  0.98  1.03  1.01  0.97    0.62  0.92  1.12  1.12  1.03
night_m:   0.70  0.73  0.75  0.76  0.69    0.62  0.76  0.85  0.81  0.81
night_i:   0.45  0.48  0.46  0.51  0.41    0.62  0.59  0.58  0.50  0.60
-----------------------------------------------------------------------
trial#     -270  -210  -150   -90   -30     +30   +90  +150  +210  +270



%%%%%%%%%%%%%  MODEL, ver 2.1, SUBBLOCK_SIZE = 30, March 4   %%%%%%%%%%%%%%%%%%%%%%%%%
%
 tic;for k=1:100;stim=2-(descr1(:,1,k)==descr1(:,3,k));rcorr=(o1(:,1,k)==descr1(:,1,k));trans(k)=PLM_transitions(stim,rcorr);end;toc
 tic;for k=1:100;stim=2-(descr2(:,1,k)==descr2(:,3,k));rcorr=(o2(:,1,k)==descr2(:,1,k));trans(100+k)=PLM_transitions(stim,rcorr);end;toc
elapsed_time = 11+11 sec  on the GX400
 trans=pack_fields(trans,[],'cols2cols')
trans = 
      zP320c: [320x200 double]
      zP320i: [320x200 double]
    contextc: [20x200 double]
    contexti: [20x200 double]
      nightc: [20x200 double]
      nighti: [20x200 double]
      blockc: [20x200 double]
      blocki: [20x200 double]

 t=[-285:30:+285];pre=[5:10];post=[11:20];   % the transition point is between 10 and 11

% zc=mean(trans.zP320c,2);zi=mean(trans.zP320i,2);      %zP correct, 320 subblocks, congruent and incongruent stimuli
 cc=mean(trans.contextc,2);ci=mean(trans.contexti,2);  %averaged over the 5 "context" transitions
 nc=mean(trans.nightc,2);ni=mean(trans.nighti,2);      %averaged over the 7 overnight transitions
 bc=mean(trans.blockc,2);bi=mean(trans.blocki,2);      %averaged over the remaining 19 transitions
 cm=(cc+ci)/2;nm=(nc+ni)/2;bm=(bc+bi)/2;    % midlines = d'/2

 subplot(3,1,1);plot(t(pre),bc(pre),'bs-',t(pre),bi(pre),'ro-',t(pre),bm(pre),'k.-',t(post),bc(post),'bs-',t(post),bi(post),'ro-',t(post),bm(post),'k.-');
 axis([-180 300 0 1.4]);ylabel('\Phi^{-1}(Pcorrect)');set(gca,'xtick',t(5:20),'ytick',[0:0.2:1.4]);
 hh=line([0 0],[0 1.4]);set(hh,'LineStyle','--','Color','k');title('Baseline block transitions');legend('Congruent','Incongruent',4);

 subplot(3,1,2);plot(t(pre),cc(pre),'bs-',t(pre),ci(pre),'ro-',t(pre),cm(pre),'k.-',t(post),cc(post),'bs-',t(post),ci(post),'ro-',t(post),cm(post),'k.-');
 axis([-180 300 0 1.4]);ylabel('\Phi^{-1}(Pcorrect)');set(gca,'xtick',t(5:20),'ytick',[0:0.2:1.4]);
 hh=line([0 0],[0 1.4]);set(hh,'LineStyle','--','Color','k');title('Context switch transitions');

 subplot(3,1,3);plot(t(pre),nc(pre),'bs-',t(pre),ni(pre),'ro-',t(pre),nm(pre),'k.-',t(post),nc(post),'bs-',t(post),ni(post),'ro-',t(post),nm(post),'k.-');
 axis([-180 300 0 1.4]);xlabel('Trials relative to transition');ylabel('\Phi^{-1}(Pcorrect)');set(gca,'xtick',t(5:20),'ytick',[0:0.2:1.4]);
 hh=line([0 0],[0 1.4]);set(hh,'LineStyle','--','Color','k');title('Overnight transitions');



%%%%%%%%%%%%%%%   EMPIRICAL DATA BY SUBJECT,  March 11, 2003   %%%%%%%%%%%%%%%%%%%%%%%%
%
% SUBBLOCK_SIZE = 60
 t=[-270:60:+270] ;    % the transition point is between 5 and 6

 k=1;r=3*k-3;foo=PLEtrans_by_sbj(S(k));cc=foo.contextc;ci=foo.contexti;cm=(cc+ci)/2;nc=foo.nightc;ni=foo.nighti;nm=(nc+ni)/2;bc=foo.blockc;bi=foo.blocki;bm=(bc+bi)/2;
 subplot(4,3,1+r);plot(t(3:5),cc(3:5),'b.-',t(3:5),ci(3:5),'r.-',t(3:5),cm(3:5),'k.-',t(6:10),cc(6:10),'b.-',t(6:10),ci(6:10),'r.-',t(6:10),cm(6:10),'k.-');axis([-180 300 0 1.6]);ylabel('\Phi^{-1}(Pcorrect)');set(gca,'xtick',t([3 5 6 8 10]),'ytick',[0:0.2:1.6]);hh=line([0 0],[0 1.6]);set(hh,'LineStyle','--','Color','k');if (r==0) title('Switch transitions');end;
 subplot(4,3,2+r);plot(t(3:5),nc(3:5),'b.-',t(3:5),ni(3:5),'r.-',t(3:5),nm(3:5),'k.-',t(6:10),nc(6:10),'b.-',t(6:10),ni(6:10),'r.-',t(6:10),nm(6:10),'k.-');axis([-180 300 0 1.6]);set(gca,'xtick',t([3 5 6 8 10]),'ytick',[0:0.2:1.6]);hh=line([0 0],[0 1.6]);set(hh,'LineStyle','--','Color','k');if (r==0) title('Night transitions');end;
 subplot(4,3,3+r);plot(t(3:5),bc(3:5),'b.-',t(3:5),bi(3:5),'r.-',t(3:5),bm(3:5),'k.-',t(6:10),bc(6:10),'b.-',t(6:10),bi(6:10),'r.-',t(6:10),bm(6:10),'k.-');axis([-180 300 0 1.6]);set(gca,'xtick',t([3 5 6 8 10]),'ytick',[0:0.2:1.6]);hh=line([0 0],[0 1.6]);set(hh,'LineStyle','--','Color','k');if (r==0) title('Baseline transitions');end;
 k=2;...   k=5;r=3*k-15;...
