API documentation#

Representation of games#

Game

A game, the fundamental unit of analysis in game theory.

History([iterable])

An immutable sequence of `HistoryTransition`s identifying a node (or an information set/event, via its canonical member) by the path of actions taken to reach it from the root.

TreeLayout(data)

The layout of a game's tree, computed for graphical display.

TreeLayoutCoordinates(level, sublevel, offset)

The layout coordinates of a single node in a game tree, computed for graphical display.

Creating, reading, and writing games#

read_gbt(filepath_or_buffer)

Construct a game from its serialised representation in a GBT file.

read_efg(filepath_or_buffer)

Construct a game from its serialised representation in an EFG file.

read_nfg(filepath_or_buffer)

Construct a game from its serialised representation in a NFG file.

read_agg(filepath_or_buffer)

Construct a game from its serialised representation in an AGG file.

read_bagg(filepath_or_buffer)

Construct a game from its serialised representation in a BAGG file.

Game.new_tree([players, title])

Create a new Game consisting of a trivial game tree, with one node, which is both root and terminal.

Game.new_table(dim[, title])

Create a new Game with a strategic representation.

Game.from_arrays(*arrays[, title])

Create a new Game with a strategic representation.

Game.to_arrays(dtype)

Generate the payoff tables for players represented as numpy arrays.

Game.from_dict(payoffs[, title])

Create a new Game with a strategic representation.

Game.to_efg([filepath_or_buffer])

Save the game to an .efg file or return its serialized representation

Game.to_nfg([filepath_or_buffer])

Save the game to a .nfg file or return its serialized representation

Game.to_html([filepath_or_buffer])

Export the game to HTML format.

Game.to_latex([filepath_or_buffer])

Export the game to LaTeX format.

Computing a tree layout for graphical display#

layout_tree(game)

Computes the layout of game's tree for graphical display.

Transforming game trees#

Game.append_move(nodes, player, actions)

Add a move for player at terminal nodes.

Game.append_infoset(nodes, infoset)

Add a move at terminal nodes, joining the information set that the node identified by infoset belongs to.

Game.append_event(nodes, actions)

Add a chance move at terminal nodes, with actions and their probabilities given by actions.

Game.insert_move(node, player, actions)

Insert a move for player prior to the node identified by node, with actions labeled according to actions.

Game.insert_infoset(node, infoset)

Insert a move in the information set or event that the node identified by infoset belongs to, prior to the node identified by node.

Game.insert_event(node, actions)

Insert a chance move prior to the node identified by node, with actions and their probabilities given by actions.

Game.copy_tree(src, dest)

Copy the subtree rooted at the node identified by src to the node identified by dest.

Game.move_tree(src, dest)

Move the subtree rooted at the node identified by src to the node identified by dest.

Game.delete_parent(node)

Delete the parent of the node identified by node.

Game.delete_tree(node)

Truncate the game tree at the node identified by node, deleting the subtree beneath it.

Transforming game information structure#

Game.make_infoset(nodes, player[, label])

Form nodes into a single information set belonging to player.

Game.make_event(nodes, probs[, label])

Form nodes into a single event with distribution probs.

Game.relabel_actions(infoset, labels[, strict])

Simultaneously reassign the labels of actions at the information set or event that the node identified by infoset belongs to.

Game.set_move_actions(infoset, actions[, ...])

Set the actions at the move that the node identified by infoset belongs to, to be actions, matching by label.

Game.set_event_actions(event, probs[, drop, add])

Set the actions at the event that the node identified by event belongs to, to be the keys of probs, in order, with the given probability distribution.

Transforming game components#

Game.relabel_players(labels[, strict])

Simultaneously reassign the labels of the game's players.

Game.set_players(players[, drop, add])

Set the players of the game to be players, matching by label.

Game.relabel_strategies(player, labels[, strict])

Simultaneously reassign the labels of player's strategies.

Game.set_strategies(player, strategies[, ...])

Set the strategies of player to be strategies, matching by label.

Game.make_outcome(location, payoffs, label)

Create an outcome with payoffs and label and attach it at location.

Game.make_outcome_null(location)

Reset the outcome at location to the null outcome.

Game.relabel_outcomes(labels[, strict])

Simultaneously reassign the labels of the game's outcomes.

Game.set_outcome_payoffs(label, payoffs)

