-
Notifications
You must be signed in to change notification settings - Fork 1
/
Simulate CDM.py
67 lines (55 loc) · 2.02 KB
/
Simulate CDM.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import numpy as np
def SimCDM(params, dt=.001, n=100):
"""
SimCDM(params, dt=.001, n=100)
Simulate a dataset from the Circular Diffusion Model.
Parameters
----------
params : list
A list of real numbers containing the parameter values as [decision criterion, multiplier for decision criterion range,
drift length, drift angle, multiplier for the standard deviation of radial component of the drift, multiplier for the
standard deviation of tangental component of the drift, non-decision time, range of the non-decision time variability]
dt: float
The time step.
n: int
The number of trials.
Returns
-------
out : numpy array
An array of shape (2,n) containing the choice angle and responce time pairs for all trials.
Notes
-----
The variability on the radial and tangental components of the drift vector is considered to follow the Normal distribution. The
variability on the decision criterion and non-decision time is considered to follow the Uniform distribution.
Set variability parameter values to zero to simulate data from the simple CDM.
"""
a = params[0]
sa = a*params[1]
v = params[2]
bias = params[3]
eta1 = v*params[4]
eta2 = v*params[5]
t0 = params[6]
st = params[7]
hit = False
x = [0,0]
t = 0
RT = []
CA = []
for i in range(n):
A = np.random.uniform(a-sa/2, a+sa/2)
A2 = A**2
drift = np.random.normal([v,0], [eta1,eta2])
V = np.array([drift[0]*np.cos(bias)-drift[1]*np.sin(bias), drift[0]*np.sin(bias)+drift[1]*np.cos(bias)])
T = np.random.uniform(t0-st/2, t0+st/2)
while not hit:
x += np.random.normal(V*dt, [np.sqrt(dt),np.sqrt(dt)])
t += dt
hit = x[0]**2 + x[1]**2 >= A2
else:
RT.append(t+T)
CA.append(np.arctan2(x[1],x[0]))
x = [0,0]
t = 0
hit = False
return np.array([CA, RT])