gameanalysis.matgame module¶
module for complete independent games
-
class
gameanalysis.matgame.
MatrixGame
(role_names, strat_names, payoff_matrix)[source]¶ Bases:
gameanalysis.rsgame.CompleteGame
Matrix game representation
This represents a complete independent game more compactly than a Game, but only works for complete independent games.
Parameters: - role_names ((str,)) – The name of each role.
- strat_names (((str,),)) – The name of each strategy per role.
- payoff_matrix (ndarray) – The matrix of payoffs for an asymmetric game. The last axis is the payoffs for each player, the first axes are the strategies for each player. matrix.shape[:-1] must correspond to the number of strategies for each player. matrix.ndim - 1 must equal matrix.shape[-1].
-
compress_profile
(profile)[source]¶ Compress profile in array of ints
Normal profiles are an array of number of players playing a strategy. Since matrix games always have one player per role, this compresses each roles counts into a single int representing the played strategy per role.
-
deviation_payoffs
(mix, *, jacobian=False)[source]¶ Computes the expected value of each pure strategy played against all opponents playing mix.
Parameters: - mix (ndarray) – The mix all other players are using
- jacobian (bool) – If true, the second returned argument will be the jacobian of the deviation payoffs with respect to the mixture. The first axis is the deviating strategy, the second axis is the strategy in the mix the jacobian is taken with respect to.
-
gameanalysis.matgame.
matgame
(payoff_matrix)[source]¶ Create a game from a dense matrix with default names
Parameters: payoff_matrix (ndarray-like) – The matrix of payoffs for an asymmetric game.
-
gameanalysis.matgame.
matgame_copy
(copy_game)[source]¶ Copy a matrix game from an existing game
Parameters: copy_game (RsGame) – Game to copy payoff data out of. This game must be complete.
-
gameanalysis.matgame.
matgame_json
(json)[source]¶ Read a matrix game from json
In general, the json will have ‘type’: ‘matrix…’ to indicate that it’s a matrix game, but if the other fields are correct, this will still succeed.
-
gameanalysis.matgame.
matgame_names
(role_names, strat_names, payoff_matrix)[source]¶ Create a game from a payoff matrix with names
Parameters: - role_names ([str]) – The name of each role.
- strat_names ([[str]]) – The name of each strategy for each role.
- payoff_matrix (ndarray-like) – The matrix mapping strategy indices to payoffs for each player.