psifr.maskers.transitions_masker#

psifr.maskers.transitions_masker(pool_items, recall_items, pool_output, recall_output, pool_test=None, recall_test=None, test=None)#

Iterate over transitions with masking.

Transitions are between a “previous” item and a “current” item. Non-included transitions will be skipped. A transition is yielded only if it matches the following conditions:

(1) Each item involved in the transition is in the pool. Items are removed from the pool after they appear as the previous item.

(2) Optionally, an additional check is run based on test values associated with the items in the transition. For example, this could be used to only include transitions where the category of the previous and current items is the same.

The masker will yield “output” values, which may be distinct from the item identifiers used to determine item repeats.

Parameters:
  • pool_items (list) – Items available for recall. Order does not matter. May contain repeated values. Item identifiers must be unique within pool.

  • recall_items (list) – Recalled items in output position order.

  • pool_output (list) – Output values for pool items. Must be the same order as pool.

  • recall_output (list) – Output values in output position order.

  • pool_test (list, optional) – Test values for items available for recall. Must be the same order as pool.

  • recall_test (list, optional) – Test values for items in output position order.

  • test (callable, optional) –

    Used to test whether individual transitions should be included, based on test values.

    test(prev, curr) - test for included transition

    test(prev, poss) - test for included possible transition

Yields:
  • output (int) – Output position of this transition. The first transition is 1.

  • prev (object) – Output value for the “from” item on this transition.

  • curr (object) – Output value for the “to” item.

  • poss (numpy.array) – Output values for all possible valid “to” items.

Examples

>>> from psifr import maskers
>>> pool = [1, 2, 3, 4, 5, 6]
>>> recs = [6, 2, 3, 6, 1, 4]
>>> masker = maskers.transitions_masker(
...     pool_items=pool, recall_items=recs, pool_output=pool, recall_output=recs
... )
>>> for output, prev, curr, poss in masker:
...     print(output, prev, curr, poss)
1 6 2 [1 2 3 4 5]
2 2 3 [1 3 4 5]
5 1 4 [4 5]