Skip to content

Commit

Permalink
add DDM tests and adjust DDM plot docs
Browse files Browse the repository at this point in the history
  • Loading branch information
itsdfish committed Jun 18, 2023
1 parent 26dfe72 commit e012bd3
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 10 deletions.
1 change: 1 addition & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ makedocs(
pages = ["Home" => "index.md",
"API" => "api.md",
"Models" => ["Attentional Drift Diffusion" => "aDDM.md",
"Drift Diffusion Model" => "DDM.md",
"Leaky Competing Accumulator" => "lca.md",
"Linear Ballistic Accumulator" => "lba.md",
"Lognormal Race Model" => "lnr.md",
Expand Down
6 changes: 3 additions & 3 deletions docs/src/DDM.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ The duration for a non-decisional processes (encoding and response execution). T
An indicator of an an initial bias towards a decision. The z parameter is relative to a (i.e. it ranges from 0 to 1).

```@example DDM
z = 0.25
z = 0.50
```

### DDM Constructor
Expand Down Expand Up @@ -94,14 +94,14 @@ rts1 = rts[choices .== 1]
rts2 = rts[choices .== 2]
# probability of choosing 1
p1 = length(rts1) / length(rts)
t_range = range(.30, 2, length=100)
t_range = range(.30, 1, length=100)
# pdf for choice 1
pdf1 = pdf.(dist, (1,), t_range)
# pdf for choice 2
pdf2 = pdf.(dist, (2,), t_range)
# histogram of retrieval times
hist = histogram(layout=(2,1), leg=false, grid=false,
xlabel="Reaction Time", ylabel="Density", xlims = (0,1.5))
xlabel="Reaction Time", ylabel="Density", xlims = (0,1.))
histogram!(rts1, subplot=1, color=:grey, bins = 200, norm=true, title="Choice 1")
plot!(t_range, pdf1, subplot=1, color=:darkorange, linewidth=2)
histogram!(rts2, subplot=2, color=:grey, bins = 150, norm=true, title="Choice 2")
Expand Down
7 changes: 0 additions & 7 deletions test/DDM_tests.jl

This file was deleted.

101 changes: 101 additions & 0 deletions test/ddm_tests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
@safetestset "DDM Tests" begin
@safetestset "DDM pdf 1" begin
using SequentialSamplingModels
using Test
using KernelDensity
using Random
Random.seed!(654)

dist = DDM=1.0, α = .8, z = .5, τ = .3)
choice,rt = rand(dist, 10^5)
rt1 = rt[choice .== 1]
p1 = mean(choice .== 1)
p2 = 1 - p1
approx_pdf = kde(rt1)
x = range(.301, 1.5, length=100)
y′ = pdf(approx_pdf, x) * p1
y = pdf.(dist, (1,), x)
@test y′ y rtol = .10

rt2 = rt[choice .== 2]
approx_pdf = kde(rt2)
y′ = pdf(approx_pdf, x) * p2
y = pdf.(dist, (2,), x)
@test y′ y rtol = .10
end

@safetestset "DDM pdf 2" begin
using SequentialSamplingModels
using Test
using KernelDensity
using Random
Random.seed!(750)

dist = DDM=2.0, α = 1.5, z = .5, τ = .30)
choice,rt = rand(dist, 10^5)
rt1 = rt[choice .== 1]
p1 = mean(choice .== 1)
p2 = 1 - p1
approx_pdf = kde(rt1)
x = range(.301, 1.5, length=100)
y′ = pdf(approx_pdf, x) * p1
y = pdf.(dist, (1,), x)
@test y′ y rtol = .05

rt2 = rt[choice .== 2]
approx_pdf = kde(rt2)
y′ = pdf(approx_pdf, x) * p2
y = pdf.(dist, (2,), x)
@test y′ y rtol = .10
end

@safetestset "DDM cdf 1" begin
using SequentialSamplingModels
using Test
using StatsBase
using Random
Random.seed!(7540)

dist = DDM=1.0, α = .8, z = .5, τ = .3)
choice,rt = rand(dist, 10^5)
rt1 = rt[choice .== 1]
p1 = mean(choice .== 1)
p2 = 1 - p1
ecdf1 = ecdf(rt1)
x = range(.31, 1.0, length=100)
y′ = ecdf1.(x) * p1
y = cdf.(dist, (1,), x)
@test y′ y rtol = .01

rt2 = rt[choice .== 2]
ecdf2 = ecdf(rt2)
y′ = ecdf1.(x) * p2
y = cdf.(dist, (2,), x)
@test y′ y rtol = .01
end

@safetestset "DDM cdf 2" begin
using SequentialSamplingModels
using Test
using StatsBase
using Random
Random.seed!(2200)

dist = DDM=2.0, α = 1.5, z = .5, τ = .30)
choice,rt = rand(dist, 10^5)
rt1 = rt[choice .== 1]
p1 = mean(choice .== 1)
p2 = 1 - p1
ecdf1 = ecdf(rt1)
x = range(.31, 1.0, length=100)
y′ = ecdf1.(x) * p1
y = cdf.(dist, (1,), x)
@test y′ y rtol = .01

rt2 = rt[choice .== 2]
ecdf2 = ecdf(rt2)
y′ = ecdf1.(x) * p2
y = cdf.(dist, (2,), x)
@test y′ y rtol = .01
end
end
2 changes: 2 additions & 0 deletions test/distributions_api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
LNR=[-1.0,3.0], σ=.3, ϕ=0.0),
DiffusionRace(;ν=[1.0,.5], k=0.5, A=1.0, θ=.2),
Wald(3,1,.2),
DDM(),
WaldMixture(2, .2, 1, .1),
aDDM(),
maaDDM()]
Expand All @@ -45,6 +46,7 @@
LNR=[-1.0,3.0], σ=.3, ϕ=0.0),
DiffusionRace(;ν=[1.0,.5], k=0.5, A=1.0, θ=.2),
Wald(3,1,.2),
DDM(),
WaldMixture(2, .2, 1, .1),
aDDM(),
maaDDM()]
Expand Down

0 comments on commit e012bd3

Please sign in to comment.