Skip to content

Commit

Permalink
Apply automatic JuliaFormating corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
frankier committed Aug 2, 2024
1 parent a059c42 commit 53e90f5
Show file tree
Hide file tree
Showing 14 changed files with 202 additions and 112 deletions.
61 changes: 44 additions & 17 deletions src/DummyData.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ using Random
using ArraysOfArrays: VectorOfArrays

import ..SimpleItemBankSpec, ..StdModelForm, ..StdModel2PL, ..StdModel3PL, ..StdModel4PL
import ..OneDimContinuousDomain, ..VectorContinuousDomain, ..BooleanResponse, ..MultinomialResponse, ..ItemBank
import ..OneDimContinuousDomain, ..VectorContinuousDomain, ..BooleanResponse,
..MultinomialResponse, ..ItemBank
import ..GuessItemBank, ..SlipItemBank
import ..ItemResponse

Expand All @@ -22,7 +23,9 @@ clamp_rand(rng, dist, dims...) = clamp.(rand(rng, dist, dims...), 0.0, 0.4)

dummy_difficulties(rng, num_questions) = rand(rng, std_normal, num_questions)
dummy_discriminations(rng, num_questions) = abs_rand(rng, Normal(1.0, 0.2), num_questions)
dummy_discriminations(rng, dims, num_questions) = abs_rand(rng, Normal(1.0, 0.2), dims, num_questions)
function dummy_discriminations(rng, dims, num_questions)
abs_rand(rng, Normal(1.0, 0.2), dims, num_questions)
end
dummy_guesses(rng, num_questions) = clamp_rand(rng, Normal(0.0, 0.2), num_questions)
dummy_slips(rng, num_questions) = clamp_rand(rng, Normal(0.0, 0.2), num_questions)

Expand All @@ -35,60 +38,75 @@ function dummy_cut_points(rng, num_questions)
cut_points_ragged
end

function dummy_item_bank(rng::AbstractRNG, spec::SimpleItemBankSpec{StdModel2PL, OneDimContinuousDomain, BooleanResponse}, num_questions)
function dummy_item_bank(rng::AbstractRNG,
spec::SimpleItemBankSpec{StdModel2PL, OneDimContinuousDomain, BooleanResponse},
num_questions)
ItemBank(
spec,
dummy_difficulties(rng, num_questions),
dummy_discriminations(rng, num_questions)
)
end

function dummy_item_bank(rng::AbstractRNG, spec::SimpleItemBankSpec{StdModel2PL, VectorContinuousDomain, BooleanResponse}, num_questions, dims)
function dummy_item_bank(rng::AbstractRNG,
spec::SimpleItemBankSpec{StdModel2PL, VectorContinuousDomain, BooleanResponse},
num_questions, dims)
ItemBank(
spec,
dummy_difficulties(rng, num_questions),
dummy_discriminations(rng, dims, num_questions)
)
end

function dummy_item_bank(rng::AbstractRNG, spec::SimpleItemBankSpec{StdModel2PL, OneDimContinuousDomain, MultinomialResponse}, num_questions)
function dummy_item_bank(rng::AbstractRNG,
spec::SimpleItemBankSpec{StdModel2PL, OneDimContinuousDomain, MultinomialResponse},
num_questions)
ItemBank(
spec,
dummy_discriminations(rng, num_questions),
dummy_cut_points(rng, num_questions)
)
end

function dummy_item_bank(rng::AbstractRNG, spec::SimpleItemBankSpec{StdModel2PL, VectorContinuousDomain, MultinomialResponse}, num_questions, dims)
function dummy_item_bank(rng::AbstractRNG,
spec::SimpleItemBankSpec{StdModel2PL, VectorContinuousDomain, MultinomialResponse},
num_questions, dims)
ItemBank(
spec,
dummy_discriminations(rng, dims, num_questions),
dummy_cut_points(rng, num_questions)
)
end

function dummy_item_bank(rng::AbstractRNG, spec::SimpleItemBankSpec{StdModel3PL}, num_questions, rest...)
function dummy_item_bank(
rng::AbstractRNG, spec::SimpleItemBankSpec{StdModel3PL}, num_questions, rest...)
GuessItemBank(
dummy_guesses(rng, num_questions),
dummy_item_bank(rng, SimpleItemBankSpec(StdModel2PL(), spec.domain, spec.response), num_questions, rest...)
dummy_item_bank(rng, SimpleItemBankSpec(StdModel2PL(), spec.domain, spec.response),
num_questions, rest...)
)
end

