gameanalysis.gamegen module

gameanalysis.gamegen.chicken(distribution=<function default_distribution>)[source]

Return a random prisoners dilemma game

gameanalysis.gamegen.covariant_game(num_role_strats, mean_dist=<function <lambda>>, var_dist=<function <lambda>>, covar_dist=<function default_distribution>)[source]

Generate a covariant game

Covariant games are asymmetric games where payoff values for each profile drawn according to multivariate normal.

The multivariate normal for each profile has a constant mean drawn from mean_dist, constant variance drawn from`var_dist`, and constant covariance drawn from covar_dist.

Parameters:
  • mean_dist ((shape) -> ndarray (shape)) – Distribution from which mean payoff for each profile is drawn. (default: lambda: 0)
  • var_dist ((shape) -> ndarray (shape)) – Distribution from which payoff variance for each profile is drawn. (default: lambda: 1)
  • covar_dist ((shape) -> ndarray (shape)) – Distribution from which the value of the off-diagonal covariance matrix entries for each profile is drawn. (default: uniform [-1, 1])
gameanalysis.gamegen.default_distribution(shape=None)[source]
gameanalysis.gamegen.game(players, strats, prob=1.0, distribution=<function default_distribution>)[source]

Generate a random role symmetric game with sparse profiles

Parameters:
  • players (int or [int]) – The number of players per role.
  • strats (int or [int]) – The number of strategies per role.
  • prob (float, optional) – The probability of any profile being included in the game.
  • distribution ((shape) -> ndarray, optional) – Distribution function to draw payoffs from.
gameanalysis.gamegen.gen_noise(game, prob=0.5, min_samples=1, min_width=0, max_width=1, noise_distribution=<function width_gaussian>)[source]

Generate noise for profiles of a game

This generates samples for payoff data by first generating some measure of distribution spread for each payoff in the game. Then, for each sample, noise is drawn from this distribution. As a result, some payoffs will have significantly more noise than other payoffs, helping to mimic real games.

Parameters:
  • game (Game) – The game to generate samples from. These samples are additive zero-mean noise to the payoff values.
  • prob (float, optional) – The probability of continuing to add another sample to a profile. If this is 0, min_samples will be generated for each profile. As this approaches one, more samples will be generated for each profile, sampled from the geometric distribution of 1 - prob.
  • min_samples (int, optional) – The minimum number of samples to generate for each profile. By default this will generate at least one sample for every profile with data. Setting this to zero means that a profile will only have data with probability prob.
  • min_width (float, optional) – The minimum standard deviation of each payoffs samples.
  • max_width (float, optional) – The maximum standard deviation of each payoffs samples.
  • noise_distribution (width distribution, optional) – The noise generating function to use. This function must be a valid width noise distribution. A width distribution takes an array of widths and a number of samples, and draws that many samples for each width such that the standard deviation of the samples is equal to the width and the mean is zero. Several default versions are specified in gamegen, and they’re all prefixed with width_. By default, this uses width_gaussian.
gameanalysis.gamegen.gen_num_profiles(game, num, distribution=<function default_distribution>)[source]

Generate profiles given game structure

Parameters:
  • game (RsGame) – Game to generate payoffs for.
  • count (int) – The number of profiles to generate.
  • distribution ((shape) -> ndarray, optional) – Distribution function to draw payoffs from.
gameanalysis.gamegen.gen_profiles(game, prob=1.0, distribution=<function default_distribution>)[source]

Generate profiles given game structure

Parameters:
  • game (RsGame) – Game to generate payoffs for.
  • prob (float, optional) – The probability to add a profile from the full game.
  • distribution ((shape) -> ndarray, optional) – Distribution function to draw payoffs from.
gameanalysis.gamegen.independent_game(num_role_strats, distribution=<function default_distribution>)[source]

Generate a random independent (asymmetric) game

All payoffs are generated independently from distribution.

Parameters:
  • num_role_strats (int or [int], len == num_role_players) – The number of strategies for each player. If an int, then it’s a one player game.
  • distribution ((shape) -> ndarray (shape)) – The distribution to sample payoffs from. Must take a single shape argument and return an ndarray of iid values with that shape.
gameanalysis.gamegen.keep_num_profiles(game, num)[source]

Keep random profiles from an existing game

Parameters:
  • game (RsGame) – Game to keep profiles from.
  • num (int) – The number of profiles to keep from the game.
gameanalysis.gamegen.keep_profiles(game, keep_prob=0.5)[source]

