pydvl.value.games
¶
This module provides several predefined games and, depending on the game, the corresponding Shapley values, Least Core values or both of them, for benchmarking purposes.
References¶
-
Castro, J., Gómez, D. and Tejada, J., 2009. Polynomial calculation of the Shapley value based on sampling. Computers & Operations Research, 36(5), pp.1726-1730. ↩
DummyGameDataset
¶
Bases: Dataset
Dummy game dataset.
Initializes a dummy game dataset with n_players and an optional description.
This class is used internally inside the Game class.
PARAMETER | DESCRIPTION |
---|---|
n_players |
Number of players that participate in the game.
TYPE:
|
description |
Optional description of the dataset. |
Source code in src/pydvl/value/games.py
indices
property
¶
Index of positions in data.x_train.
Contiguous integers from 0 to len(Dataset).
data_names
property
¶
Names of each individual datapoint.
Used for reporting Shapley values.
get_training_data
¶
Given a set of indices, returns the training data that refer to those indices.
This is used mainly by Utility to retrieve subsets of the data from indices. It is typically not needed in algorithms.
PARAMETER | DESCRIPTION |
---|---|
indices |
Optional indices that will be used to select points from
the training data. If |
RETURNS | DESCRIPTION |
---|---|
Tuple[NDArray, NDArray]
|
If |
Source code in src/pydvl/utils/dataset.py
from_sklearn
classmethod
¶
from_sklearn(
data: Bunch,
train_size: float = 0.8,
random_state: Optional[int] = None,
stratify_by_target: bool = False,
**kwargs
) -> Dataset
Constructs a Dataset object from a
sklearn.utils.Bunch, as returned by the load_*
functions in scikit-learn toy datasets.
Example
PARAMETER | DESCRIPTION |
---|---|
data |
scikit-learn Bunch object. The following attributes are supported:
TYPE:
|
train_size |
size of the training dataset. Used in
TYPE:
|
random_state |
seed for train / test split |
stratify_by_target |
If
TYPE:
|
kwargs |
Additional keyword arguments to pass to the
Dataset constructor. Use this to pass e.g.
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
Dataset
|
Object with the sklearn dataset |
Changed in version 0.6.0
Added kwargs to pass to the Dataset constructor.
Source code in src/pydvl/utils/dataset.py
from_arrays
classmethod
¶
from_arrays(
X: NDArray,
y: NDArray,
train_size: float = 0.8,
random_state: Optional[int] = None,
stratify_by_target: bool = False,
**kwargs
) -> Dataset
Constructs a Dataset object from X and y numpy arrays as
returned by the make_*
functions in sklearn generated datasets.
Example
PARAMETER | DESCRIPTION |
---|---|
X |
numpy array of shape (n_samples, n_features)
TYPE:
|
y |
numpy array of shape (n_samples,)
TYPE:
|
train_size |
size of the training dataset. Used in
TYPE:
|
random_state |
seed for train / test split |
stratify_by_target |
If
TYPE:
|
kwargs |
Additional keyword arguments to pass to the
Dataset constructor. Use this to pass e.g.
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
Dataset
|
Object with the passed X and y arrays split across training and test sets. |
New in version 0.4.0
Changed in version 0.6.0
Added kwargs to pass to the Dataset constructor.
Source code in src/pydvl/utils/dataset.py
get_test_data
¶
Returns the subsets of the train set instead of the test set.
PARAMETER | DESCRIPTION |
---|---|
indices |
Indices into the training data. |
RETURNS | DESCRIPTION |
---|---|
Tuple[NDArray, NDArray]
|
Subset of the train data. |
Source code in src/pydvl/value/games.py
DummyModel
¶
Game
¶
Game(
n_players: int,
score_range: Tuple[float, float] = (-np.inf, np.inf),
description: Optional[str] = None,
)
Bases: ABC
Base class for games
Any Game subclass has to implement the abstract _score
method
to assign a score to each coalition/subset and at least
one of shapley_values
, least_core_values
.
PARAMETER | DESCRIPTION |
---|---|
n_players |
Number of players that participate in the game.
TYPE:
|
score_range |
Minimum and maximum values of the |
description |
Optional string description of the dummy dataset that will be created. |
ATTRIBUTE | DESCRIPTION |
---|---|
n_players |
Number of players that participate in the game.
|
data |
Dummy dataset object.
|
u |
Utility object with a dummy model and dataset.
|
Source code in src/pydvl/value/games.py
SymmetricVotingGame
¶
SymmetricVotingGame(n_players: int)
Bases: Game
Toy game that is used for testing and demonstration purposes.
A symmetric voting game defined in (Castro et al., 2009)1 Section 4.1
For this game the utility of a coalition is 1 if its cardinality is greater than num_samples/2, or 0 otherwise.
PARAMETER | DESCRIPTION |
---|---|
n_players |
Number of players that participate in the game.
TYPE:
|
Source code in src/pydvl/value/games.py
AsymmetricVotingGame
¶
AsymmetricVotingGame(n_players: int = 51)
Bases: Game
Toy game that is used for testing and demonstration purposes.
An asymmetric voting game defined in (Castro et al., 2009)1 Section 4.2.
For this game the player set is \(N = \{1,\dots,51\}\) and the utility of a coalition is given by:
where \(w = [w_1,\dots, w_{51}]\) is a list of weights associated with each player.
PARAMETER | DESCRIPTION |
---|---|
n_players |
Number of players that participate in the game.
TYPE:
|
Source code in src/pydvl/value/games.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
|
ShoesGame
¶
Bases: Game
Toy game that is used for testing and demonstration purposes.
A shoes game defined in (Castro et al., 2009)1.
In this game, some players have a left shoe and others a right shoe. Single shoes have a worth of zero while pairs have a worth of 1.
The payoff of a coalition \(S\) is:
Where \(L\), respectively \(R\), is the set of players with left shoes, respectively right shoes.
PARAMETER | DESCRIPTION |
---|---|
left |
Number of players with a left shoe.
TYPE:
|
right |
Number of players with a right shoe.
TYPE:
|
Source code in src/pydvl/value/games.py
AirportGame
¶
AirportGame(n_players: int = 100)
Bases: Game
Toy game that is used for testing and demonstration purposes.
An airport game defined in (Castro et al., 2009)1 Section 4.3
PARAMETER | DESCRIPTION |
---|---|
n_players |
Number of players that participate in the game.
TYPE:
|
Source code in src/pydvl/value/games.py
MinimumSpanningTreeGame
¶
MinimumSpanningTreeGame(n_players: int = 100)
Bases: Game
Toy game that is used for testing and demonstration purposes.
A minimum spanning tree game defined in (Castro et al., 2009)1.
Let \(G = (N \cup \{0\},E)\) be a valued graph where \(N = \{1,\dots,100\}\), and the cost associated to an edge \((i, j)\) is:
A minimum spanning tree game \((N, c)\) is a cost game, where for a given coalition \(S \subset N\), \(v(S)\) is the sum of the edge cost of the minimum spanning tree, i.e. \(v(S)\) = Minimum Spanning Tree of the graph \(G|_{S\cup\{0\}}\), which is the partial graph restricted to the players \(S\) and the source node \(0\).
PARAMETER | DESCRIPTION |
---|---|
n_players |
Number of players that participate in the game.
TYPE:
|
Source code in src/pydvl/value/games.py
MinerGame
¶
MinerGame(n_players: int)
Bases: Game
Toy game that is used for testing and demonstration purposes.
Consider a group of n miners, who have discovered large bars of gold.
If two miners can carry one piece of gold, then the payoff of a coalition \(S\) is:
If there are more than two miners and there is an even number of miners, then the core consists of the single payoff where each miner gets 1/2.
If there is an odd number of miners, then the core is empty.
Taken from Wikipedia
PARAMETER | DESCRIPTION |
---|---|
n_players |
Number of miners that participate in the game.
TYPE:
|