function  F = PLE_exponent2(params,xdata)

%PLE_EXPONENT2 -- Perceptual learning: exponential law with switch costs.
%
% F = PLE_exponent2(params,xdata)
%
% This function is a variant of PLE_EXPONENT used in the first perceptual
% learning experiment (PLExp1, with feedback).  The two time constants
% are fixed to their values estimated from PLExp1 (see DPRIME_FITS.TXT):
%   TAU = 10.1551 ; TAU_S = 1.1784
% These are the values reported in Table 1 of the Psych Review paper.
%
% PLE_EXPONENT2 implements an additive mixture of two exponential
% curves -- "main carrier" and "switch cost". The basic equation is:
%   F(T,R) = D.*(1 - g*exp(-(T-1)/10.1551) - s*exp(-(R-1)/1.1784)
%
% XDATA is a two-column matrix with 36 rows, one per expeimental block.
% XDATA(:,1) is the block number T since the beginning of the experiment.
% XDATA(:,2) is the number of blocks R since the last switch.
% XDATA must be supplied explicitly; there is no default.
%
% PARAMS must be a 5-element vector: params=[D1,D2,D3,g,s].
% It corresponds to the 7-parameter "mode" of PLExp1/PLE_EXPONENT with
% the time constants TAU and TAU_S fixed as indicated above.
%
% F is a column vector with the same number of rows as XDATA.
%
% See PLExp2/PLE2_results.txt to see PLE_EXPONENT2 in action.
%
% See also PLE_EXPONENT, PLE_CURVEFIT.

% Original coding by Alexander Petrov, UC Irvine.
% $Revision: 1.0 $  $Date: 2004/11/29 10:20 $

%-- Decipher arguments, XDATA must be supplied explicitly.
t = xdata(:,1) ;
r = xdata(:,2) ;

%-- Hard-wired time constants
tau = 10.1551 ;
tau_s = 1.1784 ;

%-- Dechipher PARAMS
L = length(params) ;
if (L==5)
   D1=params(1) ; D2=params(2) ; D3=params(3) ;
   g=params(4) ; s=params(5) ;
   f = (1 - g.*exp((1-t)./tau) - s.*exp((1-r)./tau_s)) ;  % [ 36x1]
   F = [D1.*f ; D2.*f ; D3.*f] ;                          % [108x1]
else
   error('PARAMS should have exactly 5 elements: [D1,D2,D3,g,s].') ;
end

%--- Return F
%%%%% End of PLE_EXPONENT2.M