function dummy_item_bank(rng::AbstractRNG, spec::SimpleItemBankSpec{StdModel4PL}, num_questions, rest...)
function dummy_item_bank(
rng::AbstractRNG, spec::SimpleItemBankSpec{StdModel4PL}, num_questions, rest...)
SlipItemBank(
dummy_slips(rng, num_questions),
dummy_item_bank(rng, SimpleItemBankSpec(StdModel3PL(), spec.domain, spec.response), num_questions, rest...)
dummy_item_bank(rng, SimpleItemBankSpec(StdModel3PL(), spec.domain, spec.response),
num_questions, rest...)
)
end

dummy_item_bank(spec::SimpleItemBankSpec, args...) = dummy_item_bank(Random.default_rng(), spec, args...)
function dummy_item_bank(spec::SimpleItemBankSpec, args...)
dummy_item_bank(Random.default_rng(), spec, args...)
end

function item_bank_to_full_dummy(rng, item_bank, num_testees)
(item_bank, abilities, responses) = mirt_item_bank_to_full_dummy(rng, item_bank, num_testees, 1; squeeze=true)
(item_bank, abilities, responses) = mirt_item_bank_to_full_dummy(
rng, item_bank, num_testees, 1; squeeze = true)
(item_bank, abilities[1, :], responses)
end