Sets the payoff to each player at the outcome labeled label.

Information about the game#

Game.title

Get or set the title of the game.

Game.description

Get or set the description of the game.

Game.is_const_sum

Whether the game is constant sum.

Game.is_tree

Return whether a game has a tree-based representation.

Game.is_perfect_recall

Whether the game is perfect recall.

Game.has_perfect_recall(player)

Returns whether player has perfect recall.

Game.players

The set of players in the game.

Game.min_payoff

The minimum payoff to any player in any play of the game.

Game.max_payoff

The maximum payoff to any player in any play of the game.

Game.get_min_payoff(player)

Returns the smallest payoff for player in any play of the game.

Game.get_max_payoff(player)

Returns the largest payoff for player in any play of the game.

Game.get_infosets(player)

Returns a snapshot of the information sets belonging to the personal player player: the decisions at which that player chooses an action.

Game.get_events()

Returns a snapshot of the chance player's events: the points of exogenous randomness, each with a probability distribution over its actions.

Game.get_strategies(player)

Returns a snapshot of the labels of the strategies belonging to player.

Game.contingencies

An iterator over the contingencies in the game.

Game.get_outcome(location)

Returns the label of the outcome attached at location.

Game.get_outcomes()

Returns the labels of the outcomes in the game.

Game.get_outcome_payoffs(label)

Returns the payoff to each player at the outcome labeled label.

Game.get_payoffs(contingency)

Returns the payoff to each player at a pure-strategy contingency.

Game.get_subgame_roots()

Returns the Histories of the roots of the subgames of the game, in postorder (children before parents).

Game.get_minimal_subgame(history)

Returns the History of the root of the smallest subgame containing the information set or event that the node identified by history belongs to.

Game.get_strategy_unreachable()

Returns the Histories of the nodes that are not reachable by any pure strategy profile.

Player behavior#

Game.mixed_strategy_profile([data, rational])

Create a mixed strategy profile over the game.

Game.random_strategy_profile([denom, gen])

Create a MixedStrategy on the game, with probabilities drawn from the uniform distribution over the set of mixed strategy profiles.

Game.mixed_behavior_profile([data, rational])

Create a mixed behavior profile over the game.

Game.random_behavior_profile([denom, gen])

Create a MixedBehaviorProfile on the game, with probabilities drawn from the uniform distribution over the set of mixed behavior profiles.

Game.strategy_support_profile([strategies])

Create a new StrategySupportProfile on the game.

Game.behavior_support_profile([actions])

Create a new BehaviorSupportProfile on the game.

Representation of strategic behavior#

Computed quantities#

PlayerIndexedVector

A read-only mapping from player label to a computed value, one entry per player in a game.

PlayerIndexedVector.__iter__()

Implement iter(self).

PlayerIndexedVector.__getitem__(key, /)

Return self[key].

StrategyIndexedVector

A read-only mapping from strategy label to a computed value, one entry per strategy belonging to a single player.

StrategyIndexedVector.__iter__()

Implement iter(self).

StrategyIndexedVector.__getitem__(key, /)

Return self[key].

HistoryIndexedVector

A read-only mapping from a node's History to a computed value, one entry per node.

HistoryIndexedVector.__iter__()

Implement iter(self).

HistoryIndexedVector.__getitem__(key, /)

Return self[key].

InfosetIndexedVector

A read-only mapping from an information set or event to a computed value, one entry per information set or event.

InfosetIndexedVector.__iter__()

Implement iter(self).

InfosetIndexedVector.__getitem__(key, /)

Return self[key].

Probability distributions over strategies#

MixedStrategyProfile

Represents a mixed strategy profile over the strategies in a Game.

MixedStrategyProfile.game

The game on which this mixed strategy profile is defined.

MixedStrategyProfile.__iter__

Iterate over the mixed strategies in the profile, one per player.

MixedStrategyProfile.__getitem__

Returns a snapshot of the mixed strategy for the player with label player, as of now; it will not reflect any later changes to this profile.

MixedStrategyProfile.__setitem__

Sets the mixed strategy for the player with label player.

MixedStrategyProfile.set_mixed_strategy(...)

Sets the mixed strategy for the player with label player.

MixedStrategyProfile.payoffs

Returns the expected payoff to each player, if all players play according to the profile.

