From 53e90f51e55d5669f08d68fd9850f817978758aa Mon Sep 17 00:00:00 2001 From: Frankie Robertson Date: Fri, 2 Aug 2024 15:17:36 +0300 Subject: [PATCH] Apply automatic JuliaFormating corrections --- src/DummyData.jl | 61 +++++++++++++++++++++++--------- src/FittedItemBanks.jl | 24 ++++++------- src/bspline.jl | 2 +- src/cdf_items.jl | 13 ++++--- src/cdf_mirt_items.jl | 14 ++++---- src/guess_slip_items.jl | 65 ++++++++++++++++++++++++---------- src/monopoly.jl | 2 +- src/nominal_items.jl | 12 ++++--- src/porcelain.jl | 78 ++++++++++++++++++++++++++--------------- src/sampled_items.jl | 35 +++++++++++------- test/aqua.jl | 2 +- test/jet.jl | 1 - test/runtests.jl | 2 +- test/tests_top.jl | 3 +- 14 files changed, 202 insertions(+), 112 deletions(-) diff --git a/src/DummyData.jl b/src/DummyData.jl index 03b3c47..2a833c9 100644 --- a/src/DummyData.jl +++ b/src/DummyData.jl @@ -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 @@ -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) @@ -35,7 +38,9 @@ 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), @@ -43,7 +48,9 @@ function dummy_item_bank(rng::AbstractRNG, spec::SimpleItemBankSpec{StdModel2PL, ) 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), @@ -51,7 +58,9 @@ function dummy_item_bank(rng::AbstractRNG, spec::SimpleItemBankSpec{StdModel2PL, ) 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), @@ -59,7 +68,9 @@ function dummy_item_bank(rng::AbstractRNG, spec::SimpleItemBankSpec{StdModel2PL, ) 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), @@ -67,28 +78,35 @@ function dummy_item_bank(rng::AbstractRNG, spec::SimpleItemBankSpec{StdModel2PL, ) 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) @@ -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 diff --git a/src/FittedItemBanks.jl b/src/FittedItemBanks.jl index 1a0b597..041f1dc 100644 --- a/src/FittedItemBanks.jl +++ b/src/FittedItemBanks.jl @@ -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 @@ -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 @@ -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) @@ -237,7 +238,6 @@ function item_bank_domain( end end - include("./guess_slip_items.jl") include("./cdf_items.jl") include("./cdf_mirt_items.jl") diff --git a/src/bspline.jl b/src/bspline.jl index 5b425ad..0e442ca 100644 --- a/src/bspline.jl +++ b/src/bspline.jl @@ -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) diff --git a/src/cdf_items.jl b/src/cdf_items.jl index 1eabc23..cc27e92 100644 --- a/src/cdf_items.jl +++ b/src/cdf_items.jl @@ -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}, θ) @@ -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 @@ -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 \ No newline at end of file + (; difficulty = item_bank.difficulties[idx], + discrimination = item_bank.discriminations[idx]) +end diff --git a/src/cdf_mirt_items.jl b/src/cdf_mirt_items.jl index e14fe34..88751ef 100644 --- a/src/cdf_mirt_items.jl +++ b/src/cdf_mirt_items.jl @@ -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( @@ -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}, θ) @@ -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 \ No newline at end of file + (; difficulty = item_bank.difficulties[idx], + discrimination = @view item_bank.discriminations[:, idx]) +end diff --git a/src/guess_slip_items.jl b/src/guess_slip_items.jl index 2209e01..e8dd947 100644 --- a/src/guess_slip_items.jl +++ b/src/guess_slip_items.jl @@ -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) @@ -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 \ No newline at end of file +end diff --git a/src/monopoly.jl b/src/monopoly.jl index 43dbf42..6de3b1b 100644 --- a/src/monopoly.jl +++ b/src/monopoly.jl @@ -77,4 +77,4 @@ end # TODO #function item_domain(ir::ItemResponse{<:MonopolyItemBank}, left_mass, right_mass) -#end \ No newline at end of file +#end diff --git a/src/nominal_items.jl b/src/nominal_items.jl index bb36259..d23e8e7 100644 --- a/src/nominal_items.jl +++ b/src/nominal_items.jl @@ -1,7 +1,7 @@ using StaticArrays -PerRankReal = AbstractArray{<: AbstractArray{<: Real}, 1} -PerCategoryFloat = AbstractArray{<: AbstractArray{Float64}, 1} +PerRankReal = AbstractArray{<:AbstractArray{<:Real}, 1} +PerCategoryFloat = AbstractArray{<:AbstractArray{Float64}, 1} """ $(TYPEDEF) @@ -23,13 +23,15 @@ characteristic/transfer function. In Handbook of Modern Item Response Theory. ](https://doi.org/10.1007/978-1-4757-2691-6_9) """ -struct NominalItemBank{RankStorageT <: PerRankReal, CategoryStorageT <: PerCategoryFloat} <: AbstractItemBank +struct NominalItemBank{RankStorageT <: PerRankReal, CategoryStorageT <: PerCategoryFloat} <: + AbstractItemBank ranks::RankStorageT # ak_1 ... ak_k discriminations::Matrix{Float64} # a_1 ... a_n cut_points::CategoryStorageT # d_1 ... d_k end -function NominalItemBank(ranks::Matrix{Float64}, discriminations::Matrix{Float64}, cut_points::Matrix{Float64}) +function NominalItemBank(ranks::Matrix{Float64}, discriminations::Matrix{Float64}, + cut_points::Matrix{Float64}) NominalItemBank(nestedview(ranks), discriminations, nestedview(cut_points)) end @@ -87,5 +89,5 @@ function log_resp_vec(ir::ItemResponse{<:NominalItemBank}, θ) end function item_params(item_bank::NominalItemBank, idx) - (; discrimination=item_bank.discriminations[idx, :]) + (; discrimination = item_bank.discriminations[idx, :]) end diff --git a/src/porcelain.jl b/src/porcelain.jl index 8d7da61..f7415a2 100644 --- a/src/porcelain.jl +++ b/src/porcelain.jl @@ -13,8 +13,8 @@ Convenience function to construct an item bank of the standard 2-parameter logistic single-dimensional IRT model. """ function ItemBank2PL( - difficulties, - discriminations + difficulties, + discriminations ) TransferItemBank(normal_scaled_logistic, difficulties, discriminations) end @@ -24,9 +24,9 @@ Convenience function to construct an item bank of the standard 3-parameter logistic single-dimensional IRT model. """ function ItemBank3PL( - difficulties, - discriminations, - guesses + difficulties, + discriminations, + guesses ) GuessItemBank(guesses, ItemBank2PL(difficulties, discriminations)) end @@ -36,10 +36,10 @@ Convenience function to construct an item bank of the standard 4-parameter logistic single-dimensional IRT model. """ function ItemBank4PL( - difficulties, - discriminations, - guesses, - slips + difficulties, + discriminations, + guesses, + slips ) SlipItemBank(slips, ItemBank3PL(difficulties, discriminations, guesses)) end @@ -49,8 +49,8 @@ Convenience function to construct an item bank of the standard 2-parameter logistic MIRT model. """ function ItemBankMirt2PL( - difficulties, - discriminations + difficulties, + discriminations ) CdfMirtItemBank(normal_scaled_logistic, difficulties, discriminations) end @@ -60,9 +60,9 @@ Convenience function to construct an item bank of the standard 3-parameter logistic MIRT model. """ function ItemBankMirt3PL( - difficulties, - discriminations, - guesses + difficulties, + discriminations, + guesses ) GuessItemBank(guesses, ItemBankMirt2PL(difficulties, discriminations)) end @@ -72,17 +72,17 @@ Convenience function to construct an item bank of the standard 4-parameter logistic MIRT model. """ function ItemBankMirt4PL( - difficulties, - discriminations, - guesses, - slips + difficulties, + discriminations, + guesses, + slips ) SlipItemBank(slips, ItemBankMirt3PL(difficulties, discriminations, guesses)) end function ItemBankGPCM( - discriminations, - cut_points + discriminations, + cut_points ) GPCMItemBank(discriminations, cut_points) end @@ -92,19 +92,41 @@ struct StdModel2PL <: StdModelForm end struct StdModel3PL <: StdModelForm end struct StdModel4PL <: StdModelForm end -struct SimpleItemBankSpec{StdModelT <: StdModelForm, DomainTypeT <: DomainType, ResponseTypeT <: ResponseType} +struct SimpleItemBankSpec{ + StdModelT <: StdModelForm, DomainTypeT <: DomainType, ResponseTypeT <: ResponseType} model::StdModelT domain::DomainTypeT response::ResponseTypeT end -constructor(::SimpleItemBankSpec{StdModel2PL, OneDimContinuousDomain, BooleanResponse}) = ItemBank2PL -constructor(::SimpleItemBankSpec{StdModel3PL, OneDimContinuousDomain, BooleanResponse}) = ItemBank3PL -constructor(::SimpleItemBankSpec{StdModel4PL, OneDimContinuousDomain, BooleanResponse}) = ItemBank4PL -constructor(::SimpleItemBankSpec{StdModel2PL, VectorContinuousDomain, BooleanResponse}) = ItemBankMirt2PL -constructor(::SimpleItemBankSpec{StdModel3PL, VectorContinuousDomain, BooleanResponse}) = ItemBankMirt3PL -constructor(::SimpleItemBankSpec{StdModel4PL, VectorContinuousDomain, BooleanResponse}) = ItemBankMirt4PL -constructor(::SimpleItemBankSpec{StdModel2PL, D, MultinomialResponse}) where {D <: ContinuousDomain} = ItemBankGPCM +function constructor(::SimpleItemBankSpec{ + StdModel2PL, OneDimContinuousDomain, BooleanResponse}) + ItemBank2PL +end +function constructor(::SimpleItemBankSpec{ + StdModel3PL, OneDimContinuousDomain, BooleanResponse}) + ItemBank3PL +end +function constructor(::SimpleItemBankSpec{ + StdModel4PL, OneDimContinuousDomain, BooleanResponse}) + ItemBank4PL +end +function constructor(::SimpleItemBankSpec{ + StdModel2PL, VectorContinuousDomain, BooleanResponse}) + ItemBankMirt2PL +end +function constructor(::SimpleItemBankSpec{ + StdModel3PL, VectorContinuousDomain, BooleanResponse}) + ItemBankMirt3PL +end +function constructor(::SimpleItemBankSpec{ + StdModel4PL, VectorContinuousDomain, BooleanResponse}) + ItemBankMirt4PL +end +function constructor(::SimpleItemBankSpec{ + StdModel2PL, D, MultinomialResponse}) where {D <: ContinuousDomain} + ItemBankGPCM +end function ItemBank(spec::SimpleItemBankSpec, args...; kwargs...) constructor(spec)(args...; kwargs...) diff --git a/src/sampled_items.jl b/src/sampled_items.jl index bc6f42a..f510b88 100644 --- a/src/sampled_items.jl +++ b/src/sampled_items.jl @@ -3,7 +3,7 @@ $(SIGNATURES) A guassian kernel for use with `KernelSmoother` """ -gauss_kern(u) = exp(-u^2.0/2) +gauss_kern(u) = exp(-u^2.0 / 2) """ $(SIGNATURES) @@ -47,7 +47,7 @@ function item_bank_xs(item_bank::DichotomousPointsItemBank) end function item_domain(ir::ItemResponse{<:DichotomousPointsItemBank}) - (ir.item_bank.xs[1], ir.item_bank.xs[end]) + (ir.item_bank.xs[1], ir.item_bank.xs[end]) end function item_xs(ir::ItemResponse{<:DichotomousPointsItemBank}) @@ -80,7 +80,7 @@ function Base.length(item_bank::MultiGridDichotomousPointsItemBank) end function item_domain(ir::ItemResponse{<:MultiGridDichotomousPointsItemBank}) - (ir.item_bank.xs[ir.index][1], ir.item_bank.xs[ir.index][end]) + (ir.item_bank.xs[ir.index][1], ir.item_bank.xs[ir.index][end]) end function item_xs(ir::ItemResponse{<:MultiGridDichotomousPointsItemBank}) @@ -131,14 +131,16 @@ end DomainType(::DichotomousSmoothedItemBank) = OneDimContinuousDomain() ResponseType(::DichotomousSmoothedItemBank) = BooleanResponse() -inner_item_response(ir::ItemResponse{<: DichotomousSmoothedItemBank}) = ItemResponse(ir.item_bank.inner_bank, ir.index) +function inner_item_response(ir::ItemResponse{<:DichotomousSmoothedItemBank}) + ItemResponse(ir.item_bank.inner_bank, ir.index) +end function Base.length(item_bank::DichotomousSmoothedItemBank) length(item_bank.inner_bank) end function item_domain(ir::ItemResponse{<:DichotomousSmoothedItemBank}) - item_domain(ItemResponse(ir.item_bank.inner_bank, ir.index)) + item_domain(ItemResponse(ir.item_bank.inner_bank, ir.index)) end function resp_vec(ir::ItemResponse{<:DichotomousSmoothedItemBank}, θ) @@ -155,10 +157,13 @@ function resp(ir::ItemResponse{<:DichotomousSmoothedItemBank}, outcome::Bool, θ end end -function resp(ir::ItemResponse{<:DichotomousSmoothedItemBank{<:PointsItemBank, <:KernelSmoother}}, θ) +function resp( + ir::ItemResponse{<:DichotomousSmoothedItemBank{<:PointsItemBank, <:KernelSmoother}}, + θ) # XXX: Avoid allocating here? @turbo here? inner_ir = inner_item_response(ir) - kernel_comb = ir.item_bank.smoother.kernel.((item_xs(inner_ir) .- θ) ./ ir.item_bank.smoother.bandwidths[ir.index]) + kernel_comb = ir.item_bank.smoother.kernel.((item_xs(inner_ir) .- θ) ./ + ir.item_bank.smoother.bandwidths[ir.index]) sum(kernel_comb .* (item_ys(inner_ir))) / sum(kernel_comb) end @@ -167,16 +172,19 @@ function nearest_index(xs, ys, θ) if ( neighbor_idx != 1 && ( - (neighbor_idx == length(xs) + 1) || - ((θ - xs[neighbor_idx - 1]) < (xs[neighbor_idx] - θ)) - ) + (neighbor_idx == length(xs) + 1) || + ((θ - xs[neighbor_idx - 1]) < (xs[neighbor_idx] - θ)) + ) ) neighbor_idx = neighbor_idx - 1 end return neighbor_idx end -function resp(ir::ItemResponse{<:DichotomousSmoothedItemBank{<:PointsItemBank, <:NearestNeighborSmoother}}, θ) +function resp( + ir::ItemResponse{<:DichotomousSmoothedItemBank{ + <:PointsItemBank, <:NearestNeighborSmoother}}, + θ) inner_ir = inner_item_response(ir) xs = item_xs(inner_ir) ys = item_ys(inner_ir) @@ -187,7 +195,8 @@ function nearest_indices(xs, ys, thetas) pivot_theta_idx = length(thetas) ÷ 2 pivot_theta = thetas[pivot_theta_idx] pivot_xs_idx = nearest_index(xs, ys, pivot_theta) - nearest_indices((@view xs[1:pivot_xs_idx]), (@view ys[1:pivot_xs_idx]), (@view thetas[1:(pivot_theta - 1)])) + nearest_indices((@view xs[1:pivot_xs_idx]), (@view ys[1:pivot_xs_idx]), + (@view thetas[1:(pivot_theta - 1)])) end #= @@ -211,4 +220,4 @@ function gridify(item_bank, xs)::DichotomousPointsItemBank ys[:, item_idx] .= interp(xs, resp.(Ref(ItemResponse(item_bank, item_idx)), xs)) end return DichotomousPointsItemBank(xs, ys) -end \ No newline at end of file +end diff --git a/test/aqua.jl b/test/aqua.jl index 6ff324a..4aeea3f 100644 --- a/test/aqua.jl +++ b/test/aqua.jl @@ -1,5 +1,5 @@ using Aqua using FittedItemBanks -Aqua.test_all(FittedItemBanks, ambiguities=false) +Aqua.test_all(FittedItemBanks, ambiguities = false) Aqua.test_ambiguities([FittedItemBanks]) diff --git a/test/jet.jl b/test/jet.jl index 0a98999..547ca1a 100644 --- a/test/jet.jl +++ b/test/jet.jl @@ -1,7 +1,6 @@ using JET using FittedItemBanks - @testset "JET checks" begin rep = report_package( FittedItemBanks; diff --git a/test/runtests.jl b/test/runtests.jl index d8dc020..0c8ca81 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,3 +1,3 @@ using XUnit -runtests("tests_top.jl", ARGS...) \ No newline at end of file +runtests("tests_top.jl", ARGS...) diff --git a/test/tests_top.jl b/test/tests_top.jl index bed6ace..215ebce 100644 --- a/test/tests_top.jl +++ b/test/tests_top.jl @@ -1,6 +1,5 @@ using XUnit - @testset "aqua" begin include("./aqua.jl") end @@ -15,4 +14,4 @@ end @testset "format" begin include("./format.jl") -end \ No newline at end of file +end