shapiq.approximator.permutation#

This module contains all permutation-based sampling algorithms to estimate SII/nSII and STI.

class shapiq.approximator.permutation.PermutationSamplingSII(n, max_order, index='SII', top_order=False, random_state=None)[source]#

Bases: Approximator, KShapleyMixin

Permutation Sampling approximator for the SII (and k-SII) index.

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

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

  • top_order (bool) – Whether to approximate only the top order interactions (True) or all orders up to the specified order (False).

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

n#

The number of players.

max_order#

The interaction order of the approximation.

top_order#

Whether to approximate only the top order interactions (True) or all orders up to the specified order (False).

min_order#

The minimum order to approximate.

iteration_cost#

The cost of a single iteration of the permutation sampling.

Example

>>> from games import DummyGame
>>> from approximator import PermutationSamplingSII
>>> game = DummyGame(n=5, interaction=(1, 2))
>>> approximator = PermutationSamplingSII(n=5, max_order=2)
>>> approximator.approximate(budget=1_000, game=game)
InteractionValues(
    index=SII, order=2, estimated=True, estimation_budget=988,
    values={
        (0,): 0.2,
        (1,): 0.7,
        (2,): 0.7,
        (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
    }
)
approximate(budget, game, batch_size=5)[source]#

Approximates the interaction values.

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

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

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

Returns:

The estimated interaction values.

Return type:

InteractionValues

class shapiq.approximator.permutation.PermutationSamplingSTI(n, max_order, random_state=None)[source]#

Bases: Approximator

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

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

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

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

n#

The number of players.

max_order#

The interaction order of the approximation.

min_order#

The minimum order to approximate.

iteration_cost#

The cost of a single iteration of the permutation sampling.

Example

>>> from games import DummyGame
>>> from approximator import PermutationSamplingSTI
>>> game = DummyGame(n=5, interaction=(1, 2))
>>> approximator = PermutationSamplingSTI(n=5, max_order=2)
>>> approximator.approximate(budget=200, game=game)
InteractionValues(
    index=STI, 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
    }
)
approximate(budget, game, batch_size=1)[source]#

Approximates the interaction values.

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

  • 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.

Returns:

The estimated interaction values.

Return type:

InteractionValues

Modules

shapiq.approximator.permutation.sii

This module implements the Permutation Sampling approximator for the SII (and k-SII) index.

shapiq.approximator.permutation.sti

This module contains the permutation sampling algorithms to estimate STI scores.