shapiq.approximator.ApproximatorΒΆ
- class shapiq.approximator.Approximator(n, max_order, index, *, top_order=False, min_order=0, pairing_trick=False, sampling_weights=None, random_state=None, initialize_dict=True)[source]ΒΆ
-
This class is the base class for all approximators.
Approximators are used to estimate the interaction values of a model or any value function. Different approximators can be used to estimate different interaction indices. Some can be used to estimate all indices.
- Variables:
n β The number of players.
_grand_coalition_set β The set of players (starting from
0ton - 1)._grand_coalition_array β The array of players (starting from
0ton).max_order β The interaction order of the approximation.
index β The interaction index to be estimated.
top_order β If True, the approximation is performed only for the top order interactions. If False, the approximation is performed for all orders up to the specified order.
min_order β The minimum order of the approximation. If top_order is
True,min_orderis equal to max_order. Otherwise,min_orderis equal to0.iteration_cost β The cost of a single iteration of the approximator.
- Parameters:
Initialize the Approximator.
- Parameters:
n (
int) β The number of players.max_order (
int) β The maximum interaction order of the approximation.index (
TypeVar(TIndices, bound=Literal['SV','BV','SII','BII','k-SII','STII','FBII','FSII','kADD-SHAP','CHII'])) β The interaction index to be estimated.top_order (
bool) β If True, the approximation is performed only for the top order interactions. If False, the approximation is performed for all orders up to the specified order.min_order (
int) β The minimum interaction order of the approximation. Defaults to0.pairing_trick (
bool) β If True, the pairing trick is applied to the sampling procedure. Defaults toFalse.sampling_weights (
ndarray[tuple[Any,...],dtype[floating]] |None) β An optional array of weights for the sampling procedure. The weights must be of shape(n + 1,)and are used to determine the probability of sampling a coalition of a certain size. Defaults toNone.random_state (
int|None) β The random state to use for the approximation. Defaults toNone. If notNone, the random state is used to seed the random number generator.initialize_dict (
bool) β If True, initializes the interaction lookup dictionary. Defaults toTrue. Note this is oftenTruefor estimators that estimate all interactions for each order. This is set toFalsefor example inSPEX.
- static aggregate_interaction_values(base_interactions, order=None)[source]ΒΆ
Aggregates the interaction values.
- Parameters:
base_interactions (
InteractionValues) β The base interaction values to aggregate.order (
int|None) β The order of the aggregation. For example, the order of the k-SII aggregation. IfNone(default), the maximum order of the base interactions is used.
- Return type:
- Returns:
The aggregated interaction values.
- __call__(budget, game, **kwargs)[source]ΒΆ
Calls the approximate method.
This method is a wrapper around the approximate method. It is used to call the approximator with the given budget and game function.
- Parameters:
- Return type:
- abstractmethod approximate(budget, game, **kwargs)[source]ΒΆ
Approximates the interaction values.
Abstract method that needs to be implemented for each approximator.
- Parameters:
- Return type:
- Returns:
The interaction values.
- Raises:
NotImplementedError β If the method is not implemented.