Skip to content

Commit

Permalink
add rand for shiftedlognormal
Browse files Browse the repository at this point in the history
  • Loading branch information
itsdfish committed Jul 5, 2024
1 parent 07ace74 commit f154178
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 11 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.11.3"
version = "0.11.4"

[deps]
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Expand Down
10 changes: 5 additions & 5 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ makedocs(
"Ex-Gaussian Distribution" => "ex_gaussian.md",
"Shifted LogNormal" => "shifted_lognormal.md",
"Wald Model" => "wald.md",
"Wald Mixture Model" => "wald_mixture.md",
"Wald Mixture Model" => "wald_mixture.md"
],
"Multi-choice Models" => [
"Single Attribute Models" => [
Expand All @@ -37,17 +37,17 @@ makedocs(
"Lognormal Race Model (LNR)" => "lnr.md",
"Poisson Race" => "poisson_race.md",
"Racing Diffusion Model (RDM)" => "rdm.md",
"Starting-time Drift Diffusion Model (stDDM)" => "stDDM.md",
"Starting-time Drift Diffusion Model (stDDM)" => "stDDM.md"
],
"Multi-attribute Models" => [
"Muti-attribute Attentional Drift Diffusion Model" => "maaDDM.md",
"Multi-attribute Decision Field Theory" => "mdft.md",
"Multi-attribute Linear Ballistic Accumulator" => "mlba.md",
"Multi-attribute Linear Ballistic Accumulator" => "mlba.md"
]
],
"Alternative Geometries" => [
"Circular Drift Diffusion Model (CDDM)" => "cddm.md",
],
"Circular Drift Diffusion Model (CDDM)" => "cddm.md"
]
],
"Parameter Estimation" => [
"Mode Estimation" => "mode_estimation.md",
Expand Down
21 changes: 18 additions & 3 deletions src/ShiftedLogNormal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,24 @@ function logpdf(dist::AbstractShiftedLogNormal, rt)
return logpdf(LogNormal(ν, σ), rt - τ)
end

function rand(dist::AbstractShiftedLogNormal, n_trials::Int)
function rand(rng::AbstractRNG, dist::AbstractShiftedLogNormal, n_trials::Int)
(; τ, ν, σ) = dist
return rand(LogNormal(ν, σ), n_trials) .+ τ
return rand(rng, LogNormal(ν, σ), n_trials) .+ τ
end

model = ShiftedLogNormal= 1, σ = 1, τ = 0.20)
function rand(rng::AbstractRNG, dist::AbstractShiftedLogNormal)
(; τ, ν, σ) = dist
return rand(rng, LogNormal(ν, σ)) .+ τ
end

function params(d::AbstractShiftedLogNormal)
return (d.ν, d.σ, d.τ)
end

function mean(dist::AbstractShiftedLogNormal)
return mean(LogNormal(dist.ν, dist.σ)) + dist.τ
end

function std(dist::AbstractShiftedLogNormal)
return std(LogNormal(dist.ν, dist.σ))
end
2 changes: 0 additions & 2 deletions src/Wald.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
loglikelihood(d::AbstractWald, data::AbstractArray{T, 1}) where {T} = sum(logpdf.(d, data))

"""
Wald{T<:Real} <: AbstractWald
Expand Down
13 changes: 13 additions & 0 deletions src/type_system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ maximum(d::SSM1D) = Inf
minimum(d::SSM2D) = 0.0
maximum(d::SSM2D) = Inf

insupport(d::SSM1D, rt::Real) = rt minimum(d) && rt maximum(d)
insupport(d::SSM2D, data) = data.rt minimum(d) && data.rt maximum(d)

Base.broadcastable(x::SSM1D) = Ref(x)
Expand Down Expand Up @@ -188,6 +189,18 @@ Computes the likelihood for a 2D sequential sampling model.
logpdf(d::SSM2D, data::NamedTuple) = logpdf.(d, data.choice, data.rt)
logpdf(d::SSM2D, data::AbstractVector{<:Real}) = logpdf(d, Int(data[1]), data[2])

"""
loglikelihood(d::SSM1D, data::AbstractArray{T, 1})
Computes the summed log likelihood for a 1D sequential sampling model.
# Arguments
- `d::SSM2D`: an object for a 2D sequential sampling model
- `data::AbstractVector{<:Real}`: a vector of reaction times
"""
loglikelihood(d::SSM1D, data::AbstractVector{<:Real}) = sum(logpdf.(d, data))

"""
loglikelihood(d::SSM2D, data::NamedTuple)
Expand Down

0 comments on commit f154178

Please sign in to comment.