def pf(parameters, psyfun='cGauss'):
"""Generate conditional probabilities from psychometric function.
Arguments
---------
parameters: ndarray (float64) containing parameters as columns
mu : threshold
sigma : slope
gamma : guessing rate (optional), default is 0.2
lambda : lapse rate (optional), default is 0.04
x : stimulus intensity
psyfun : type of psychometric function.
'cGauss' cumulative Gaussian
'Gumbel' Gumbel, aka log Weibull
Returns
-------
1D-array of conditional probabilities p(response | mu,sigma,gamma,lambda,x)
"""
# Unpack parameters
if np.size(parameters, 1) == 5:
[mu, sigma, gamma, llambda, x] = np.transpose(parameters)
elif np.size(parameters, 1) == 4:
[mu, sigma, llambda, x] = np.transpose(parameters)
gamma = llambda
elif np.size(parameters, 1) == 3:
[mu, sigma, x] = np.transpose(parameters)
gamma = 0.2
llambda = 0.04
else: # insufficient number of parameters will give a flat line
psyfun = None
gamma = 0.2
llambda = 0.04
# Psychometric function
ones = np.ones(np.shape(mu))
if psyfun == 'cGauss':
# F(x; mu, sigma) = Normcdf(mu, sigma) = 1/2 * erfc(-sigma * (x-mu) /sqrt(2))
z = np.divide(np.subtract(x, mu), sigma)
p = 0.5 * erfc(-z / np.sqrt(2))
elif psyfun == 'Gumbel':
# F(x; mu, sigma) = 1 - exp(-10^(sigma(x-mu)))
p = ones - np.exp(-np.power((np.multiply(ones, 10.0)), (np.multiply(sigma, (np.subtract(x, mu))))))
elif psyfun == 'Weibull':
# F(x; mu, sigma)
p = 1 - np.exp(-(np.divide(x, mu)) ** sigma)
else:
# flat line if no psychometric function is specified
p = np.ones(np.shape(mu))
y = gamma + np.multiply((ones - gamma - llambda), p)
return y
评论列表
文章目录