shapiq.approximator.PermutationSamplingSTIIΒΆ

class shapiq.approximator.PermutationSamplingSTII(n, max_order, random_state=None, **kwargs)[source]ΒΆ

Bases: Approximator[Literal[β€˜STII’]]

Permutation Sampling approximator for the Shapley Taylor Index (STII).

See also

Example

>>> from shapiq_games.synthetic import DummyGame
>>> from shapiq.approximator import PermutationSamplingSTII
>>> game = DummyGame(n=5, interaction=(1, 2))
>>> approximator = PermutationSamplingSTII(n=5, max_order=2)
>>> approximator.approximate(budget=200, game=game)
InteractionValues(
    index=STII, order=2, estimated=True, estimation_budget=165,
    values={
        (0,): 0.2,
        (1,): 0.2,
        (2,): 0.2,
        (3,): 0.2,
        (4,): 0.2,
        (0, 1): 0,
        (0, 2): 0,
        (0, 3): 0,
        (0, 4): 0,
        (1, 2): 1.0,
        (1, 3): 0,
        (1, 4): 0,
        (2, 3): 0,
        (2, 4): 0,
        (3, 4): 0
    }
)

Initialize the Permutation Sampling approximator for STII.

Parameters:
  • n (int) – The number of players.

  • max_order (int) – The interaction order of the approximation.

  • random_state (int | None) – The random state to use for the permutation sampling. Defaults to None.

  • **kwargs (Any) – Additional keyword arguments (not used, only for compatibility).

approximate(budget, game, batch_size=1, **kwargs)[source]ΒΆ

Approximates the interaction values.

Parameters:
  • budget (int) – The budget for the approximation.

  • game (Game | Callable[[ndarray], ndarray]) – The game function as a callable that takes a set of players and returns the value.

  • batch_size (int) – The size of the batch. If None, the batch size is set to 1. Defaults to 1.

  • *args – Additional positional arguments (not used in this method).

  • **kwargs (Any) – Additional keyword arguments (not used in this method).

Returns:

The estimated interaction values.

Return type:

InteractionValues

valid_indices: tuple[Literal['STII'], ...] = ('STII',)ΒΆ

The valid indices for the base approximator.