Skip to content

Commit b47307b

Browse files
committed
Improve docstring for psychometric functions in tools
1 parent b977910 commit b47307b

File tree

2 files changed

+47
-10
lines changed

2 files changed

+47
-10
lines changed

psignifit/sigmoids.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ def __eq__(self, o: object) -> bool:
6161
def __call__(self, stimulus_level: N, threshold: N, width: N, gamma: N = 0, lambd: N = 0) -> N:
6262
""" Calculate the sigmoid value at specified stimulus levels.
6363
64+
See Eq 1 in Schuett, Harmeling, Macke and Wichmann (2016).
65+
6466
Args:
6567
stimulus_level: Stimulus level value
6668
threshold: Threshold at `PC`

psignifit/tools.py

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ def pool_blocks(data: np.ndarray, max_tol=0, max_gap=np.inf, max_length=np.inf):
5454
def psychometric(stimulus_level, threshold, width, gamma, lambda_, sigmoid_name):
5555
""" Psychometric function aka proportion correct function.
5656
57-
Generates proportion correct values for a range of stimulus levels given a
58-
sigmoid.
59-
Implementation of Eq 1 in Schuett, Harmeling, Macke and Wichmann (2016)
57+
This is a convenience function used mostly for testing and demos, to make the intent of creating a psychometric
58+
function more explicit. The implementation simply combines creating a `Sigmoid` object using the sigmoid name,
59+
and calling the object to generate the proportion correct values corresponding to `stimulus_level`.
6060
6161
Parameters:
6262
stimulus_level: array
@@ -69,24 +69,59 @@ def psychometric(stimulus_level, threshold, width, gamma, lambda_, sigmoid_name)
6969
Guess rate
7070
lambda_: float
7171
Lapse rate
72-
sigmoid: callable
73-
Sigmoid function to use. Default is Gaussian
72+
sigmoid_name: callable
73+
Name of sigmoid function to use. See `psignifit.sigmoids.ALL_SIGMOID_NAMES` for the list of available
74+
sigmoids.
7475
7576
Returns:
7677
psi: array
77-
proportion correct values for each stimulus level
78+
Proportion correct values for each stimulus level
7879
7980
"""
80-
# we use the defaults for pc and alpha in the sigmoids:
81-
# pc = 0.5
82-
# alpha = 0.05
8381
sigmoid = sigmoid_by_name(sigmoid_name)
8482
psi = sigmoid(stimulus_level, threshold=threshold, width=width, gamma=gamma, lambd=lambda_)
8583
return psi
8684

8785

8886
def psychometric_with_eta(stimulus_level, threshold, width, gamma, lambda_,
89-
sigmoid_name, eta, random_state=np.random.RandomState(42)):
87+
sigmoid_name, eta, random_state=None):
88+
""" Psychometric function with overdispersion.
89+
90+
This is a convenience function used mostly for testing and demos. Just like the function `psychometric`, it
91+
computes proportion correct values for a given psychometric function type, specified by name. In addition,
92+
it adds some additional noise to the data, so that its variance is compatible with the overdispersion
93+
parameter `eta`.
94+
95+
See Section 2.2 in Schuett, Harmeling, Macke and Wichmann (2016).
96+
97+
Parameters:
98+
stimulus_level: array
99+
Values of the stimulus value
100+
threshold: float
101+
Threshold of the psychometric function
102+
width: float
103+
Width of the psychometric function
104+
gamma: float
105+
Guess rate
106+
lambda_: float
107+
Lapse rate
108+
sigmoid_name: callable
109+
Name of sigmoid function to use. See `psignifit.sigmoids.ALL_SIGMOID_NAMES` for the list of available
110+
sigmoids.
111+
eta: float
112+
Overdispersion parameter
113+
random_state: np.RandomState
114+
Random state used to generate the additional variance in the data.
115+
If None, NumPy's default random number generator is used.
116+
117+
Returns:
118+
psi: array
119+
Proportion correct values for each stimulus level
120+
121+
"""
122+
123+
if random_state is None:
124+
random_state = np.random.default_rng()
90125

91126
psi = psychometric(stimulus_level, threshold, width, gamma, lambda_, sigmoid_name)
92127
new_psi = []

0 commit comments

Comments
 (0)