shapiq.utils.generate_interaction_lookupΒΆ

shapiq.utils.generate_interaction_lookup(players, min_order, max_order=None)[source]ΒΆ

Generates a lookup dictionary for interactions.

Parameters:
  • players (Iterable[TypeVar(T, int, str)] | int) – A unique set of players or an Integer denoting the number of players.

  • min_order (int) – The minimum order of the approximation.

  • max_order (int | None) – The maximum order of the approximation.

Return type:

dict[tuple[TypeVar(T, int, str), ...], int] | dict[tuple[int, ...], int]

Returns:

A dictionary that maps interactions to their index in the values vector.

Example

>>> generate_interaction_lookup(3, 1, 3)
{(0,): 0, (1,): 1, (2,): 2, (0, 1): 3, (0, 2): 4, (1, 2): 5, (0, 1, 2): 6}
>>> generate_interaction_lookup(3, 2, 2)
{(0, 1): 0, (0, 2): 1, (1, 2): 2}
>>> generate_interaction_lookup(["A", "B", "C"], 1, 2)
{('A',): 0, ('B',): 1, ('C',): 2, ('A', 'B'): 3, ('A', 'C'): 4, ('B', 'C'): 5}