Skip to content

Commit

Permalink
Automatically format with JuliaFormatter
Browse files Browse the repository at this point in the history
  • Loading branch information
frankier committed Aug 2, 2024
1 parent d46a4c6 commit 604706b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
17 changes: 10 additions & 7 deletions src/item_banks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function plot_item_bank(item_bank::AbstractItemBank;
labeller = index_labeller,
zero_symmetric = false,
include_outcome_toggles = true,
include_item_toggles = false,)
include_item_toggles = false)
fig = Figure()
ax = Axis(fig[1, 1])
lim_lo, lim_hi = _item_bank_domain(DomainType(item_bank),
Expand Down Expand Up @@ -165,11 +165,12 @@ function make_grid(::OneDimContinuousDomain, item_bank, lim_lo, lim_hi, num_poin
range(lim_lo, lim_hi, length = num_points)
end

function make_grid(::VectorContinuousDomain, item_bank, lim_lo::AbstractVector, lim_hi::AbstractVector, num_points)
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)
for (lo, hi)
in zip(lim_lo, lim_hi)
)...)
reshape(collect.(prod), :)
end
Expand All @@ -194,7 +195,7 @@ function plot_item_bank_comparison(item_banks::AbstractVector;
labeller = index_labeller,
include_outcome_toggles = true,
include_item_toggles = false,
ignore_domain_indices = [],)
ignore_domain_indices = [])
fig = Figure()
ax = Axis(fig[1, 1])
# Get limits
Expand All @@ -209,7 +210,8 @@ function plot_item_bank_comparison(item_banks::AbstractVector;
lim_hi = max(lim_hi, ib_lim_hi)
end
# Plot lines
outcomes = Array{Union{Makie.Lines, Makie.Heatmap}}(undef, length(item_banks), 2, length(items))
outcomes = Array{Union{Makie.Lines, Makie.Heatmap}}(
undef, length(item_banks), 2, length(items))
some_heatmap = nothing
for (ibi, item_bank) in enumerate(item_banks)
ax = Axis(fig[ibi, 1])
Expand All @@ -234,7 +236,8 @@ function plot_item_bank_comparison(item_banks::AbstractVector;
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],
draw_item_toggles!(
fig[include_outcome_toggles ? length(item_banks) : 1, 2],
items,
labeller) : nothing
# Connect widgets
Expand Down
1 change: 0 additions & 1 deletion src/makie_extensions.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Makie: make_block_docstring # This is used by @Block


# Allows hline! on AlgebraOfGraphics plots. May be better way in future.
# See: https://github.com/JuliaPlots/AlgebraOfGraphics.jl/issues/299
function aog_hlines!(fg::AlgebraOfGraphics.FigureGrid, args...; kws...)
Expand Down
29 changes: 17 additions & 12 deletions src/recorder.jl
Original file line number Diff line number Diff line change
Expand Up @@ -158,43 +158,47 @@ function eachmatcol(xs::Vector)
xs
end

function save_sampled(xs::Nothing, integrator, recorder::CatRecorder, tracked_responses, ir, item_correct)
function save_sampled(
xs::Nothing, integrator, recorder::CatRecorder, tracked_responses, ir, item_correct)
# Just skip saving in this case
end

function save_sampled(xs::Nothing, integrator::RiemannEnumerationIntegrator, recorder::CatRecorder, tracked_responses, ir, item_correct)
function save_sampled(xs::Nothing, integrator::RiemannEnumerationIntegrator,
recorder::CatRecorder, tracked_responses, ir, item_correct)
# In this case, the item bank is probably sampled so we can use that

# Save likelihoods
dist_est = distribution_estimator(recorder.ability_estimator)
denom = normdenom(integrator, dist_est, tracked_responses)
recorder.likelihoods[:, recorder.col_idx] = function_ys(
Aggregators.pdf(
dist_est,
tracked_responses
)
dist_est,
tracked_responses
)
) ./ denom
raw_denom = normdenom(integrator, recorder.raw_estimator, tracked_responses)
recorder.raw_likelihoods[:, recorder.col_idx] = function_ys(
Aggregators.pdf(
recorder.raw_estimator,
tracked_responses
)
recorder.raw_estimator,
tracked_responses
)
) ./ raw_denom

# Save item responses
recorder.item_responses[:, recorder.col_idx] = item_ys(ir, item_correct)
end

function save_sampled(xs, integrator, recorder::CatRecorder, tracked_responses, ir, item_correct)
function save_sampled(
xs, integrator, recorder::CatRecorder, tracked_responses, ir, item_correct)
# Save likelihoods
dist_est = distribution_estimator(recorder.ability_estimator)
denom = normdenom(integrator, dist_est, tracked_responses)
recorder.likelihoods[:, recorder.col_idx] = Aggregators.pdf.(Ref(dist_est),
Ref(tracked_responses),
eachmatcol(xs)) ./ denom
raw_denom = normdenom(integrator, recorder.raw_estimator, tracked_responses)
recorder.raw_likelihoods[:, recorder.col_idx] = Aggregators.pdf.(Ref(recorder.raw_estimator),
recorder.raw_likelihoods[:, recorder.col_idx] = Aggregators.pdf.(
Ref(recorder.raw_estimator),
Ref(tracked_responses),
eachmatcol(xs)) ./ raw_denom

Expand Down Expand Up @@ -224,7 +228,8 @@ function (recorder::CatRecorder)(tracked_responses, resp_idx, terminating)
item_index = tracked_responses.responses.indices[end]
item_correct = tracked_responses.responses.values[end] > 0
ir = ItemResponse(tracked_responses.item_bank, item_index)
save_sampled(recorder.xs, recorder.integrator, recorder, tracked_responses, ir, item_correct)
save_sampled(
recorder.xs, recorder.integrator, recorder, tracked_responses, ir, item_correct)

# Save item parameters
params = item_params(tracked_responses.item_bank, item_index)
Expand Down Expand Up @@ -286,7 +291,7 @@ function lh_evolution_interactive(recorder; abilities = nothing)
"raw ability estimate",
"actual ability",
"current item response",
"previous responses",
"previous responses"
]
toggles = [Toggle(conv_dist_fig, active = true) for _ in toggle_labels]
labels = [Label(conv_dist_fig, lift(x -> x ? "Hide $l" : "Show $l", t.active))
Expand Down

0 comments on commit 604706b

Please sign in to comment.