|
| 1 | +#= |
| 2 | +This file implements next item combinators which take a state criterion |
| 3 | +or item criterion and look at its value in expectation with regards to |
| 4 | +a particular item. |
| 5 | +=# |
| 6 | + |
| 7 | +abstract type ResponseExpectation end |
| 8 | + |
| 9 | +function ResponseExpectation(ability_estimator::PointAbilityEstimator, |
| 10 | + bits...) |
| 11 | + PointResponseExpectation(ability_estimator) |
| 12 | +end |
| 13 | + |
| 14 | +function ResponseExpectation(ability_estimator::DistributionAbilityEstimator, |
| 15 | + bits...) |
| 16 | + @returnsome Integrator(bits...) integrator->DistributionResponseExpectation( |
| 17 | + ability_estimator, |
| 18 | + integrator) |
| 19 | +end |
| 20 | + |
| 21 | +""" |
| 22 | +$(TYPEDEF) |
| 23 | +$(TYPEDFIELDS) |
| 24 | +
|
| 25 | +This `ResponseExpectation` gets expected outcomes based on a point ability estimates. |
| 26 | +""" |
| 27 | +struct PointResponseExpectation{ |
| 28 | + PointAbilityEstimatorT <: PointAbilityEstimator, |
| 29 | +} <: ResponseExpectation |
| 30 | + ability_estimator::PointAbilityEstimatorT |
| 31 | +end |
| 32 | + |
| 33 | +function Aggregators.response_expectation( |
| 34 | + point_response_expectation::PointResponseExpectation, |
| 35 | + tracked_responses, |
| 36 | + item_idx) |
| 37 | + response_expectation(point_response_expectation.ability_estimator, |
| 38 | + tracked_responses, |
| 39 | + item_idx) |
| 40 | +end |
| 41 | + |
| 42 | +struct DistributionResponseExpectation{ |
| 43 | + DistributionAbilityEstimatorT <: DistributionAbilityEstimator, |
| 44 | + AbilityIntegratorT <: AbilityIntegrator |
| 45 | +} <: ResponseExpectation |
| 46 | + ability_estimator::DistributionAbilityEstimatorT |
| 47 | + integrator::AbilityIntegratorT |
| 48 | +end |
| 49 | + |
| 50 | +function Aggregators.response_expectation( |
| 51 | + dist_response_expectation::DistributionResponseExpectation, |
| 52 | + tracked_responses, |
| 53 | + item_idx) |
| 54 | + response_expectation(dist_response_expectation.ability_estimator, |
| 55 | + dist_response_expectation.integrator, |
| 56 | + tracked_responses, |
| 57 | + item_idx) |
| 58 | +end |
| 59 | + |
| 60 | +""" |
| 61 | +$(TYPEDEF) |
| 62 | +$(TYPEDFIELDS) |
| 63 | +
|
| 64 | +This ItemCriterion wraps a a `ResponseExpectation` and a `StateCriterion` or |
| 65 | +`ItemCriterion` to look at the criterion's expected value for a particular |
| 66 | +item 1-ply ahead. |
| 67 | +""" |
| 68 | +struct ExpectationBasedItemCriterion{ |
| 69 | + ResponseExpectationT <: ResponseExpectation, |
| 70 | + CriterionT <: Union{StateCriterion, ItemCriterion} |
| 71 | +} <: ItemCriterion |
| 72 | + response_expectation::ResponseExpectationT |
| 73 | + criterion::CriterionT |
| 74 | +end |
| 75 | + |
| 76 | +function _get_some_criterion(bits...; kwargs...) |
| 77 | + @returnsome StateCriterion(bits...; kwargs...) |
| 78 | + @returnsome ItemCriterion(bits...; kwargs...) |
| 79 | +end |
| 80 | + |
| 81 | +function ExpectationBasedItemCriterion(bits...; |
| 82 | + ability_estimator = nothing, |
| 83 | + ability_tracker = nothing) |
| 84 | + @requiresome criterion = _get_some_criterion( |
| 85 | + bits...; ability_estimator = ability_estimator, |
| 86 | + ability_tracker = ability_tracker) |
| 87 | + @requiresome ability_estimator = AbilityEstimator(bits..., |
| 88 | + ability_estimator = ability_estimator, |
| 89 | + ability_tracker = ability_tracker) |
| 90 | + response_expectation = ResponseExpectation(ability_estimator, bits...) |
| 91 | + ExpectationBasedItemCriterion(response_expectation, criterion) |
| 92 | +end |
| 93 | + |
| 94 | +function init_thread(::ExpectationBasedItemCriterion, responses::TrackedResponses) |
| 95 | + Speculator(responses, 1) |
| 96 | +end |
| 97 | + |
| 98 | +function _generic_criterion(criterion::StateCriterion, tracked_responses, item_idx) |
| 99 | + criterion(tracked_responses) |
| 100 | +end |
| 101 | +# TODO: Support init_thread for wrapped ItemCriterion |
| 102 | +function _generic_criterion(criterion::ItemCriterion, tracked_responses, item_idx) |
| 103 | + criterion(tracked_responses, item_idx) |
| 104 | +end |
| 105 | + |
| 106 | +function (item_criterion::ExpectationBasedItemCriterion)(speculator::Speculator, |
| 107 | + tracked_responses::TrackedResponses, |
| 108 | + item_idx) |
| 109 | + exp_resp = Aggregators.response_expectation(item_criterion.response_expectation, |
| 110 | + tracked_responses, |
| 111 | + item_idx) |
| 112 | + possible_responses = responses(ItemResponse(tracked_responses.item_bank, item_idx)) |
| 113 | + res = 0.0 |
| 114 | + for (prob, possible_response) in zip(exp_resp, possible_responses) |
| 115 | + replace_speculation!(speculator, SVector(item_idx), SVector(possible_response)) |
| 116 | + res += prob * |
| 117 | + _generic_criterion(item_criterion.criterion, speculator.responses, item_idx) |
| 118 | + end |
| 119 | + res |
| 120 | +end |
0 commit comments