shapiq_benchmark.computers.BruteForceComputer

class shapiq_benchmark.computers.BruteForceComputer(game)[source]

Bases: Computer[Game]

Brute force: evaluates all 2**n coalitions with ExactComputer.

Works for every game, at a cost exponential in the number of players: computing the values of a game of more than max_players players warns. The game values are evaluated once and reused for every index and order.

Bind the computer to a game.

Parameters:

game (Game) – The game.

classmethod supported_indices()[source]

The indices of ExactComputer.

Return type:

tuple[Literal['SII', 'BII', 'CHII', 'Co-Moebius', 'SGV', 'BGV', 'CHGV', 'IGV', 'EGV', 'k-SII', 'STII', 'FSII', 'kADD-SHAP', 'FBII', 'SV', 'BV', 'JointSV', 'Moebius', 'Fourier', 'ELC'], ...]

classmethod supports_game(game)[source]

Brute force supports every game.

Return type:

bool

exact_values(index, order)

Compute the exact interaction values of order 1 to order.

Parameters:
  • index (Literal['SII', 'BII', 'CHII', 'Co-Moebius', 'SGV', 'BGV', 'CHGV', 'IGV', 'EGV', 'k-SII', 'STII', 'FSII', 'kADD-SHAP', 'FBII', 'SV', 'BV', 'JointSV', 'Moebius', 'Fourier', 'ELC']) – The interaction index, e.g. "k-SII".

  • order (int) – The highest interaction order.

Return type:

InteractionValues

Returns:

The interactions of order 1 to order, with the game’s empty value as baseline.

Raises:

UnsupportedComputationError – If (index, order) is not supported.

max_order()

Return the highest supported interaction order (the number of players by default).

Return type:

int

supports(index, order)

Return whether the computer can compute index up to order for its game.

Return type:

bool

max_players = 25

The number of players above which computing warns (2**25 game evaluations). Brute force more than doubles its time and memory with every player: at 22 players, the Shapley values of a cheap game take about 2.5 minutes and 2.6 GB. Set BruteForceComputer.max_players to change the limit.

name = 'brute_force'

A short, stable name of the computer (part of ground-truth cache keys).