Skip to content

Commit 27ae85f

Browse files
committed
Add docs for Stateful and improve using your cat guide
1 parent e2825f3 commit 27ae85f

File tree

6 files changed

+213
-24
lines changed

6 files changed

+213
-24
lines changed

docs/make.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,15 @@ makedocs(;
3434
format = format,
3535
pages = [
3636
"Getting started" => "index.md",
37-
"Creating a CAT" => "creating_a_cat.md",
38-
"Using your CAT" => "using_your_cat.md",
37+
"Guides" => [
38+
"Creating a CAT" => "creating_a_cat.md",
39+
"Using your CAT" => "using_your_cat.md",
40+
],
3941
(build_demos ? demopage : "Demo page skipped" => []),
40-
"API reference" => "api.md",
42+
"References" => [
43+
"Stateful interface" => "stateful.md",
44+
"API reference (all docstrings)" => "api.md",
45+
],
4146
"Contributing" => "contributing.md",
4247
],
4348
warnonly = [:missing_docs],

docs/src/stateful.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Stateful interface
2+
3+
```@meta
4+
CurrentModule = ComputerAdaptiveTesting
5+
```
6+
7+
```@docs
8+
Stateful.Stateful
9+
```
10+
11+
## Interface
12+
13+
```@docs
14+
Stateful.StatefulCat
15+
Stateful.next_item
16+
Stateful.ranked_items
17+
Stateful.item_criteria
18+
Stateful.add_response!
19+
Stateful.rollback!
20+
Stateful.reset!
21+
Stateful.set_item_bank!
22+
Stateful.get_responses
23+
Stateful.get_ability
24+
```
25+
26+
## CatRules implementation
27+
28+
There is an implementation in terms of [CatRules](@ref):
29+
30+
```@docs
31+
Stateful.StatefulCatConfig
32+
```
33+
34+
## Usage
35+
36+
Just as [CatLoopConfig](@ref) can wrap [CatRules](@ref), you can also use it with any implementor of [Stateful.StatefulCat](@ref), and run using [Sim.run_cat](@ref).

docs/src/using_your_cat.md

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,52 @@
11
# Using your CAT
22

3+
```@meta
4+
CurrentModule = ComputerAdaptiveTesting
5+
```
6+
37
Now you've created your cat according to [Creating a CAT](@ref), there are
4-
a number of ways you can use it. This section covers a few. See also the [Examples](@ref demo-page).
8+
a number of ways you can use it.
9+
This section covers a few.
10+
See also the [Examples](@ref demo-page).
11+
12+
When you've set up your CAT using [CatRules](@ref), you can wrap it in a [CatLoopConfig](@ref) and run it with [run_cat](@ref).
13+
14+
```@docs; canonical=false
15+
CatLoopConfig
16+
run_cat
17+
```
518

619
## Simulating CATs
720

8-
TODO
21+
You might like to use a response memory or simulated responses to simulate your CAT using `auto_responder`:
922

10-
## Integrating into a user-facing applications
23+
```@docs; canonical=false
24+
Sim.auto_responder
25+
```
1126

12-
TODO
27+
In case your data is different you might like to modify the implementation:
1328

14-
## Evaluating CATs
29+
```@example
30+
function auto_responder(responses)
31+
function (index, label_)
32+
responses[index]
33+
end
34+
end
35+
```
1536

16-
TODO
37+
## Integrating into a user-facing applications
1738

18-
## Visualising CATs
39+
A simple interactive implementation of `get_response(...)` is `prompt_response`:
1940

20-
TODO
41+
```@docs; canonical=false
42+
Sim.prompt_response
43+
```
2144

22-
## Constructing decision trees from CATs
45+
For other types of interactivity you can modify the implementation:
2346

24-
TODO
47+
```@example
48+
function prompt_response(index_, label)
49+
println("Response for $label > ")
50+
parse(Int8, readline())
51+
end
52+
```

src/CatConfig.jl

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module CatConfig
22

33
export CatRules, CatLoopConfig
44

5-
using DocStringExtensions: FUNCTIONNAME, TYPEDEF, TYPEDFIELDS
5+
using DocStringExtensions
66
using PsychometricsBazaarBase.Parameters
77

88
using ..Aggregators: AbilityEstimator, AbilityTracker, ConsAbilityTracker,
@@ -114,20 +114,30 @@ function collect_trackers(next_item_rule::NextItemRule, ability_tracker::Ability
114114
end
115115

116116
"""
117+
```julia
118+
struct $(FUNCTIONNAME)
119+
$(FUNCTIONNAME)(; rules=..., get_response=..., new_response_callback=...)
120+
```
121+
$(TYPEDFIELDS)
122+
117123
Configuration for a simulatable CAT.
118124
"""
119125
@with_kw struct CatLoopConfig{CatEngineT} <: CatConfigBase
120126
"""
121-
The CAT configuration.
127+
An object which implements the CAT engine.
128+
Implementations exist for:
129+
* [CatRules](@ref)
130+
* [Stateful.StatefulCat](@ref ComputerAdaptiveTesting.Stateful.StatefulCat)
122131
"""
123132
rules::CatEngineT # e.g. CatRules
124133
"""
125-
The function (index, label) -> Int8 which obtains the testee's response for
134+
The function `(index, label) -> Int8`` which obtains the testee's response for
126135
a given question, e.g. by prompting or simulation from data.
127136
"""
128137
get_response::Any
129138
"""
130-
A callback called each time there is a new responses
139+
A callback called each time there is a new responses.
140+
If provided, it is passed `(responses::TrackedResponses, terminating)`.
131141
"""
132142
new_response_callback = nothing
133143
end

src/Sim.jl

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module Sim
22

3+
using DocStringExtensions
34
using StatsBase
45
using FittedItemBanks: AbstractItemBank, ResponseType
56
using ..Responses
@@ -10,14 +11,18 @@ using ..NextItemRules: compute_criteria, best_item
1011
export run_cat, prompt_response, auto_responder
1112

1213
"""
13-
This response callback simply prompts
14+
$(TYPEDSIGNATURES)
15+
16+
This response callback simply prompts the user for the response using the console
1417
"""
1518
function prompt_response(index_, label)
1619
println("Response for $label > ")
1720
parse(Int8, readline())
1821
end
1922

2023
"""
24+
$(TYPEDSIGNATURES)
25+
2126
This function constructs a next item function which automatically responds
2227
according to `responses`.
2328
"""
@@ -39,7 +44,13 @@ function item_label(ib_labels, next_index)
3944
end
4045

4146
"""
42-
Run a given CatLoopConfig
47+
```julia
48+
$(FUNCTIONNAME)(cat_config::CatLoopConfig, item_bank::AbstractItemBank; ib_labels=nothing)
49+
```
50+
51+
Run a given [CatLoopConfig](@ref) `cat_config` on the given `item_bank`.
52+
If `ib_labels` is not given, default labels of the form
53+
`<<item #\$index>>` are passed to the callback.
4354
"""
4455
function run_cat(cat_config::CatLoopConfig{RulesT},
4556
item_bank::AbstractItemBank;

src/Stateful.jl

Lines changed: 104 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,131 @@
1+
"""
2+
This module defines the interface for a stateful CAT as well as an implementation in terms
3+
of [CatRules](@ref).
4+
The interface is meant to enable polymorphic use of different CAT implementations.
5+
"""
16
module Stateful
27

8+
using DocStringExtensions
9+
310
using FittedItemBanks: AbstractItemBank, ResponseType
411
using ..Aggregators: TrackedResponses, Aggregators
512
using ..CatConfig: CatLoopConfig, CatRules
613
using ..Responses: BareResponses, Response
714
using ..NextItemRules: compute_criteria, best_item
15+
using ..Sim: Sim, item_label
816

9-
export StatefulCat, StatefulCatConfig, run_cat
17+
export StatefulCat, StatefulCatConfig
1018
public next_item, ranked_items, item_criteria
1119
public add_response!, rollback!, reset!, get_responses, get_ability
1220

13-
## StatefulCat interface
21+
"""
22+
$(TYPEDEF)
23+
24+
Abstract supertype for implementation of the stateful CAT interface.
25+
"""
1426
abstract type StatefulCat end
1527

28+
"""
29+
```julia
30+
$(FUNCTIONNAME)(config::StatefulCat) -> IndexT
31+
```
32+
33+
Returns the index of the best next item according to the CAT.
34+
35+
Ideally `IndexT` will be an integer and the return type a 1-based index, however it
36+
should at least be the same type as accepted by [add_response!](@ref).
37+
"""
1638
function next_item end
1739

40+
"""
41+
```julia
42+
$(FUNCTIONNAME)(config::StatefulCat) -> AbstractVector{IndexT}
43+
```
44+
45+
Return a vector of indices of the sorted from best to worst item according to the CAT.
46+
"""
1847
function ranked_items end
1948

49+
"""
50+
```julia
51+
$(FUNCTIONNAME)(config::StatefulCat) -> AbstractVector{CriteriaT}
52+
```
53+
54+
Returns a vector of criteria values for each item in the item bank.
55+
56+
The criteria can vary, but should attempt to interoperate with ComputerAdaptiveTesting.jl.
57+
"""
2058
function item_criteria end
2159

60+
"""
61+
```julia
62+
$(FUNCTIONNAME)(config::StatefulCat, index::IndexT, response::ResponseT)
63+
````
64+
65+
The exact response type `ResponseT` depends on the item bank.
66+
It should be chosen to interoperate with any equivalent item bank according to the
67+
implementation in `ComputerAdaptiveTesting.jl`.
68+
"""
2269
function add_response! end
2370

24-
#function add_responses! end
71+
"""
72+
```julia
73+
$(FUNCTIONNAME)(config::StatefulCat)
74+
```
75+
76+
Rollback the last response added with [add_response!](@ref).
2577
78+
Some CAT implementations may not support this operation in which case they will
79+
throw an error.
80+
"""
2681
function rollback! end
2782

83+
84+
"""
85+
```julia
86+
$(FUNCTIONNAME)(config::StatefulCat)
87+
```
88+
89+
Reset the CAT to its initial state, removing all responses.
90+
"""
2891
function reset! end
2992

93+
"""
94+
```julia
95+
$(FUNCTIONNAME)(config::StatefulCat, item_bank::AbstractItemBank)
96+
```
97+
98+
Set the current item bank of the CAT.
99+
This will also reset the CAT to its initial state, removing all responses.
100+
101+
Some CAT implementations may not support this operation in which case they will
102+
throw an error.
103+
"""
104+
function set_item_bank! end
105+
106+
"""
107+
```julia
108+
$(FUNCTIONNAME)(config::StatefulCat) -> Tuple{AbstractVector{IndexT}, AbstractVector{ResponseT}}
109+
```
110+
111+
Returns a tuple of the indices and responses of the items that have been
112+
added to the CAT with [add_response!](@ref) so far.
113+
"""
30114
function get_responses end
31115

116+
"""
117+
```julia
118+
$(FUNCTIONNAME)(config::StatefulCat) -> AbilityT
119+
```
120+
121+
Return the current ability estimate according to the CAT.
122+
The type of the ability estimate `AbilityT` depends on the CAT implementation
123+
but should attempt to interoperate with ComputerAdaptiveTesting.jl.
124+
"""
32125
function get_ability end
33126

34127
## Running the CAT
35-
function run_cat(cat_config::CatLoopConfig{RulesT},
128+
function Sim.run_cat(cat_config::CatLoopConfig{RulesT},
36129
ib_labels = nothing) where {RulesT <: StatefulCat}
37130
(; stateful_cat, get_response, new_response_callback) = cat_config
38131
while true
@@ -59,7 +152,13 @@ end
59152

60153
## TODO: Materialise the cat into a decsision tree
61154

62-
## Implementation for CatConfig
155+
"""
156+
$(TYPEDEF)
157+
$(TYPEDSIGNATURES)
158+
159+
This is a the `StatefulCat` implementation in terms of `CatRules`.
160+
It is also the de-facto standard for the behavior of the interface.
161+
"""
63162
struct StatefulCatConfig{TrackedResponsesT <: TrackedResponses} <: StatefulCat
64163
rules::CatRules
65164
tracked_responses::Ref{TrackedResponsesT}

0 commit comments

Comments
 (0)