gameanalysis.aggfn module

An action graph game with additive function nodes

class gameanalysis.aggfn.AgfnGame(role_names, strat_names, function_names, num_role_players, action_weights, function_inputs, function_table, offsets)[source]

Bases: gameanalysis.rsgame.CompleteGame

Action graph with function nodes game

Action node utilities have additive structure. Function nodes are contribution-independent. Graph is bipartite so that function nodes have in-edges only from action nodes and vise versa.

Parameters:
  • role_names ((str,)) – The name of each role.
  • strat_names (((str,),)) – The name of each strategy per role.
  • num_role_players (ndarray) – The number of players for each role.
  • function_names ((str,)) – The name of each function. Must be sorted, unique, and non-empty.
  • action_weights (ndarray) – Each entry specifies the incoming weight in the action graph for the action node (column). Must have shape (num_functions, num_strats). The action weights for a particular function can’t be all zero, otherwise that function should not exist.
  • function_inputs (ndarray) – Each entry specifies whether the action node (row) is an input to the function node (col). Must have shape (num_strats, num_functions).
  • function_table (ndarray) – Value of arbitrary functions for a number of players activating the function. This can either have shape (num_functions, num_players + 1) or (num_functions,) + tuple(num_role_players + 1). The former treats different roles ass simply different strategy sets, the later treats each nodes inputs as distinct, and so each function maps from the number of inputs from each role.
deviation_payoffs(mix, *, jacobian=False)[source]

Get the deviation payoffs

function_index(func_name)[source]

Get the index of a function by name

get_payoffs(profile)[source]

Returns an array of profile payoffs.

max_strat_payoffs()[source]

Returns an upper bound on the payoffs.

min_strat_payoffs()[source]

Returns a lower bound on the payoffs.

normalize()[source]

Return a normalized AgfnGame

restrict(rest)[source]
to_json()[source]
gameanalysis.aggfn.aggfn(num_role_players, num_role_strats, action_weights, function_inputs, function_table, offsets=None)[source]

Create an Aggfn with default names

Parameters:
  • num_role_players (ndarray) – The number of players per role.
  • num_role_strats (ndarray) – The number of strategies per role.
  • action_weights (ndarray, float) – The action weights.
  • function_inputs (ndarray, bool) – The input mask for each function.
  • function_table (ndarray, float) – The function value relative to number of incoming edges.
  • offsets (ndarray, float, optional) – A constant offset for each strategies payoff. Constant functions are not allowed in the function table as they are clutter, instead, constant functions can be specified here.
gameanalysis.aggfn.aggfn_funcs(num_role_players, num_role_strats, action_weights, function_inputs, functions, offsets=None)[source]

Construct and Aggfn with functions

This is generally less efficient than just constructing the function table using vectorized operations or an existing function table.

Parameters:
  • num_role_players (ndarray) – The number of players per role.
  • num_role_strats (ndarray) – The number of strategies per role.
  • action_weights (ndarray, float) – The action weights.
  • function_inputs (ndarray, bool) – The input mask for each function.
  • functions ([(nr1, nr2, ..) -> float]) – List of functions that maps the player per role activations to a single value. The number of ordered arguments will be inferred from each function.
gameanalysis.aggfn.aggfn_json(json)[source]

Read an Aggfn from json

Json versions of the game will generally have ‘type’: ‘aggfn…’ in them, but as long as the proper fields exist, this will succeed.

gameanalysis.aggfn.aggfn_names(role_names, num_role_players, strat_names, function_names, action_weights, function_inputs, function_table, offsets=None)[source]

Create an Aggfn with specified names

Parameters:
  • role_names ([str]) – The name of each role.
  • num_role_players (ndarray) – The number of players for each role.
  • strat_names ([[str]]) – The name of each strategy for each role.
  • function_names ([str]) – The name of each function.
  • action_weights (ndarray) – The mapping of each function to the strategy weight for a player.
  • function_inpits (ndarray) – The mask indicating which strategies are inputs to which function.
  • offsets (ndarray, float, optional) – A constant offset for each strategies payoff. Constant functions are not allowed in the function table as they are clutter, instead, constant functions can be specified here.
gameanalysis.aggfn.aggfn_names_replace(copy_game, function_names, action_weights, function_inputs, function_table, offsets=None)[source]

Replace an existing game with an Aggfn

Parameters:
  • copy_game (RsGame) – The game to take game structure from.
  • function_names ([str]) – The name of each function.
  • action_weights (ndarray-like) – The weights of each function to player payoffs.
  • function_inputs (ndarray-like) – The mask of each strategy to function.
  • function_table (ndarray-like) – The lookup table of number of incoming edges to function value.
  • offsets (ndarray, float, optional) – A constant offset for each strategies payoff. Constant functions are not allowed in the function table as they are clutter, instead, constant functions can be specified here.
gameanalysis.aggfn.aggfn_replace(copy_game, action_weights, function_inputs, function_table, offsets=None)[source]

Replace an existing game with default function names

Parameters:
  • copy_game (RsGame) – The game to take game structure from.
  • action_weights (ndarray-like) – The weights of each function to player payoffs.
  • function_inputs (ndarray-like) – The mask of each strategy to function.
  • function_table (ndarray-like) – The lookup table of number of incoming edges to function value.
  • offsets (ndarray, float, optional) – A constant offset for each strategies payoff. Constant functions are not allowed in the function table as they are clutter, instead, constant functions can be specified here.