Keep random profiles from an existing game

Parameters:
  • game (RsGame) – The game to take profiles from.
  • keep_prob (float, optional) – The probability of keeping a profile from the full game.
gameanalysis.gamegen.polymatrix_game(num_players, num_strats, matrix_game=<function independent_game>, players_per_matrix=2)[source]

Creates a polymatrix game using the specified k-player matrix game function.

Each player’s payoff in each profile is a sum over independent games played against each set of opponents. Each k-tuple of players plays an instance of the specified random k-player matrix game.

Parameters:
  • num_players (int) – The number of players.
  • num_strats (int) – The number of strategies per player.
  • matrix_game ((players_per_matrix, num_strats) -> Game, optional) – A function to generate games between sub groups of players.
  • players_per_matrix (int, optional) – The number of players that interact simultaneously.

Notes

The actual roles and strategies of matrix game are ignored.

gameanalysis.gamegen.prisoners_dilemma(distribution=<function default_distribution>)[source]

Return a random prisoners dilemma game

gameanalysis.gamegen.rock_paper_scissors(win=1, loss=-1)[source]

Return an instance of rock paper scissors

gameanalysis.gamegen.sample_profiles(game, num)[source]

Generate unique profiles from a game

Parameters:
  • game (RsGame) – Game to generate random profiles from.
  • num (int) – Number of profiles to sample from the game.
gameanalysis.gamegen.samplegame(players, strats, prob=0.5, min_samples=1, min_width=0, max_width=1, payoff_distribution=<function default_distribution>, noise_distribution=<function width_gaussian>)[source]

Generate a random role symmetric sample game

Parameters:
  • players (int or [int]) – The number of players per role.
  • strats (int or [int]) – The number of strategies per role.
  • prob (float, optional) – The probability of adding another sample above min_samples. These draws are repeated, so 0.5 will add one extra sample in expectation.
  • min_samples (int, optional) – The minimum number of samples to generate for each profile. If 0, the game will potentially be sparse.
  • min_width (float, optional) – The minimum standard deviation for each payoffs samples.
  • max_width (float, optional) – The maximum standard deviation for each payoffs samples.
  • payoff_distribution ((shape) -> ndarray, optional) – The distribution to sample mean payoffs from.
  • noise_distribution (width distribution, optional) – The distribution used to add noise to each payoff. See gen_noise for a description of width distributions.
gameanalysis.gamegen.sparse_game(players, strats, num, distribution=<function default_distribution>)[source]

Generate a random role symmetric game with sparse profiles

Parameters:
  • players (int or [int]) – The number of players per role.
  • strats (int or [int]) – The number of strategies per role.
  • num (int) – The number of profiles to draw payoffs for.
  • distribution ((shape) -> ndarray, optional) – Distribution function to draw payoffs from.
gameanalysis.gamegen.sym_2p2s_game(a, b, c, d, distribution=<function default_distribution>)[source]

Create a symmetric 2-player 2-strategy game of the specified form.

Four payoff values get drawn from U(min_val, max_val), and then are assigned to profiles in order from smallest to largest according to the order parameters as follows:

  s0 s1
s0 a,a b,c
s1 c,b d,d

distribution must accept a size parameter a la numpy distributions.

gameanalysis.gamegen.sym_2p2s_known_eq(eq_prob)[source]

Generate a symmetric 2-player 2-strategy game

This game has a single mixed equilibrium where strategy one is played with probability eq_prob.

gameanalysis.gamegen.travellers_dilemma(players=2, max_value=100)[source]

Return an instance of travellers dilemma

Strategies range from 2 to max_value, thus there will be max_value - 1 strategies.

gameanalysis.gamegen.two_player_zero_sum_game(num_role_strats, distribution=<function default_distribution>)[source]

Generate a two-player, zero-sum game

gameanalysis.gamegen.width_bimodal(widths, num_samples)[source]

Bimodal Gaussian width distribution

Samples come from a uniform mixture between two symmetric Gaussians.

gameanalysis.gamegen.width_gaussian(widths, num_samples)[source]

Gaussian width distribution

Samples come from iid Gaussian distributions.

gameanalysis.gamegen.width_gumbel(widths, num_samples)[source]

Gumbel width distribution

Samples come from iid Gumbel distributions. Distributions are randomly inverted since Gumbels are skewed.

gameanalysis.gamegen.width_uniform(widths, num_samples)[source]

Uniform width distribution

Samples come from iid uniform distributions.