-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfull_ddm.jl
114 lines (96 loc) · 2.92 KB
/
full_ddm.jl
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using GLMakie, Colors, Distributions
# Array containing the steps of a single DDM process
x = Observable(Vector{Float64}())
t = Observable(Vector{Float64}())
# Arrays containing the Positive and Negative response times
p_pos = Observable(Vector{Float64}())
p_neg = Observable(Vector{Float64}())
# Update drift diffusion model
function update_ddm()
x[] = [0.0]
tn = 0.000
while true
tn += 0.001
x_new = x[][end] + rand(Normal(δ[], σ[]))
push!(x[], x_new)
if abs(x_new) >= α[]
break
end
end
rt = tn + τ[]
if x[][end] >= α[]
push!(p_pos[], rt)
else
push!(p_neg[], rt)
end
t[] = [range(τ[], rt, length=length(x[]));]
notify(x)
notify(p_neg)
notify(p_pos)
end
# Figure
fig = Figure();
# SliderGrid
sg = SliderGrid(
fig[1, 1:8],
(label="Drift Rate", range=-1.0:0.001:1.0, format="{:.3f}", startvalue=0.005),
(label="Decision Bound", range=0.1:0.001:2.0, format="{:.1f}", startvalue=1.0),
(label="Non-Decision Time", range=0.0:0.001:1.0, format="{:.1f}", startvalue=0.3),
(label="Stochastic Noise", range=0.0:0.001:1.0, format="{:.3f}", startvalue=0.1),
(label="Maximum Time", range=1:0.1:10, format="{:.1f}", startvalue=1)
)
# Observables
δ, α, τ, σ, max_t = [s.value for s in sg.sliders]
n_α = lift(α) do α
-α
end
# Buttons
new_btn = Button(fig[1, 9], label="New trial")
mtp_btn = Button(fig[1, 10], label="50 new trials")
rst_btn = Button(fig[2, 9:10], label="Reset axes")
on(new_btn.clicks) do n
update_ddm()
end
on(mtp_btn.clicks) do n
for i in 1:50
update_ddm()
end
end
# Middle Axis
ax_middle = Axis(fig[4, 1:10], xlabel="Time", ylabel="Decision Variable", title="Drift Diffusion Model")
line_middle = lines!(ax_middle, t, x, color=:black)
line_bound_pos = hlines!(ax_middle, α, color=:teal, linestyle=:dash)
line_bound_neg = hlines!(ax_middle, n_α, color=:coral, linestyle=:dash)
line_non_decision_time = vlines!(ax_middle, τ, color=:black, linestyle=:dash)
# Top Axis
ax_top = Axis(fig[3, 1:10], xlabel="Time", ylabel="Probability")
hist_top = hist!(ax_top, p_pos, bins=range(0.0, max_t[], length=100), color=:teal)
# dens_top = density!(ax_top, p_pos, color=:teal)
ylims!(0, 50)
hidespines!(ax_top)
hidexdecorations!(ax_top)
# Bottom Axis
ax_bottom = Axis(fig[5, 1:10], xlabel="Time", ylabel="Probability")
hist_bottom = hist!(ax_bottom, p_neg, bins=range(0.0, max_t[], length=100), color=:coral)
# dens_bottom = density!(ax_bottom, p_neg, color=:coral)
ylims!(0, 50)
hidespines!(ax_bottom)
hidexdecorations!(ax_bottom)
ax_bottom.yreversed = true
linkyaxes!(ax_top, ax_bottom)
lift(α) do α
reset_limits!(ax_middle)
end
on(max_t) do _
# reset_limits!(ax_middle)
reset_limits!(ax_top)
reset_limits!(ax_bottom)
end
on(rst_btn.clicks) do n
autolimits!(ax_top)
autolimits!(ax_bottom)
end
# Link axes
linkxaxes!(ax_middle, ax_top, ax_bottom)
# Show the figure
display(fig)