def velocity_ExponentialAnti_SigmoidalPursuit(x, target_dir, baseline, anti_onset, anti_slope, anti_offset, pursuit_slope, horizontal_shift, steady_state, fit_baseline:bool=False) :
'''
Model of eye-velocity over time, in a smooth pursuit task.
Anticipatory phase is modeled as an exponential, and initial visually guided pursuit as a sigmoid
Parameters
----------
x : ndarray
time in milliseconds
target_dir : int
direction of the target
-1 (corresponding usually to left/down) or 1 (corresponding usually to right/up)
anti_onset : int
anticipation onset in milliseconds
anti_slope : float
defines the slope of the sigmoid corresponding to the anticipatory phase
anti_offset : int
offset of the anticipatory phase in milliseconds
pursuit_slope : float
defines the slope of the sigmoid corresponding to the initial phase of the visually-guided pursuit
horizontal_shift : int
shift in the sigmoid function corresponding to the initial phase of the visually-guided pursuit
steady_state : float
eye velocity reached in the late phase of visually-guided pursuit (in degrees/sec)
fit_baseline : bool
if ``True``, fits a flat regression corresponding to the baseline velocity
this parameter is intended to be used when there were problems with the eye-tracker calibration,
such that eye velocity is not centered in zero during the fixation phase
Returns
-------
velocity : list
model of the eye velocity in deg/sec
'''
if not fit_baseline: baseline = 0
anti_sign = np.sign(anti_slope)
anti_slope = abs(anti_slope)/1000 # to switch from deg/sec to deg/ms
pursuit_slope = target_dir*pursuit_slope/1000
steady_state = steady_state*target_dir
anti_onset = np.floor(anti_onset)
anti_offset = np.floor(anti_offset)
time = x
idx_baseline = np.where(time < anti_onset)[0]
idx_anticipation = np.where((time >= anti_onset)&(time < anti_offset))[0]
idx_pursuit = np.where(time >= anti_offset)[0]
x_anticipation = np.arange(0,len(idx_anticipation),1)
x_pursuit = np.arange(0,len(idx_pursuit),1)
velocity = np.zeros(len(time))
velocity[idx_baseline] = baseline * np.ones(len(idx_baseline))
velocity[idx_anticipation] = baseline + anti_sign*(np.exp(anti_slope*x_anticipation)-1)
max_anticipation = anti_sign*max(abs(velocity))
sigmoid_pursuit = (steady_state-max_anticipation)/(1 + np.exp(-pursuit_slope*(x_pursuit-horizontal_shift)))
velocity[idx_pursuit] = max_anticipation + sigmoid_pursuit - sigmoid_pursuit[0]
return velocity