Skip to content

Commit 78aab07

Browse files
author
Frankie Robertson
committed
Add/improve show(...) methods
1 parent 4f7d7db commit 78aab07

File tree

11 files changed

+116
-7
lines changed

11 files changed

+116
-7
lines changed

src/aggregators/Aggregators.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ using PsychometricsBazaarBase.Integrators: Integrators,
3333
using PsychometricsBazaarBase.Optimizers: OneDimOptimOptimizer, Optimizer
3434
using PsychometricsBazaarBase.ConstDistributions: std_normal, std_mv_normal
3535
import Distributions: pdf
36+
import Base: show
3637

3738
import FittedItemBanks
3839
import PsychometricsBazaarBase.IntegralCoeffs

src/aggregators/ability_estimator.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,15 @@ function ModeAbilityEstimator(bits...)
212212
ModeAbilityEstimator(dist_est, optimizer)
213213
end
214214

215+
function show(io::IO, ::MIME"text/plain", ability_estimator::ModeAbilityEstimator)
216+
println(io, "Estimate ability using its mode")
217+
indent_io = indent(io, 2; skip_first=true)
218+
print(indent_io, "Distribution estimator ")
219+
show(indent_io, ability_estimator.dist_est)
220+
print(indent_io, "Optimizer: ")
221+
show(indent_io, ability_estimator.optim)
222+
end
223+
215224
struct MeanAbilityEstimator{
216225
DistEst <: DistributionAbilityEstimator,
217226
IntegratorT <: AbilityIntegrator

src/aggregators/optimizers.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,22 @@ function (optim::FunctionOptimizer)(f::F,
1010
optim.optim(comp_f)
1111
end
1212

13+
function show(io::IO, ::MIME"text/plain", optim::FunctionOptimizer)
14+
indent_io = indent(io, 2)
15+
if optim.optim isa OneDimOptimOptimizer || optim.optim isa MultiDimOptimOptimizer || optim.optim isa NativeOneDimOptimOptimizer
16+
inner = optim.optim
17+
println(io, "Optimizer:")
18+
if optim.optim isa NativeOneDimOptimOptimizer
19+
name = typeof(inner.method).name.name
20+
else
21+
name = typeof(inner.optim).name.name
22+
end
23+
print(indent_io, "Method: ", name)
24+
print(indent_io, "Lo: ", inner.lo)
25+
print(indent_io, "Hi: ", inner.hi)
26+
end
27+
end
28+
1329
#=
1430
"""
1531
Argmax + max over the ability likihood given a set of responses with a given

src/next_item_rules/combinators/expectation.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ function Aggregators.response_expectation(
3939
item_idx)
4040
end
4141

42+
function show(io::IO, ::MIME"text/plain", point_response_expectation::PointResponseExpectation)
43+
println(io, "Expected response at point ability estimate")
44+
indent_io = indent(io, 2)
45+
print(indent_io, "Ability estimator: ")
46+
summary(indent_io, point_response_expectation.ability_estimator)
47+
println(io)
48+
end
49+
4250
struct DistributionResponseExpectation{
4351
DistributionAbilityEstimatorT <: DistributionAbilityEstimator,
4452
AbilityIntegratorT <: AbilityIntegrator
@@ -124,3 +132,12 @@ function compute_criterion(
124132
end
125133
res
126134
end
135+
136+
function show(io::IO, ::MIME"text/plain", item_criterion::ExpectationBasedItemCriterion)
137+
println(io, "Optimize an state/item/item-category criterion based on an expected response")
138+
indent_io = indent(io, 2)
139+
print(indent_io, "Expected response obtained by: ")
140+
show(indent_io, MIME"text/plain"(), item_criterion.response_expectation)
141+
print(indent_io, "Criterion: ")
142+
show(indent_io, MIME"text/plain"(), item_criterion.criterion)
143+
end

src/next_item_rules/criteria/pointwise/information.jl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ function compute_criterion_vec(
2222
-actual
2323
end
2424

25+
function show(io::IO, ::MIME"text/plain", ::ObservedInformationPointwiseItemCategoryCriterion)
26+
println(io, "Observed pointwise item-category information")
27+
end
28+
2529
"""
2630
See EmpiricalInformationPointwiseItemCategoryCriterion for more details.
2731
"""
@@ -46,6 +50,11 @@ function compute_criterion_vec(
4650
-actual
4751
end
4852

53+
54+
function show(io::IO, ::MIME"text/plain", ::RawEmpiricalInformationPointwiseItemCategoryCriterion)
55+
println(io, "Raw empirical pointwise item-category information")
56+
end
57+
4958
"""
5059
In equation 10 of [1] we see that we can compute information using 2nd derivatives of log likelihood or 1st derivative squared.
5160
For single categories, we need to an extra term which disappears when we calculate the total see [2].
@@ -95,6 +104,10 @@ function compute_criterion_vec(
95104
-actual
96105
end
97106

107+
function show(io::IO, ::MIME"text/plain", ::EmpiricalInformationPointwiseItemCategoryCriterion)
108+
println(io, "Empirical pointwise item-category information")
109+
end
110+
98111
#=
99112
"""
100113
This implements Fisher information as a pointwise item criterion.
@@ -116,4 +129,17 @@ function compute_criterion(
116129
ability
117130
)
118131
sum(compute_criterion_vec(tii.pcic, ir, ability))
132+
end
133+
134+
function show(io::IO, ::MIME"text/plain", rule::TotalItemInformation)
135+
if rule.pcic isa ObservedInformationPointwiseItemCategoryCriterion
136+
println(io, "Observed pointwise item information")
137+
elseif rule.pcic isa RawEmpiricalInformationPointwiseItemCategoryCriterion
138+
println(io, "Raw empirical pointwise item information")
139+
elseif rule.pcic isa EmpiricalInformationPointwiseItemCategoryCriterion
140+
println(io, "Empirical pointwise item information")
141+
else
142+
print(io, "Total ")
143+
show(io, MIME("text/plain"), rule.pcic)
144+
end
119145
end

src/next_item_rules/criteria/state/ability_variance.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ function compute_criterion(
6868
denom)
6969
end
7070

71+
function show(io::IO, ::MIME"text/plain", criterion::AbilityVarianceStateCriterion)
72+
println(io, "Minimise variance of ability estimate")
73+
indent_io = indent(io, 2)
74+
print(indent_io, "Distribution estimator: ")
75+
show(indent_io, MIME"text/plain"(), criterion.dist_est)
76+
print(indent_io, "Integrator: ")
77+
show(indent_io, MIME"text/plain"(), criterion.integrator)
78+
end
79+
7180
struct AbilityCovarianceStateMultiCriterion{
7281
DistEstT <: DistributionAbilityEstimator,
7382
IntegratorT <: AbilityIntegrator

src/next_item_rules/prelude/next_item_rule.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,13 @@ function best_item(rule::NextItemRule, tracked_responses::TrackedResponses)
5353
best_item(rule, tracked_responses, tracked_responses.item_bank)
5454
end
5555

56-
function Base.show(io::IO, ::MIME"text/plain", next_item_rule::ItemStrategyNextItemRule)
57-
println(io, "Strategy:")
58-
show(indent_io, MIME"text/plain"(), rules.strategy)
59-
println(io, "Item criterion:")
60-
show(indent_io, MIME"text/plain"(), rules.criterion)
56+
function Base.show(io::IO, ::MIME"text/plain", rule::ItemStrategyNextItemRule)
57+
println(io, "Pick optimal item criterion according to strategy")
58+
indent_io = indent(io, 2)
59+
print(indent_io, "Strategy: ")
60+
show(indent_io, MIME"text/plain"(), rule.strategy)
61+
print(indent_io, "Item criterion: ")
62+
show(indent_io, MIME"text/plain"(), rule.criterion)
6163
end
6264

6365
# Default implementation

src/next_item_rules/strategies/balance.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ end
4141

4242
function show(io::IO, ::MIME"text/plain", rule::GreedyForcedContentBalancer)
4343
indent_io = indent(io, 2)
44-
println(io, "Greedy + forced content balancer")
44+
println(io, "Greedy + forced content balancing")
4545
println(indent_io, "Target ratio: " * join(rule.targets, ", "))
46-
print(indent_io, "Using rule: ")
4746
show(indent_io, MIME("text/plain"), rule.inner_rule)
4847
end
4948

src/next_item_rules/strategies/pointwise.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ function best_item(rule::PointwiseNextItemRule, responses::TrackedResponses, ite
1616
return idx
1717
end
1818

19+
function show(io::IO, ::MIME"text/plain", rule::PointwiseNextItemRule)
20+
println(io, "Optimize a pointwise criterion at specified points")
21+
indent_io = indent(io, 2)
22+
points_desc = join(rule.points, ", ")
23+
println(indent_io, "Points: $points_desc")
24+
print(indent_io, "Criterion: ")
25+
show(indent_io, MIME("text/plain"), rule.criterion)
26+
end
27+
28+
1929
function PointwiseFirstNextItemRule(criterion, points, rule)
2030
FixedRuleSequencer((length(points),), (PointwiseNextItemRule(criterion, points), rule))
2131
end

src/next_item_rules/strategies/randomesque.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,8 @@ function best_item(
5151
items
5252
) where {ItemCriterionT <: ItemCriterion}
5353
randomesque(rule.strategy.rng, rule.criterion, responses, items, rule.strategy.k)[1]
54+
end
55+
56+
function show(io::IO, ::MIME"text/plain", rule::RandomesqueStrategy)
57+
println(io, "Randomesque strategy with k = $(rule.k)")
5458
end

0 commit comments

Comments
 (0)