Skip to content

Commit 150e69d

Browse files
committed
increase unit test coverage
1 parent 5a3d2b5 commit 150e69d

File tree

10 files changed

+155
-53
lines changed

10 files changed

+155
-53
lines changed

src/multi_choice_models/AttentionalDiffusion.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ function rand(rng::AbstractRNG, dist::AbstractaDDM; fixate, Δt = 0.001)
205205
while abs(v) < α
206206
t += Δt
207207
location = fixate()
208-
v += increment(rng, dist, location)
208+
v += increment!(rng, dist, location)
209209
end
210210
choice = (v < α) + 1
211211
return (; choice, rt = t)
@@ -275,10 +275,10 @@ function survivor(d::AbstractaDDM, choice::Int, ub::Real, args...; fixate, kwarg
275275
return survivor(Random.default_rng(), d, choice, fixate, ub, args...; fixate, kwargs...)
276276
end
277277

278-
increment(dist::AbstractaDDM, location) = increment(Random.default_rng(), dist, location)
278+
increment!(dist::AbstractaDDM, location) = increment!(Random.default_rng(), dist, location)
279279

280280
"""
281-
increment(rng::AbstractRNG, dist::aDDM, location)
281+
increment!(rng::AbstractRNG, dist::aDDM, location)
282282
283283
Returns the change evidence for a single iteration.
284284
@@ -288,7 +288,7 @@ Returns the change evidence for a single iteration.
288288
- `dist::aDDM`: a model object for the attentional drift diffusion model
289289
- `location`: an index for fixation location
290290
"""
291-
function increment(rng::AbstractRNG, dist::aDDM, location)
291+
function increment!(rng::AbstractRNG, dist::aDDM, location)
292292
(; σ, ν, θ, Δ) = dist
293293
# option 1
294294
if location == 1
@@ -349,7 +349,7 @@ function simulate(
349349
while abs(x) < α
350350
t += Δt
351351
location = _fixate()
352-
x += increment(model, location)
352+
x += increment!(model, location)
353353
push!(evidence, x)
354354
push!(time_steps, t)
355355
end

src/multi_choice_models/maaDDM.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ get_pdf_type(d::maaDDM) = Approximate
153153
n_options(d::maaDDM) = size(d.ν, 1)
154154

155155
"""
156-
increment(rng, dist::maaDDM, location)
156+
increment!(rng, dist::maaDDM, location)
157157
158158
Returns the change evidence for a single iteration.
159159
@@ -162,7 +162,7 @@ Returns the change evidence for a single iteration.
162162
- `dist::maaDDM`: a model object for the multiattribute attentional drift diffusion model
163163
- `location`: an index for fixation location
164164
"""
165-
function increment(rng, dist::maaDDM, location)
165+
function increment!(rng, dist::maaDDM, location)
166166
(; ν, θ, ϕ, ω, Δ, σ) = dist
167167
# option 1, attribute 1
168168
if location == 1
@@ -177,9 +177,10 @@ function increment(rng, dist::maaDDM, location)
177177
return Δ *** ν[1, 1] - ν[2, 1]) + (1 - ω) * ϕ ** ν[1, 2] - ν[2, 2])) +
178178
noise(rng, σ)
179179
# option 2, attribute 2
180-
else
180+
elseif location == 4
181181
return Δ ** ω ** ν[1, 1] - ν[2, 1]) + (1 - ω) ** ν[1, 2] - ν[2, 2])) +
182182
noise(rng, σ)
183183
end
184+
@argcheck location [1,2,3,4]
184185
return -100.0
185186
end

src/single_choice_models/ShiftedLogNormal.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,20 @@ function pdf(dist::AbstractShiftedLogNormal, rt::Real)
5959
return pdf(LogNormal(ν, σ), rt - τ)
6060
end
6161

62+
function cdf(dist::AbstractShiftedLogNormal, rt::Real)
63+
(; τ, ν, σ) = dist
64+
@argcheck τ rt
65+
return cdf(LogNormal(ν, σ), rt - τ)
66+
end
67+
6268
function rand(rng::AbstractRNG, dist::AbstractShiftedLogNormal, n_trials::Int)
6369
(; τ, ν, σ) = dist
6470
return rand(rng, LogNormal(ν, σ), n_trials) .+ τ
6571
end
6672

6773
function rand(rng::AbstractRNG, dist::AbstractShiftedLogNormal)
6874
(; τ, ν, σ) = dist
69-
return rand(rng, LogNormal(ν, σ)) .+ τ
75+
return rand(rng, LogNormal(ν, σ)) + τ
7076
end
7177

7278
function params(d::AbstractShiftedLogNormal)

src/single_choice_models/ex_gaussian.jl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ to model reaction time distributions. Note that this is not technically a sequen
88
99
- `μ::T`: mean of Gaussian component. μ ∈ ℝ⁺.
1010
- `σ::T`: standard deviation of Gaussian component. σ ∈ ℝ⁺
11-
- `τ::T`: mean of exponential component. τ ∈ [0, min_rt]
11+
- `τ::T`: mean of exponential component. τ ∈ (0, min_rt]
1212
1313
# Constructors
1414
@@ -41,7 +41,7 @@ struct ExGaussian{T <: Real} <: SSM1D
4141
function ExGaussian(μ::T, σ::T, τ::T) where {T <: Real}
4242
@argcheck μ 0
4343
@argcheck σ 0
44-
@argcheck τ 0
44+
@argcheck τ > 0
4545
return new{T}(μ, σ, τ)
4646
end
4747
end
@@ -64,9 +64,6 @@ end
6464

6565
function logpdf(d::ExGaussian, rt::Float64)
6666
(; μ, σ, τ) = d
67-
if τ == 0
68-
return -Inf
69-
end
7067
return log(1 / τ) +
7168
- rt) / τ +
7269
^2 / 2τ^2) +

src/single_choice_models/wald.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ function simulate(rng::AbstractRNG, model::Wald; Δt = 0.001)
114114
t = 0.0
115115
evidence = [0.0]
116116
time_steps = [t]
117-
ν′ = rand(truncated(Normal(ν, η), 0, Inf))
118-
while x .< α
117+
ν′ = rand(rng, truncated(Normal(ν, η), 0, Inf))
118+
while x < α
119119
t += Δt
120120
x = increment!(rng, model, x, ν′; Δt)
121121
push!(evidence, x)

0 commit comments

Comments
 (0)