MixedStrategyProfile.strategy_values

Returns the expected payoff of playing each strategy, conditional on reaching it, if all other players play according to the profile, grouped by player.

MixedStrategyProfile.strategy_regrets

Returns the regret to playing each strategy, if all other players play according to the profile, grouped by player.

MixedStrategyProfile.player_regrets

Returns the regret of each player for playing their mixed strategy, if all other players play according to the profile.

MixedStrategyProfile.max_regret()

Returns the maximum regret of any player.

MixedStrategyProfile.liap_value()

Returns the Lyapunov value (see [McK91]) of the strategy profile.

MixedStrategyProfile.as_behavior()

Creates a mixed behavior profile which is equivalent to this mixed strategy profile.

MixedStrategyProfile.as_float()

Creates a floating-point copy of this mixed strategy profile.

MixedStrategyProfile.normalize()

Create a profile with the same strategy proportions as this one, but normalised so probabilities for each player sum to one.

MixedStrategyProfile.copy()

Creates a copy of the mixed strategy profile.

MixedStrategy

A probability distribution over a player's strategies.

MixedStrategy.__iter__

Iterate over the probabilities assigned to strategies by the mixed strategy.

MixedStrategy.__getitem__

Returns the probability that the strategy with label strategy is played.

PayoffVector

The expected payoff to each player, one entry per player in a game.

PlayerRegretVector

The regret of each player for playing their mixed strategy, one entry per player.

StrategyValueVector

The expected payoff of playing each strategy, conditional on reaching it, for one player's strategies.

StrategyRegretVector

The regret of playing each strategy, for one player's strategies.

StrategyValuesVector

The expected payoff of playing each strategy, conditional on reaching it, grouped by player; each value is a StrategyValueVector for that player's strategies.

StrategyRegretsVector

The regret of playing each strategy, grouped by player; each value is a StrategyRegretVector for that player's strategies.

Probability distributions over behavior#

MixedBehaviorProfile

Represents a mixed behavior profile over the actions in a Game.

MixedBehaviorProfile.game

The game on which this mixed behavior profile is defined.

MixedBehaviorProfile.__iter__

Iterate over the mixed behaviors in the profile, one per player.

MixedBehaviorProfile.__getitem__

Access a component of the mixed behavior profile specified by index.

MixedBehaviorProfile.__setitem__

Sets the mixed action at the information set containing index.

MixedBehaviorProfile.set_mixed_action(index, ...)

Sets the mixed action at the information set containing index.

MixedBehaviorProfile.payoffs

Returns the expected payoff to each player, if all players play according to the profile.

MixedBehaviorProfile.action_values

Returns the expected payoff to the player of playing each action, conditional on reaching its information set, if all players play according to the profile, grouped by information set.

MixedBehaviorProfile.action_regrets

Returns the regret to playing each action, if all other players play according to the profile, grouped by information set.

MixedBehaviorProfile.infoset_values

Returns the expected payoff to the player conditional on reaching each information set, if all players play according to the profile.

MixedBehaviorProfile.infoset_regrets

Returns the regret to the player for playing their mixed action at each information set, if all other players play according to the profile.

MixedBehaviorProfile.history_values

Returns the expected payoff to each player conditional on play reaching each node, if all players play according to the profile, grouped by player.

MixedBehaviorProfile.realiz_probs

Returns the probability with which each node is reached, if all players play according to the profile.

MixedBehaviorProfile.infoset_probs

Returns the probability with which each information set is reached, if all players play according to the profile.

MixedBehaviorProfile.event_probs

Returns the probability with which each chance event is reached, if all players play according to the profile.

MixedBehaviorProfile.beliefs

Returns, for each node, the conditional probability that the node is reached, given that its information set (or, at a chance node, its event) is reached, if all players play according to the profile.

MixedBehaviorProfile.agent_max_regret()

Returns the maximum regret at any information set.

MixedBehaviorProfile.agent_liap_value()

Returns the Lyapunov value (see [McK91]) of the strategy profile.

MixedBehaviorProfile.max_regret()

Returns the maximum regret at any information set.

MixedBehaviorProfile.liap_value()

Returns the Lyapunov value (see [McK91]) of the strategy profile.

MixedBehaviorProfile.as_strategy()

Returns a MixedStrategyProfile which is equivalent to the profile.

