function run2002FDtask(Motion,coherences,period,A9,B9,g_f,g_h,lambda,sigLIP,pre_y,muu,n_f,n_h,Tsacc,g_BG,g_delay,varargin);
% run2002FDtask :: Function, which is called by runTask.m, to run the fixed duration task (Roitman & Shadlen, 2002)
%
%% Input variables
% Motion :: 5D matrix that stores the dynamics of population activity of
% middle temporal and medial superior temporal neurons
% [1: time steps, 2: preferred direction, 3: coherence level, 4: trial, 5:
% middle temporal or medial superior temporal]
%
% coherences :: Coherence levels between 0 and 100%
%
% period :: Duration for which recordings were made in model middle
% temporal and medial superior temporal areas
%
% A9 :: Parameter that scales passive decay in lateral intraparietal
% neuronal responses
%
% B9 :: Maximal rate of the model lateral intraparietal neurons
%
% g_f :: Parameter that scales the gain of self-excitation in lateral
% intraparietal recurrent competitive field
%
% g_h :: Parameter that scales the gain of recurrent inhition in lateral
% intraparietal recurrent competitive field
%
% lambda :: Parameter that scales the bottom-up excitation to a lateral
% intraparietal cellfrom the media superior temporal pool tuned to the
% preferred direction
%
% sigLIP :: Standard deviation of the Brownian motion process that injects
% noise into the dynamics of lateral intraparietal area neurons
%
% pre_y :: Pre-motion onset period rate of each model lateral intraparietal
% neuron whose receptive field contains a choice target
%
% muu :: Threshold parameter of the recurrent signal functions in the
% lateral intraparietal recurrent competitive field
%
% n_f :: Steepness parameter of the self-excitatory signal function in the
% lateral intraparietal recurrent competitive field
%
% n_h :: Steepness parameter of the recurrent inhibitory signal function in
% the lateral intraparietal recurrent competitive field
%
% Tsacc :: Rate of the selected lateral intraparietal cell when the saccade
% is initiated
%
% g_BG :: Parameter that scales the gain of self-excitation for the selected
% lateral intraparietal call after the GO signal, which signifies the end
% of the variable delay period
%
% g_delay :: Parameter that scales the gain of self-excitation during the
% variable delay period for the selected lateral intraparietal cell
%
%% Reference
% Grossberg, S. and Pilly, P. K. (2008). Temporal dyanamics of decision-making during motion perception in the visual cortex. Vision Research, 48(12), 1345-1373.
%
%% Author
% Praveen K. Pilly (advaitp@gmail.com)
%
%% License policy
% Written by Praveen K. Pilly, Department of Cognitive and Neural Systems, Boston University
% Copyright 2009, Trustees of Boston University
%
% Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted
% without fee, provided that the above copyright notice and this permission notice appear in all copies, derivative works and
% associated documentation, and that neither the name of Boston University nor that of the author(s) be used in advertising or
% publicity pertaining to the distribution or sale of the software without specific, prior written permission. Neither Boston
% University nor its agents make any representations about the suitability of this software for any purpose. It is provided "as
% is" without warranty of any kind, either express or implied. Neither Boston University nor the author indemnify any
% infringement of copyright, patent, trademark, or trade secret resulting from the use, modification, distribution or sale of
% this software.
%
%% Last modified
% June 25, 2009
%%
% fixed time step of numerical integration
dt=0.001; % (in sec)
cohL=size(Motion,3);
numtrials=size(Motion,4);
duration=3.5; % (in sec): the time for which LIP responses are recorded
num=length(0:dt:duration); % number of time steps
Y1c=zeros(num,numtrials,cohL); % correct trial LIP dynamics of recorded population
Y2c=zeros(num,numtrials,cohL); % correct trial LIP dynamics of the other population
% 'RT' in FD task just implies time of saccade initiation with respect to motion onset
RTc=zeros(numtrials,cohL);
Y1e=zeros(num,numtrials,cohL); % error trial LIP dynamics of recorded population
Y2e=zeros(num,numtrials,cohL); % error trial LIP dynamics of the other population
RTe=zeros(numtrials,cohL);
Acc=zeros(1,cohL); % tracks the number of correct responses
for coh=1:cohL
coh % to track the progress
for trial=1:numtrials
% trial % to track the progress
% To set the pseudo-random number generator to a random state to
% begin with
rand('state',sum(100*clock))
randn('state',sum(100*clock))
% Note stimulus grid is 60 x 60
x1=Motion(:,1,coh,trial,2)/(60*60); % average rightward MST cell activity
x2=Motion(:,5,coh,trial,2)/(60*60); % average leftward MST cell activity
% run model LIP module for 2002 FD task
[Y1,Y2,Ch,RTsacc]=MODE_lip_FD(x1,x2,num,A9,B9,g_f,g_h,lambda,sigLIP,pre_y,muu,n_f,n_h,Tsacc,g_BG,g_delay);
if Ch==1
RTc(trial,coh)=RTsacc;
Y1c(:,trial,coh)=Y1;
Y2c(:,trial,coh)=Y2;
% Remember that the correct stimulus direction in the simulations
% is always rightward (d=1), for simplicity
Acc(coh)=Acc(coh)+1;
elseif Ch==2
RTe(trial,coh)=RTsacc;
Y1e(:,trial,coh)=Y1;
Y2e(:,trial,coh)=Y2;
end
if nargin > 0
hwait = varargin{1};
waitbar((1 + trial+(coh-1)*numtrials)/(cohL*numtrials + 1), ...
hwait, 'Run in progress . . .');
end
end
end
% Convert coherence levels into log10 scale for usage in figures
log10cohs=max(log10(coherences+eps),-0.1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Psychometric function
% clear global x_ml t_ml n_xl
%
% [w_ml]=ml_e(coherences',Acc'/numtrials,numtrials);
% % The first two inputs need to be column vectors
%
% Xcoh=0.7:0.1:10; Xcoh=[Xcoh 11:100]; % in units of percentage
% Yperf=1-0.5*exp(-(Xcoh/w_ml(1,1)).^w_ml(2,1));
%
% % Fitted parameters of the psychometric function
% alpha=w_ml(1,1) % coherence threshold
% beta=w_ml(2,1) % parameter that controls the steepness of the psychometric function
figure
% plot(log10(Xcoh),100*Yperf,'k')
% hold on
plot(log10cohs,Acc*100/numtrials,'ko-')
hold off
xlabel('Motion strength (% coherence)','Fontsize',15)
ylabel('Accuracy (% correct)','Fontsize',15)
title('Psychometric function','Fontsize',15)
set(gca,'Fontsize',12)
box off
axis([-0.15 log10(52) 40 100])
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Average LIP responses during correct trials at all coherences
[Y1c_lhs,Y2c_lhs]=left_part_lipFD(RTc,Y1c,Y2c,cohL,numtrials,dt);
[Y1e_lhs,Y2e_lhs]=left_part_lipFD(RTe,Y1e,Y2e,cohL,numtrials,dt);
[Y1c_rhs,Y2c_rhs]=right_part_lipFD(RTc,Y1c,Y2c,cohL,numtrials,dt);
[Y1e_rhs,Y2e_rhs]=right_part_lipFD(RTe,Y1e,Y2e,cohL,numtrials,dt);
colors=['bgrcmy'];
figure
hold on
for coh=1:cohL
if max(RTc(:,coh))~=0 % to check if at least one correct trial at a coherence level has occurred
% Left portion
plot(0:1000*dt:1000,Y1c_lhs(:,coh),colors(coh)) % x-axis is in msec
plot(0:1000*dt:1000,Y2c_lhs(:,coh),[colors(coh) '--'])
% Right portion
plot(1300:1900,Y1c_rhs(:,coh),colors(coh))
plot(1300:1900,Y2c_rhs(:,coh),[colors(coh) '--'])
end
end
hold off
xlabel('Time (ms)','Fontsize',15)
ylabel('Activity','Fontsize',15)
set(gca,'Fontsize',12)
axis([0 1900 20 70])
box off
title('Average LIP responses during correct trials at all coherence levels','Fontsize',15)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Correct and error trial average LIP responses at a given coherence
coh=2; % select coherence level here
% error trial average responses are shown in black
figure
hold on
% Correct trials
if max(RTc(:,coh))~=0 % to check if at least one correct trial at a coherence level has occurred
% Left portion
plot(0:1000*dt:1000,Y1c_lhs(:,coh),colors(coh)) % x-axis is in msec
plot(0:1000*dt:1000,Y2c_lhs(:,coh),[colors(coh) '--'])
% Right portion
plot(1300:1900,Y1c_rhs(:,coh),colors(coh))
plot(1300:1900,Y2c_rhs(:,coh),[colors(coh) '--'])
end
% Error trials
if max(RTe(:,coh))~=0 % to check if at least one error trial at a coherence level has occurred
% Left portion
plot(0:1000*dt:1000,Y1e_lhs(:,coh),'k-') % x-axis is in msec
plot(0:1000*dt:1000,Y2e_lhs(:,coh),'k--')
% Right portion
plot(1300:1900,Y1e_rhs(:,coh),'k-')
plot(1300:1900,Y2e_rhs(:,coh),'k--')
end
hold off
xlabel('Time (ms)','Fontsize',15)
ylabel('Activity','Fontsize',15)
set(gca,'Fontsize',12)
axis([0 1900 20 70])
box off
title('Correct and error trial average LIP responses at 3.2% coherence for which the model monkey makes errors','Fontsize',15)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% To plot individual trial LIP responses
trial=1; % choose trial here
coh=1; % choose coherence here
figure
hold on
if RTc(trial,coh)~=0
plot(Y1c(:,trial,coh),'r')
plot(Y2c(:,trial,coh),'r--')
% plots motion offset time
plot([1/dt 1/dt],[0 70],'k--') % period is in secs
else
plot(Y1e(:,trial,coh),'r')
plot(Y2e(:,trial,coh),'r--')
% plots motion offset time
plot([1/dt 1/dt],[0 70],'k--') % period is in secs
end
hold off
xlabel('Time (ms)','Fontsize',15)
ylabel('Activity','Fontsize',15)
set(gca,'Fontsize',12)
box off
axis([0 duration/dt 0 70])
title('An individual trial LIP responses for 0% coherence','Fontsize',15)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
return