gameanalysis.rsgame module¶
Module for base role symmetric game structures
Role symmetric games have a number of common attributes and functions that are defined in the RsGame class that actual RsGame interfaces should support. In addition, an implementation of an EmptyGame is provided for convenience purposes. Note, that the constructor to EmptyGame (and most games) should not be called, and instead, various convenience functions to create EmptyGames that start with the prefix emptygame should be called instead.
Most structures in a role symmetric game are an array of length game.num_strats, that lists a value for every strategy in the game. In this form, each roles strategies are contiguous. To aggregate elements by role, it is helpful to use numpy ufuncs, such as np.add.reduceat(profile, game.role_starts) will add up all of the players in each role of a profile. np.split(profile, game.role_starts[1:]) will return a list where each element is that role’s data. To convert a role array into a strategy array, one can do something like role_array.repeat(game.num_role_strats).
As a general rule, any attribute of a game that begins with num_ is an actual attribute instead of a getter function. Attributes that have the world role in them tend to be arrays of size num_roles and attributes that have strat in the name tend to be arrays of size num_strats.
-
gameanalysis.rsgame.
add
(*games)[source]¶ Add games together to that the payoff is the sum of each game
- Parameters
games (RsGame) – The games to add together
-
gameanalysis.rsgame.
const
(num_role_players, num_role_strats, constant)[source]¶ Create a new constant game
-
gameanalysis.rsgame.
const_names
(role_names, num_role_players, strat_names, constant)[source]¶ Create a new constant game with names
-
gameanalysis.rsgame.
const_replace
(copy_game, constant)[source]¶ Replace a game with constant payoffs
-
gameanalysis.rsgame.
empty
(num_role_players, num_role_strats)[source]¶ Create an empty game with default names
- Parameters
num_role_players (ndarray-like, int) – The number of players in each role in order, or the number of players per role if identical (will be broadcast to match the number of roles).
num_role_strats (ndarray-like, int) – The number of strategies in each role in order, or the number of strategies per role if identical (will be broadcast to match the number of roles).
-
gameanalysis.rsgame.
empty_copy
(copy_game)[source]¶ Copy parameters of a game into an empty game
This method is useful to keep convenience methods of game without attached data.
- Parameters
copy_game (RsGame) – Game to copy info from.
-
gameanalysis.rsgame.
empty_json
(json)[source]¶ Read a EmptyGame from json
- Parameters
json ({...}) – A json representation of a basic game with names. Must either be {roles: [{name: <role>, strategies: [<strat>]}]}, or {strategies: {<role>: [<strat>]}}.
-
gameanalysis.rsgame.
empty_names
(role_names, num_role_players, strat_names)[source]¶ Create an empty game with names
- Parameters
roles_names ([str]) – The name for each role.
num_role_players (ndarray, int, [int]) – The number of players in each role.
strat_names ([[str]]) – The name of each strategy for each role.
-
gameanalysis.rsgame.
mix
(game0, game1, prob)[source]¶ Mix games together
The resulting payoff is a (1-prob) fraction of game0 and a prob fraction of game1.
- Parameters
game0 (RsGame) – The first game to mix.
game1 (RsGame) – The second game to mix.
prob (float) – The fraction to merge the games. 0 corresponds to a copy of game0, 1 corresponds to game1, and somewhere between corresponds to the linear interpolation between them.