MixedBehaviorProfile.as_float()

Creates a floating-point copy of this mixed behavior profile.

MixedBehaviorProfile.normalize()

Create a profile with the same action proportions as this one, but normalised so probabilities for each infoset sum to one.

MixedBehaviorProfile.copy()

Creates a copy of the behavior strategy profile.

MixedBehavior

A set of probability distributions describing a player's behavior.

MixedBehavior.__iter__

Iterate over the mixed actions specified by the mixed behavior.

MixedBehavior.__getitem__

Returns the mixed action at the information set selector resolves to.

MixedAction

A probability distribution over a player's actions at an information set.

MixedAction.__iter__

Iterate over the probabilities assigned to actions by the mixed action.

MixedAction.__getitem__

Returns the probability that the action with label action is played.

InfosetValueVector

The expected payoff to the player conditional on reaching each information set, one entry per information set.

InfosetRegretVector

The regret of playing the mixed action at each information set, one entry per information set.

InfosetProbVector

The probability with which each information set is reached, one entry per information set.

EventProbVector

The probability with which each chance event is reached, one entry per event.

ActionValueVector

The expected payoff of playing each action, conditional on reaching it, for one information set's actions.

ActionRegretVector

The regret of playing each action, for one information set's actions.

ActionValuesVector

The expected payoff of playing each action, conditional on reaching it, grouped by information set; each value is an ActionValueVector for that information set's actions.

ActionRegretsVector

The regret of playing each action, grouped by information set; each value is an ActionValueVector for that information set's actions.

RealizProbVector

The probability with which each node is reached, one entry per node.

BeliefVector

The conditional probability that each node is reached, given that its information set is reached, one entry per node.

HistoryValueVector

The expected payoff to one player conditional on reaching each node, one entry per node.

HistoryValuesVector

The expected payoff to each personal player conditional on reaching each node, grouped by player; each value is a HistoryValueVector for that player.

Representation of supports#

Subsets of strategies#

StrategySupportProfile

A set-like object representing a subset of the strategies in game.

StrategySupportProfile.game

The Game on which the support profile is defined.

StrategySupportProfile.__iter__

Iterate over the strategy supports in the profile, one per player.

StrategySupportProfile.__getitem__

Return a StrategySupport representing the labels of the strategies in the support belonging to the player with label player, as of now; it will not reflect any later changes to this profile.

StrategySupportProfile.__setitem__

Sets the support for the player with label player to exactly the given strategies.

StrategySupportProfile.copy()

Creates a copy of the support profile.

StrategySupportProfile.restrict()

Creates a deep copy of the support profile's game, including only the strategies in the support.

StrategySupportProfile.is_dominated(player, ...)

Returns whether the strategy with label strategy, belonging to the player with label player, is dominated.

StrategySupport

The labels of the strategies for a specified player in a StrategySupportProfile.

StrategySupport.player

StrategySupport.__iter__()

Implement iter(self).

StrategySupport.__contains__(key, /)

Return bool(key in self).

Subsets of actions#

BehaviorSupportProfile

A set-like object representing a subset of the actions in an extensive game.

BehaviorSupportProfile.game

The Game on which the support profile is defined.

BehaviorSupportProfile.__iter__

Iterate over the behavior supports in the profile, one per player.

BehaviorSupportProfile.__getitem__

Access a component of the support profile specified by index.

BehaviorSupportProfile.__setitem__

Sets the support at infoset to exactly the given actions.

BehaviorSupportProfile.copy()

Creates a copy of the support profile.

BehaviorSupportProfile.is_infoset_reachable(infoset)

Returns whether infoset can be reached under this support, i.e. whether there is some path of play consistent with the support that reaches it.

BehaviorSupport

The action supports at the information sets belonging to a specified player in a BehaviorSupportProfile.

BehaviorSupport.player

The label of the player for whom this behavior support is defined.

BehaviorSupport.__iter__

Iterate over the action supports specified by the behavior support, one per information set belonging to the player.

BehaviorSupport.__getitem__

Returns the action support at the information set selector resolves to.

ActionSupport

A set of actions at a specified information set in a BehaviorSupportProfile.

ActionSupport.history

The History of the node that was resolved to identify this information set.

ActionSupport.__iter__()

Implement iter(self).

