Skip to content

Commit

Permalink
Add heatmaps for 2D items
Browse files Browse the repository at this point in the history
  • Loading branch information
frankier committed Nov 29, 2023
1 parent 85bde6a commit c10d065
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 36 deletions.
13 changes: 7 additions & 6 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,29 @@ version = "0.1.0"
AlgebraOfGraphics = "cbdf2221-f076-402e-a563-3d30da359d67"
ComputerAdaptiveTesting = "5a0d4f34-1f62-4a66-80fe-87aba0485488"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
FittedItemBanks = "3f797b09-34e4-41d7-acf6-3302ae3248a5"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
PsychometricsBazaarBase = "b0d9cada-d963-45e9-a4c6-4746243987f1"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
XUnit = "3e3c03f2-1a94-11e9-2981-050a4ca824ab"

[compat]
AlgebraOfGraphics = "0.6.12"
Aqua = "^0.8.2"
ComputerAdaptiveTesting = "0.2.0"
DataFrames = "1.4.1"
DocStringExtensions = "^0.9"
Distributions = "0.25.76"
DocStringExtensions = "^0.9"
FittedItemBanks = "^0.3.0, ^0.4.0"
Makie = "^0.18.0, ^0.19.0, ^0.20.0"
PsychometricsBazaarBase = "^0.6.0"
XUnit = "^1.1.6"
julia = "^1.8"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
XUnit = "3e3c03f2-1a94-11e9-2981-050a4ca824ab"

[targets]
test = ["Aqua", "XUnit"]
3 changes: 2 additions & 1 deletion src/AdaptiveTestPlots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ using Makie
using Makie: @Block
using DocStringExtensions
using FittedItemBanks
using FittedItemBanks: item_params
using FittedItemBanks: item_params, item_bank_domain
using ComputerAdaptiveTesting: Aggregators
using ComputerAdaptiveTesting.Aggregators
using PsychometricsBazaarBase.Integrators
using FillArrays

include("./makie_extensions.jl")
include("./item_banks.jl")
Expand Down
65 changes: 36 additions & 29 deletions src/item_banks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,6 @@ end
function index_labeller(index::Int)
"Item $index"
end
#=
toggles = Array{Toggle}(undef, length(item_bank))
for idx in eachindex(item_bank)
label = labeller(idx)
toggles[idx] = (off_label = "Show $name", on_label="Hide $name", active = true)
end
#ir = ItemResponse(item_bank, idx)
ltgrid = LabelledToggleGrid(
fig[1, 2],
toggles...,
width = 350,
tellheight = false
)
#GridLayout()
ltgrid
=#

function _item_bank_domain(::OneDimContinuousDomain,
item_bank,
Expand Down Expand Up @@ -157,29 +141,46 @@ function plot_item_response(::VectorContinuousDomain,
xs,
item_label,
outcomes;
ys_buf = Array{Float64}(undef, length(xs), domdims(ir.item_bank)))
ys_buf = Array{Float64}(undef, length(xs), 2))
for (i, x) in enumerate(xs)
ys_buf[i, :] .= resp_vec(ir, x)
end

dim1 = [x[1] for x in xs]
dim2 = [x[2] for x in xs]
for out in [1, 2]
outcomes[out] = lines!(ax,
xs,
outcomes[out] = heatmap!(ax,
dim1,
dim2,
(@view ys_buf[:, out]),
label = "Item $item_label; Outcome $out")
end
end

function plot_item_response(ir::ItemResponse, args...; kwargs...)
plot_item_response(DomainType(ir), ir, args...; kwargs...)
plot_item_response(DomainType(ir.item_bank), ir, args...; kwargs...)
end

function make_grid(::OneDimContinuousDomain, item_bank, lim_lo, lim_hi, num_points)
range(lim_lo, lim_hi, length = num_points)
end

function make_grid(::VectorContinuousDomain, item_bank, lim_lo::AbstractVector, lim_hi::AbstractVector, num_points)
prod = Iterators.product((
range(lo, hi, length = num_points)
for (lo, hi)
in zip(lim_lo, lim_hi)
)...)
reshape(collect.(prod), :)
end

function make_grid(dom::VectorContinuousDomain, item_bank, lim_lo, lim_hi, num_points)
ndim = domdims(item_bank)
make_grid(dom, item_bank, Fill(lim_lo, ndim), Fill(lim_hi, ndim), num_points)
end

function item_response_xs(::VectorContinuousDomain, lim_lo, lim_hi)
range(lim_lo, lim_hi, length = 100)
prod = Iterators.product((range(lo, hi, length = 100)
for (lo, hi)
in zip(theta_lo, theta_hi))...)
grid = reshape(collect.(prod), :)
function make_grid(item_bank, lim_lo, lim_hi, num_points)
make_grid(DomainType(item_bank), item_bank, lim_lo, lim_hi, num_points)
end

"""
Expand All @@ -196,6 +197,7 @@ function plot_item_bank_comparison(item_banks::AbstractVector;
ignore_domain_indices = [],)
fig = Figure()
ax = Axis(fig[1, 1])
# Get limits
lim_lo = Inf
lim_hi = -Inf
for (idx, item_bank) in enumerate(item_banks)
Expand All @@ -206,22 +208,27 @@ function plot_item_bank_comparison(item_banks::AbstractVector;
lim_lo = min(lim_lo, ib_lim_lo)
lim_hi = max(lim_hi, ib_lim_hi)
end
outcomes = Array{Makie.Lines}(undef, length(item_banks), 2, length(items))
# Plot lines
outcomes = Array{Union{Makie.Lines, Makie.Heatmap}}(undef, length(item_banks), 2, length(items))
for (ibi, item_bank) in enumerate(item_banks)
ax = Axis(fig[ibi, 1])
xlims!(ax, lim_lo, lim_hi)
for (ii, item) in enumerate(items)
ir = ItemResponse(item_bank, item)
xs = range(lim_lo, lim_hi, length = 100)
plot_item_response(ir, ax, xs, ys, labeller(item), @view outcomes[ibi, :, ii])
xs = make_grid(ir.item_bank, lim_lo, lim_hi, 100)
item_label = labeller(item)
item_lines = @view outcomes[ibi, :, ii]
plot_item_response(ir, ax, xs, item_label, item_lines)
end
end
# Draw widgets
outcome_grid = include_outcome_toggles ? draw_outcome_toggles!(fig[1, 2], [1, 2]) :
nothing
item_grid = include_item_toggles ?
draw_item_toggles!(fig[include_outcome_toggles ? length(item_banks) : 1, 2],
items,
labeller) : nothing
# Connect widgets
for (i, outcome_toggle) in enumerate(toggle_grid_observables(outcome_grid, 2))
for (j, item_toggle) in enumerate(toggle_grid_observables(item_grid, items))
for ibi in eachindex(item_banks)
Expand Down

0 comments on commit c10d065

Please sign in to comment.