function  F = PLE_power(params,xdata)

%PLE_POWER -- Perceptual learning following power law with switch costs.
%
%  F = PLE_power(params,xdata)
%  F = PLE_power(params)
%
%  This function is designed to be minimized via LSQCURVEFIT.
%  It implements an additive mixture of two power curves -- "main carrier"
%  and "switch cost":
%    F(T,R) = F_as + (F_in-F_as)*T^(-alpha) + s*R^(-beta)
%
%  XDATA is a two-column matrix, typically with 32 rows (one per 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.
%  If not supplied, XDATA defaults to [1:32 ; Inf,1:8,1:8,1:8,1:6,1]'.
%  PARAMS is a vector specifying the following five parameters:
%   1. F_as -- asymptotic F value (when T=Inf)
%   2. F_in -- initial F value (when T=1)
%   3. alpha-- primary learning rate
%   4. s    -- switch cost (when R=1)
%   5. beta -- rate of recovery from switches
%
%  See also PLE_CURVEFIT, PLE_EXPONENT, LSQCURVEFIT.

%  Original coding by Alexander Petrov, UC Irvine.
%  $Revision: 1.0 $  $Date: 2002/02/13 18:26 $

%-- Decipher arguments
if (nargin < 2)    % XDATA not supplied?
   t = [1:32]' ;                   % time since beginning of experiment
   r = [Inf,1:8,1:8,1:8,1:6,1]' ;  % time since last switch
else
   t = xdata(:,1) ;
   r = xdata(:,2) ;
end

F_as = params(1) ;                 % asymptotic level
delta_F = params(2) - F_as ;       % improvement = F_initial - F_asympt
minus_alpha = -params(3) ;         % primary learning rate
s = params(4) ;                    % switch cost
minus_beta = -params(5) ;          % rate of recovery from switches

%-- Main work
F = F_as + delta_F * (t.^minus_alpha) + s * (r.^minus_beta) ;

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