ActionSupport.__contains__(key, /)

Return bool(key in self).

Computation on supports#

undominated_strategies_solve(profile[, ...])

Return a support profile including only the strategies in profile which are not dominated by another pure strategy.

Computation of Nash equilibria#

enumpure_solve(game[, nash_callback])

Compute all pure-strategy Nash equilibria of game.

enumpure_agent_solve(game[, nash_callback])

Compute all pure-strategy agent Nash equilibria of game.

enummixed_solve(game[, rational, ...])

Compute all mixed-strategy Nash equilibria of a two-player game using the strategic representation.

enumpoly_solve(game[, use_strategic, ...])

:ref:`Compute Nash equilibria by enumerating all support profiles of strategies or actions, and for each support finding all totally-mixed equilibria of the game over that support.

lp_solve(game[, rational, use_strategic, ...])

Compute Nash equilibria of a two-player constant-sum game using linear programming.

lcp_solve(game[, rational, use_strategic, ...])

Compute Nash equilibria of a two-player game using linear complementarity programming.

liap_solve(start[, maxregret, maxiter, ...])

Compute an approximate Nash equilibrium of a game using Lyapunov function minimization.

liap_agent_solve(start[, maxregret, ...])

Compute an approximate agent Nash equilibrium of a game using Lyapunov function minimization.

logit_solve(game[, use_strategic, ...])

Compute a Nash equilibrium of a game using the logit quantal response equilibrium correspondence.

simpdiv_solve(start[, maxregret, refine, ...])

Compute a Nash equilibrium of a game using simplicial subdivision.

ipa_solve(perturbation[, nash_callback, ...])

Compute a Nash equilibrium of a game using iterated polymatrix approximation.

gnm_solve(perturbation[, end_lambda, steps, ...])

Compute Nash equilibria of a game using a global Newton method.

hp_solve(prior[, maxregret, event_callback])

Compute a Nash equilibrium of a game using [HerPee01]

Each of these returns its own result type, documented below:

NashResultBase(*, game, rational, use_strategic)

Common attributes shared by every result of a method which computes Nash equilibria in a game.

EnumPureResult(*, game, rational, ...)

The result of enumerating pure-strategy Nash equilibria (enumpure_solve) or pure-strategy agent Nash equilibria (enumpure_agent_solve).

EnumMixedResult(*, game, rational, ...[, ...])

The result of enummixed_solve.

EnumPolyResult(*, game, rational, ...[, ...])

The result of enumpoly_solve.

LpResult(*, game, rational, use_strategic, ...)

The result of lp_solve.

LcpStrategyResult(*, game, rational, ...)

The result of lcp_solve when solving on the strategic representation.

LcpBehaviorResult(*, game, rational, ...)

The result of lcp_solve when solving on the extensive representation.

LiapResult(*, game, rational, use_strategic, ...)

The result of liap_solve or liap_agent_solve.

LogitResult(*, game, rational, ...)

The result of logit_solve.

SimpdivResult(*, game, rational, ...)

The result of simpdiv_solve.

IPAResult(*, game, rational, use_strategic, ...)

The result of ipa_solve.

GNMResult(*, game, rational, use_strategic, ...)

The result of gnm_solve.

HPResult(*, game, rational, use_strategic, ...)

The result of hp_solve.

Computation of quantal response equilibria#

logit_solve_branch(game[, use_strategic, ...])

logit_solve_lambda(game, lam[, ...])

Compute the QRE(s) at the specified value(s) of lam along the principal branch.

logit_estimate(data[, use_empirical, ...])

Use maximum likelihood estimation to find the logit quantal response equilibrium which best fits empirical frequencies of play.

LogitQREMixedStrategyFitResult(data, method, ...)

The result of fitting a QRE to a given probability distribution over strategies.

LogitQREMixedBehaviorFitResult(data, method, ...)

The result of fitting a QRE to a given probability distribution over actions.

Catalog of games#

load(slug)

Load a game from the package catalog.

generate_openspiel(game_name[, params])

Generate a game using the OpenSpiel library.

generate_gamut(game_class[, params, gamut_jar])

Generate a game using the GAMUT game generator.

gamut_games()

Return a DataFrame listing all 35 GAMUT game classes.

games([n_actions, n_contingencies, ...])

List games available in the package catalog.