Skip to content

Commit

Permalink
Merge pull request #79 from itsdfish/auto-juliaformatter-pr
Browse files Browse the repository at this point in the history
Automatic JuliaFormatter.jl run
  • Loading branch information
itsdfish authored Jul 4, 2024
2 parents 428adf6 + df7b4ce commit f8a2c02
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 45 deletions.
12 changes: 6 additions & 6 deletions src/ShiftedLogNormal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@ loglike = logpdf.(dist, rts)
Heathcote, A., & Bohlscheid, E. Analysis and Modeling of Response Time using the Shifted Lognormal Distribution.
"""
struct ShiftedLogNormal{T <: Real} <: AbstractShiftedLogNormal
ν::T
σ::T
ν::T
σ::T
τ::T
end

ShiftedLogNormal(ν, σ, τ) = ShiftedLogNormal(promote(ν, σ, τ)...)

ShiftedLogNormal(; ν = -1, σ=.5, τ = .20) = ShiftedLogNormal(ν, σ, τ)
ShiftedLogNormal(; ν = -1, σ = 0.5, τ = 0.20) = ShiftedLogNormal(ν, σ, τ)

function logpdf(dist::AbstractShiftedLogNormal, rt)
(; τ, ν, σ) = dist
(; τ, ν, σ) = dist
return logpdf(LogNormal(ν, σ), rt - τ)
end

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

model = ShiftedLogNormal= 1, σ = 1, τ = .20)
model = ShiftedLogNormal= 1, σ = 1, τ = 0.20)
76 changes: 37 additions & 39 deletions test/shiftedlognormaldistribution.jl
Original file line number Diff line number Diff line change
@@ -1,68 +1,66 @@
@safetestset "Shifted Lognormal Distribution" begin

@safetestset "rand" begin
using Distributions
using Random
@safetestset "Shifted Lognormal Distribution" begin
@safetestset "rand" begin
using Distributions
using Random
using SequentialSamplingModels
using Test
using Test

Random.seed!(5411)

lognormal = LogNormal(-1, .3)
shifted_lognormal = ShiftedLogNormal= -1, σ=.3, τ = 0.5)
lognormal = LogNormal(-1, 0.3)
shifted_lognormal = ShiftedLogNormal= -1, σ = 0.3, τ = 0.5)
mean(rand(shifted_lognormal, 10_000))
# τ is properly added
@test mean(rand(lognormal, 10_000)) - mean(rand(shifted_lognormal, 10_000)) -.5 atol = .01
@test mean(rand(lognormal, 10_000)) - mean(rand(shifted_lognormal, 10_000)) -0.5 atol =
0.01
end


@safetestset "pdf" begin
using Distributions
@safetestset "pdf" begin
using Distributions
using SequentialSamplingModels
using Test
using Test

lognormal = LogNormal(-1, .3)
shifted_lognormal = ShiftedLogNormal= -1, σ=.3, τ = 0.0)
lognormal = LogNormal(-1, 0.3)
shifted_lognormal = ShiftedLogNormal= -1, σ = 0.3, τ = 0.0)
x = rand(shifted_lognormal, 100)
@test pdf.(lognormal, x) pdf.(shifted_lognormal, x)
end

@safetestset "logpdf 1" begin
using Distributions
@safetestset "logpdf 1" begin
using Distributions
using SequentialSamplingModels
using Test
using Test

lognormal = LogNormal(-1, .3)
shifted_lognormal = ShiftedLogNormal= -1, σ=.3, τ = 0.0)
lognormal = LogNormal(-1, 0.3)
shifted_lognormal = ShiftedLogNormal= -1, σ = 0.3, τ = 0.0)
x = rand(shifted_lognormal, 100)
@test logpdf.(lognormal, x) logpdf.(shifted_lognormal, x)
end

@safetestset "logpdf 2" begin
using Distributions
@safetestset "logpdf 2" begin
using Distributions
using Random
using SequentialSamplingModels
using Test
using Test

Random.seed!(2008)

parms == -1, σ=.3, τ = 0.0)
parms == -1, σ = 0.3, τ = 0.0)
x = rand(ShiftedLogNormal(; parms...), 10_000)

νs = range(.80 * parms.ν, 1.2 * parms.ν, length = 100)
LLs = map-> sum(logpdf.(ShiftedLogNormal(; parms..., ν), x)), νs)
_,idx = findmax(LLs)
@test νs[idx] parms.ν rtol = .01

σs = range(.80 * parms.σ, 1.2 * parms.σ, length = 100)
LLs = map-> sum(logpdf.(ShiftedLogNormal(; parms..., σ), x)), σs)
_,idx = findmax(LLs)
@test σs[idx] parms.σ rtol = .01
νs = range(0.80 * parms.ν, 1.2 * parms.ν, length = 100)
LLs = map-> sum(logpdf.(ShiftedLogNormal(; parms..., ν), x)), νs)
_, idx = findmax(LLs)
@test νs[idx] parms.ν rtol = 0.01

σs = range(0.80 * parms.σ, 1.2 * parms.σ, length = 100)
LLs = map-> sum(logpdf.(ShiftedLogNormal(; parms..., σ), x)), σs)
_, idx = findmax(LLs)
@test σs[idx] parms.σ rtol = 0.01

τs = range(.80 * parms.τ, 1.2 * parms.τ, length = 100)
LLs = map-> sum(logpdf.(ShiftedLogNormal(; parms..., τ), x)), τs)
_,idx = findmax(LLs)
@test τs[idx] parms.τ rtol = .01
τs = range(0.80 * parms.τ, 1.2 * parms.τ, length = 100)
LLs = map-> sum(logpdf.(ShiftedLogNormal(; parms..., τ), x)), τs)
_, idx = findmax(LLs)
@test τs[idx] parms.τ rtol = 0.01
end
end
end

0 comments on commit f8a2c02

Please sign in to comment.