gameanalysis.gamegen module

Module for generating random games

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

Return a random prisoners dilemma game

gameanalysis.gamegen.congestion(num_players, num_facilities, num_required, *, degree=2)[source]

Generate a congestion game

A congestion game is a symmetric game, where there are a given number of facilities, and each player must choose to use some amount of them. The payoff for each facility decreases as more players use it, and a players utility is the sum of the utilities for every facility.

In this formulation, facility payoffs are random polynomials of the number of people using said facility.

Parameters
  • num_players (int > 1) – The number of players.

  • num_facilities (int > 1) – The number of facilities.

  • num_required (0 < int < num_facilities) – The number of required facilities.

  • degree (int > 0, optional) – Degree of payoff polynomials.

gameanalysis.gamegen.covariant_game(num_role_strats, mean_dist=<OrderingMock name='mock.zeros' id='140424101004816'>, var_dist=<OrderingMock name='mock.ones' id='140424097610336'>, 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]

Default distribution for payoffs

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.game_replace(base, prob=1.0, distribution=<function default_distribution>)[source]

Replace a games profiles with random ones

This is identical to gen_profiles, but provides a more common name.

gameanalysis.gamegen.gen_noise(base, 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
  • base (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(base, num, distribution=<function default_distribution>)[source]

Generate profiles given game structure

Parameters
  • base (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(base, prob=1.0, distribution=<function default_distribution>)[source]

Generate profiles given game structure

Parameters
  • base (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(base, num)[source]

Keep random profiles from an existing game

Parameters
  • base (RsGame) – Game to keep profiles from.

  • num (int) – The number of profiles to keep from the game.

gameanalysis.gamegen.keep_profiles(base, keep_prob=0.5)[source]

Keep random profiles from an existing game

Parameters
  • base (RsGame) – The game to take profiles from.

  • keep_prob (float, optional) – The probability of keeping a profile from the full game.

gameanalysis.gamegen.local_effect(num_players, num_strategies, *, edge_prob=0.2)[source]

Generate a local effect game

In a local effect game, strategies are connected by a graph, and utilities are a function of the number of players playing our strategy and the number of players playing a neighboring strategy, hence local effect.

In this formulation, payoffs for others playing our strategy are negative quadratics, and payoffs for playing other strategies are positive cubics.

Parameters
  • num_players (int > 1) – The number of players.

  • num_strategies (int > 1) – The number of strategies.

  • edge_prob (float, optional) – The probability that one strategy affects another.

gameanalysis.gamegen.normal_aggfn(role_players, role_strats, functions, *, input_prob=0.2, weight_prob=0.2)[source]

Generate a random normal AgfnGame

Each function value is an i.i.d Gaussian random walk.

Parameters
  • role_players (int or ndarray) – The number of players per role.

  • role_strats (int or ndarray) – The number of strategies per role.

  • functions (int) – The number of functions to generate.

  • input_prob (float, optional) – The probability of a strategy counting towards a function value.

  • weight_prob (float, optional) – The probability of a function producing non-zero payoffs to a strategy.

gameanalysis.gamegen.poly_aggfn(role_players, role_strats, functions, *, input_prob=0.2, weight_prob=0.2, degree=4)[source]

Generate a random polynomial AgfnGame

Functions are generated by generating degree zeros in [0, num_players] to serve as a polynomial functions.

Parameters
  • role_players (int or ndarray) – The number of players per role.

  • role_strats (int or ndarray) – The number of strategies per role.

  • functions (int) – The number of functions to generate.

  • input_prob (float, optional) – The probability of a strategy counting towards a function value.

  • weight_prob (float, optional) – The probability of a function producing non-zero payoffs to a strategy.

  • degree (int or [float], optional) – Either an integer specifying the degree or a list of the probabilities of degrees starting from one, e.g. 3 is the same as [0, 0, 1].

gameanalysis.gamegen.polymatrix_game(num_players, num_strats, matrix_game=<function independent_game>, players_per_matrix=2)[source]

Creates a polymatrix game

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(base, num)[source]

Generate unique profiles from a game

Parameters
  • base (RsGame) – Game to generate random profiles from.

  • num (int) – Number of profiles to sample from the game.

gameanalysis.gamegen.samplegame(players, strats, *args, **kwargs)[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.

  • **args – The arguments to pass to samplegame_replace.

gameanalysis.gamegen.samplegame_replace(base, 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
  • base (RsGame) – The structure of the game to generate.

  • 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.sine_aggfn(role_players, role_strats, functions, *, input_prob=0.2, weight_prob=0.2, period=4)[source]

Generate a random sinusodial AgfnGame

Functions are generated by generating sinusoids with uniform random shifts and n periods in 0 to num_players, where n is chosen randomle between min_period and max_period.

Parameters
  • role_players (int or ndarray) – The number of players per role.

  • role_strats (int or ndarray) – The number of strategies per role.

  • functions (int) – The number of functions to generate.

  • input_prob (float, optional) – The probability of a strategy counting towards a function value.

  • weight_prob (float, optional) – The probability of a function producing non-zero payoffs to a strategy.

  • period (float, optional) – The loose number of periods in the payoff for each function.

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.