shapiq.utils.transform_coalitions_to_arrayΒΆ

shapiq.utils.transform_coalitions_to_array(coalitions, n_players=None)[source]ΒΆ

Transforms a collection of coalitions to a binary array (one-hot encodings).

Parameters:
  • coalitions (Collection[tuple[int, ...]]) – Collection of coalitions.

  • n_players (int | None) – Number of players. Defaults to None (determined from the coalitions). If provided, n_players must be greater than the maximum player index in the coalitions.

Return type:

ndarray[tuple[Any, ...], dtype[bool]]

Returns:

Binary array of coalitions.

Example

>>> coalitions = [(0, 1), (1, 2), (0, 2)]
>>> transform_coalitions_to_array(coalitions)
array([[ True,  True, False],
       [False,  True,  True],
       [ True, False,  True]])
>>> transform_coalitions_to_array(coalitions, n_players=4)
array([[ True,  True, False, False],
       [False,  True,  True, False],
       [ True, False,  True, False]])