Skip to content

Commit

Permalink
make attentional diffusion interface consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
itsdfish committed May 29, 2023
1 parent 8e598af commit 4a6bd46
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SequentialSamplingModels"
uuid = "0e71a2a6-2b30-4447-8742-d083a85e82d1"
authors = ["itsdfish"]
version = "0.3.0"
version = "0.3.1"

[deps]
ConcreteStructs = "2569d6c7-a4a2-43d3-a901-331e8e4be471"
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ The examples below show basic usage. Addition information can be found in the RE
```julia
using SequentialSamplingModels
dist = LNR=[-2,-3], σ=1.0, ϕ=.3)
data = rand(dist, 10)
like = pdf.(dist, data)
loglike = logpdf.(dist, data)
choice,rts = rand(dist, 10)
like = pdf.(dist, choice, rts)
loglike = logpdf.(dist, choice, rts)
```

## Linear Ballistic Accumulator
Expand Down Expand Up @@ -47,9 +47,9 @@ loglike = logpdf.(dist, rt)
```julia
using SequentialSamplingModels
dist = DiffusionRace(;ν=[1.0,.5], k=0.5, A=1.0, θ=.2)
data = rand(dist, 10)
like = pdf.(dist, data)
loglike = logpdf.(dist, data)
choice,rt = rand(dist, 10)
like = pdf.(dist, choice, rts)
loglike = logpdf.(dist, choice, rts)
```

## Attentional Diffusion Model
Expand Down Expand Up @@ -84,7 +84,7 @@ mutable struct Transition
.015 .98 .005;
.45 .45 .1])

rts = rand(model, 1000, attend, tmat)
choice,rts = rand(model, 1000, attend, tmat)
```

## Multiattribute Attentional Drift Diffusion
Expand Down
8 changes: 4 additions & 4 deletions src/AttentionalDiffusion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ Generate `n_sim` simulated trials from the attention diffusion model.
- `kwargs...`: optional keyword arguments for the `fixation` function
"""
function rand(dist::AbstractaDDM, n_sim::Int, fixation, args...; rand_state! = _rand_state!, kwargs...)
rts = [Vector{Float64}() for _ in 1:2]
choice = fill(0, n_sim)
rt = fill(0.0, n_sim)
for sim in 1:n_sim
rand_state!(args...; kwargs...)
choice,rt = _rand(dist, () -> fixation(args...; kwargs...))
push!(rts[choice], rt)
choice[sim],rt[sim] = _rand(dist, () -> fixation(args...; kwargs...))
end
return rts
return (;choice,rt)
end

function _rand_state!(tmat)
Expand Down
18 changes: 9 additions & 9 deletions test/attentional_diffusion_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@
.015 .98 .005;
.45 .45 .1])

rts1 = rand(model, 1000, x -> attend(x), tmat)
n1,n2 = length.(rts1)
@test n1 > n2
choice,rts = rand(model, 1000, x -> attend(x), tmat)
p1 = mean(choice .== 1)
@test p1 > .50

model = aDDM(;ν1=4.0, ν2=5.0)
rts2 = rand(model, 1000, x -> attend(x), tmat)
n1,n2 = length.(rts2)
@test n1 < n2
choice,rts1 = rand(model, 1000, x -> attend(x), tmat)
p1 = mean(choice .== 1)
@test p1 < .50

μ_rts1 = mean(vcat(rts1...))
μ_rts1 = mean(rts1)
model = aDDM(;ν1=5.0, ν2=5.0)
rts3 = rand(model, 1000, x -> attend(x), tmat)
μ_rts3 = mean(vcat(rts3...))
choice,rts3 = rand(model, 1000, x -> attend(x), tmat)
μ_rts3 = mean(rts3)
@test μ_rts1 < μ_rts3
end
end

0 comments on commit 4a6bd46

Please sign in to comment.