function mirt_item_bank_to_full_dummy(rng, item_bank, num_testees, dims; squeeze=false)
function mirt_item_bank_to_full_dummy(rng, item_bank, num_testees, dims; squeeze = false)
num_questions = length(item_bank)
abilities = rand(rng, std_normal, dims, num_testees)
irs = zeros(num_questions, num_testees)
Expand All @@ -106,14 +124,23 @@ function mirt_item_bank_to_full_dummy(rng, item_bank, num_testees, dims; squeeze
(item_bank, abilities, responses)
end

function dummy_full(rng::AbstractRNG, spec::SimpleItemBankSpec{<: StdModelForm, <: OneDimContinuousDomain} ;num_questions=default_num_questions, num_testees=default_num_testees)
function dummy_full(rng::AbstractRNG,
spec::SimpleItemBankSpec{<:StdModelForm, <:OneDimContinuousDomain};
num_questions = default_num_questions,
num_testees = default_num_testees)
item_bank_to_full_dummy(rng, dummy_item_bank(rng, spec, num_questions), num_testees)
end

function dummy_full(rng::AbstractRNG, spec::SimpleItemBankSpec{<: StdModelForm, <: VectorContinuousDomain}, dims; num_questions=default_num_questions, num_testees=default_num_testees)
mirt_item_bank_to_full_dummy(rng, dummy_item_bank(rng, spec, num_questions, dims), num_testees, dims)
function dummy_full(rng::AbstractRNG,
spec::SimpleItemBankSpec{<:StdModelForm, <:VectorContinuousDomain},
dims; num_questions = default_num_questions,
num_testees = default_num_testees)
mirt_item_bank_to_full_dummy(
rng, dummy_item_bank(rng, spec, num_questions, dims), num_testees, dims)
end

dummy_full(spec::SimpleItemBankSpec, args...; kwargs...) = dummy_full(Random.default_rng(), spec, args...; kwargs...)
function dummy_full(spec::SimpleItemBankSpec, args...; kwargs...)
dummy_full(Random.default_rng(), spec, args...; kwargs...)
end

end
24 changes: 12 additions & 12 deletions src/FittedItemBanks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export BSplineItemBank

export Smoother, KernelSmoother, NearestNeighborSmoother
export PointsItemBank
export DichotomousSmoothedItemBank, DichotomousPointsItemBank, MultiGridDichotomousPointsItemBank
export DichotomousSmoothedItemBank, DichotomousPointsItemBank,
MultiGridDichotomousPointsItemBank

export domdims, ItemResponse, resp, resp_vec, responses, item_params

Expand Down Expand Up @@ -153,12 +154,12 @@ end
Binary search for the point x where f(x) = target += precis given f is assumed as monotonically increasing.
"""
function _search(
f::F,
lim_lower,
lim_upper,
target,
precis;
max_iters=50,
f::F,
lim_lower,
lim_upper,
target,
precis;
max_iters = 50
) where {F}
lower = lim_lower
upper = lim_upper
Expand Down Expand Up @@ -203,10 +204,10 @@ range (lo, hi) which includes for each item the range in which the the item
response function is changing.
"""
function item_bank_domain(
item_bank::AbstractItemBank;
zero_symmetric=false,
items=eachindex(item_bank),
thresh=nothing
item_bank::AbstractItemBank;
zero_symmetric = false,
items = eachindex(item_bank),
thresh = nothing
)
if length(item_bank) == 0
(NaN, NaN)
Expand Down Expand Up @@ -237,7 +238,6 @@ function item_bank_domain(
end
end


include("./guess_slip_items.jl")
include("./cdf_items.jl")
include("./cdf_mirt_items.jl")
Expand Down
2 changes: 1 addition & 1 deletion src/bspline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function resp(ir::ItemResponse{<:BSplineItemBank}, outcome::Bool, θ)
end

function bsplines_unchecked(basis::BSplineBasis, leftknot, x,
drv=NoDerivative(); derivspace=nothing)
drv = NoDerivative(); derivspace = nothing)
dest = bsplines_destarray(basis, x, drv, derivspace)
offset = @inbounds _bsplines!(dest, derivspace, basis, x, leftknot, drv)
bsplines_offsetarray(dest, offset, drv)
Expand Down
13 changes: 8 additions & 5 deletions src/cdf_items.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ function _unnorm_abil_1d(θ, difficulty, discrimination)
end

function norm_abil(ir::ItemResponse{<:TransferItemBank}, θ)
_norm_abil_1d(θ, ir.item_bank.difficulties[ir.index], ir.item_bank.discriminations[ir.index])
_norm_abil_1d(
θ, ir.item_bank.difficulties[ir.index], ir.item_bank.discriminations[ir.index])
end

function unnorm_abil(ir::ItemResponse{<:TransferItemBank}, θ)
_unnorm_abil_1d(θ, ir.item_bank.difficulties[ir.index], ir.item_bank.discriminations[ir.index])
_unnorm_abil_1d(
θ, ir.item_bank.difficulties[ir.index], ir.item_bank.discriminations[ir.index])
end

function resp_vec(ir::ItemResponse{<:TransferItemBank}, θ)
Expand All @@ -47,7 +49,7 @@ function density_vec(ir::ItemResponse{<:TransferItemBank}, θ)
end
=#

function item_domain(ir::ItemResponse, mass=1e-3)
function item_domain(ir::ItemResponse, mass = 1e-3)
item_domain(ir, mass, mass)
end

Expand Down Expand Up @@ -87,5 +89,6 @@ function cresp(ir::ItemResponse{<:TransferItemBank}, θ)
end

function item_params(item_bank::TransferItemBank, idx)
(; difficulty=item_bank.difficulties[idx], discrimination=item_bank.discriminations[idx])
end
(; difficulty = item_bank.difficulties[idx],
discrimination = item_bank.discriminations[idx])
end
14 changes: 8 additions & 6 deletions src/cdf_mirt_items.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ struct CdfMirtItemBank{DistT <: ContinuousUnivariateDistribution} <: AbstractIte
discriminations::Matrix{Float64}

function CdfMirtItemBank(
distribution::DistT,
difficulties::Vector{Float64},
discriminations::Matrix{Float64},
distribution::DistT,
difficulties::Vector{Float64},
discriminations::Matrix{Float64}
) where {DistT <: ContinuousUnivariateDistribution}
if size(discriminations, 2) != length(difficulties)
error(
Expand Down Expand Up @@ -43,7 +43,8 @@ function _mirt_norm_abil(θ, difficulty, discrimination)
end

function norm_abil(ir::ItemResponse{<:CdfMirtItemBank}, θ)
_mirt_norm_abil(θ, ir.item_bank.difficulties[ir.index], @view ir.item_bank.discriminations[:, ir.index])
_mirt_norm_abil(θ, ir.item_bank.difficulties[ir.index],
@view ir.item_bank.discriminations[:, ir.index])
end

function resp_vec(ir::ItemResponse{<:CdfMirtItemBank}, θ)
Expand All @@ -68,5 +69,6 @@ function cresp(ir::ItemResponse{<:CdfMirtItemBank}, θ)
end

function item_params(item_bank::CdfMirtItemBank, idx)
(; difficulty=item_bank.difficulties[idx], discrimination=@view item_bank.discriminations[:, idx])
end
(; difficulty = item_bank.difficulties[idx],
discrimination = @view item_bank.discriminations[:, idx])
end
65 changes: 46 additions & 19 deletions src/guess_slip_items.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,66 +12,93 @@ struct FixedGuessItemBank{InnerItemBank <: AbstractItemBank} <: AbstractItemBank
guess::Float64
inner_bank::InnerItemBank

FixedGuessItemBank(guess, inner_bank) = FixedGuessItemBank(ResponseType(inner_bank), guess, inner_bank)
FixedGuessItemBank(::BooleanResponse, guess, inner_bank) = new{typeof(inner_bank)}(guess, inner_bank)
function FixedGuessItemBank(guess, inner_bank)
FixedGuessItemBank(ResponseType(inner_bank), guess, inner_bank)
end
function FixedGuessItemBank(::BooleanResponse, guess, inner_bank)
new{typeof(inner_bank)}(guess, inner_bank)
end
end
y_offset(item_bank::FixedGuessItemBank, item_idx) = item_bank.guess
@forward FixedGuessItemBank.inner_bank Base.length, domdims
subset(item_bank::FixedGuessItemBank, idxs) = FixedGuessItemBank(item_bank.guess, subset(item_bank.inner_bank, idxs))
function subset(item_bank::FixedGuessItemBank, idxs)
FixedGuessItemBank(item_bank.guess, subset(item_bank.inner_bank, idxs))
end
function item_params(item_bank::FixedGuessItemBank, idx)
(;item_params(item_bank.inner_bank, idx)..., guess=item_bank.guess)
(; item_params(item_bank.inner_bank, idx)..., guess = item_bank.guess)
end

struct FixedSlipItemBank{InnerItemBank <: AbstractItemBank} <: AbstractItemBank
slip::Float64
inner_bank::InnerItemBank

FixedSlipItemBank(slip, inner_bank) = FixedSlipItemBank(ResponseType(inner_bank), slip, inner_bank)
FixedSlipItemBank(::BooleanResponse, slip, inner_bank) = new{typeof(inner_bank)}(slip, inner_bank)
function FixedSlipItemBank(slip, inner_bank)
FixedSlipItemBank(ResponseType(inner_bank), slip, inner_bank)
end
function FixedSlipItemBank(::BooleanResponse, slip, inner_bank)
new{typeof(inner_bank)}(slip, inner_bank)
end
end
y_offset(item_bank::FixedSlipItemBank, item_idx) = item_bank.slip
@forward FixedSlipItemBank.inner_bank Base.length, domdims, subset
subset(item_bank::FixedSlipItemBank, idxs) = FixedSlipItemBank(item_bank.slip, subset(item_bank.inner_bank, idxs))
function subset(item_bank::FixedSlipItemBank, idxs)
FixedSlipItemBank(item_bank.slip, subset(item_bank.inner_bank, idxs))
end
function item_params(item_bank::FixedSlipItemBank, idx)
(;item_params(item_bank.inner_bank, idx)..., slip=item_bank.slip)
(; item_params(item_bank.inner_bank, idx)..., slip = item_bank.slip)
end

struct GuessItemBank{InnerItemBank <: AbstractItemBank} <: AbstractItemBank
guesses::Vector{Float64}
inner_bank::InnerItemBank

GuessItemBank(guesses, inner_bank) = GuessItemBank(ResponseType(inner_bank), guesses, inner_bank)
GuessItemBank(::BooleanResponse, guesses, inner_bank) = new{typeof(inner_bank)}(guesses, inner_bank)
function GuessItemBank(guesses, inner_bank)
GuessItemBank(ResponseType(inner_bank), guesses, inner_bank)
end
function GuessItemBank(::BooleanResponse, guesses, inner_bank)
new{typeof(inner_bank)}(guesses, inner_bank)
end
end
y_offset(item_bank::GuessItemBank, item_idx) = item_bank.guesses[item_idx]
@forward GuessItemBank.inner_bank Base.length, domdims
subset(item_bank::GuessItemBank, idxs) = FixedSlipItemBank(item_bank.guesses[idxs], subset(item_bank.inner_bank, idxs))
function subset(item_bank::GuessItemBank, idxs)
FixedSlipItemBank(item_bank.guesses[idxs], subset(item_bank.inner_bank, idxs))
end
function item_params(item_bank::GuessItemBank, idx)
(;item_params(item_bank.inner_bank, idx)..., guess=item_bank.guesses[idx])
(; item_params(item_bank.inner_bank, idx)..., guess = item_bank.guesses[idx])
end

struct SlipItemBank{InnerItemBank <: AbstractItemBank} <: AbstractItemBank
slips::Vector{Float64}
inner_bank::InnerItemBank

SlipItemBank(slips, inner_bank) = SlipItemBank(ResponseType(inner_bank), slips, inner_bank)
SlipItemBank(::BooleanResponse, slips, inner_bank) = new{typeof(inner_bank)}(slips, inner_bank)
function SlipItemBank(slips, inner_bank)
SlipItemBank(ResponseType(inner_bank), slips, inner_bank)
end
function SlipItemBank(::BooleanResponse, slips, inner_bank)
new{typeof(inner_bank)}(slips, inner_bank)
end
end
y_offset(item_bank::SlipItemBank, item_idx) = item_bank.slips[item_idx]
@forward SlipItemBank.inner_bank Base.length, domdims
subset(item_bank::SlipItemBank, idxs) = FixedSlipItemBank(item_bank.slips[idxs], subset(item_bank.inner_bank, idxs))
function subset(item_bank::SlipItemBank, idxs)
FixedSlipItemBank(item_bank.slips[idxs], subset(item_bank.inner_bank, idxs))
end
function item_params(item_bank::SlipItemBank, idx)
(;item_params(item_bank.inner_bank, idx)..., slip=item_bank.slips[idx])
(; item_params(item_bank.inner_bank, idx)..., slip = item_bank.slips[idx])
end

const AnySlipItemBank = Union{SlipItemBank, FixedSlipItemBank}
const AnyGuessItemBank = Union{GuessItemBank, FixedGuessItemBank}
const AnySlipOrGuessItemBank = Union{AnySlipItemBank, AnyGuessItemBank}
const AnySlipAndGuessItemBank = Union{SlipItemBank{AnyGuessItemBank}, FixedSlipItemBank{AnyGuessItemBank}}
const AnySlipAndGuessItemBank = Union{
SlipItemBank{AnyGuessItemBank}, FixedSlipItemBank{AnyGuessItemBank}}

DomainType(item_bank::AnySlipOrGuessItemBank) = DomainType(item_bank.inner_bank)
ResponseType(item_bank::AnySlipOrGuessItemBank) = ResponseType(item_bank.inner_bank)
inner_item_response(ir::ItemResponse{<: AnySlipOrGuessItemBank}) = ItemResponse(ir.item_bank.inner_bank, ir.index)
function inner_item_response(ir::ItemResponse{<:AnySlipOrGuessItemBank})
ItemResponse(ir.item_bank.inner_bank, ir.index)
end

# Ensure we always have Slip{Guess{ItemBank}}
function FixedGuessItemBank(guess::Float64, inner_bank::AnySlipItemBank)
Expand Down Expand Up @@ -152,4 +179,4 @@ function resp(ir::ItemResponse{<:AnySlipAndGuessItemBank}, response, θ)
y_offset(ir.item_bank, ir.index),
resp(ItemResponse(ir.item_bank.inner_bank, ir.index), response, θ)
)
end
end
2 changes: 1 addition & 1 deletion src/monopoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ end

# TODO
#function item_domain(ir::ItemResponse{<:MonopolyItemBank}, left_mass, right_mass)
#end
#end
Loading

0 comments on commit 53e90f5

Please sign in to comment.