Chadwick Gambit: Software Tools for Game Theory

API documentation#

Representation of games#

Game

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

Player

A player in a Game.

Outcome

An outcome in a Game.

Node

A node in a Game.

Infoset

An information set in a Game.

Action

A choice available at an Infoset in a Game.

Strategy

A plan of action for a Player in a Game.

Creating, reading, and writing games#

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.from_dict(payoffs[, title])

Create a new Game with a strategic representation.

Game.read_game(filepath)

Construct a game from its serialised representation in a file.

Game.parse_game(text)

Construct a game from its serialised representation in a string

Game.write([format])

Produce a serialization of the game.

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 in information set infoset at terminal nodes.

Game.insert_move(node, player, actions)

Insert a move for player prior to the node node, with actions actions.

Game.insert_infoset(node, infoset)

Insert a move in information set infoset prior to the node node.

Game.copy_tree(src, dest)

Copy the subtree rooted at 'src' to 'dest'.

Game.move_tree(src, dest)

Move the subtree rooted at 'src' to 'dest'.

Game.delete_parent(node)

Delete the parent node of node.

Game.delete_tree(node)

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

Transforming game information structure#

Game.set_player(infoset, player)

Set the player at an information set.

Game.set_infoset(node, infoset)

Place node in the information set infoset.

Game.leave_infoset(node)

Remove this node from its information set.

Game.reveal(infoset, player)

Reveals the move made at infoset to player.

Game.set_chance_probs(infoset, probs)

Set the action probabilities at chance information set infoset.

Transforming game components#

Game.add_player([label])

Add a new player to the game.

Game.add_outcome([payoffs, label])

Add a new outcome to the game.

Game.delete_outcome(outcome)

Delete an outcome from the game.

Game.set_outcome(node, outcome)

Set outcome to be the outcome at node.

Game.add_strategy(player[, label])

Add a new strategy to the set of strategies for player.

Game.delete_strategy(strategy)

Delete strategy from the game.

Information about the game#

Game.title

Get or set the title of the game.

Game.comment

Get or set the comment 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.players

The set of players in the game.

Game.outcomes

The set of outcomes in the game.

Game.min_payoff

The minimum payoff in the game.

Game.max_payoff

The maximum payoff in the game.

Game.strategies

The set of strategies in the game.

Game.root

The root node of the game.

Game.actions

The set of actions available in the game.

Game.infosets

The set of information sets in the game.

Game.nodes([subtree])

Return a list of nodes in the game tree.

Game.contingencies

An iterator over the contingencies in the game.

Player.label

Gets or sets the text label of the player.

Player.number

Returns the number of the player in its game.

Player.game

Gets the Game to which the player belongs.

Player.strategies

Returns the set of strategies belonging to the player.

Player.infosets

Returns the set of information sets at which the player has the decision.

Player.actions

Returns the set of actions available to the player at some information set.

Player.is_chance

Returns whether the player is the chance player.

Player.min_payoff

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

Player.max_payoff

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

Player.strategies

Returns the set of strategies belonging to the player.

Outcome.label

The text label associated with this outcome.

Outcome.game

Returns the game with which this outcome is associated.

Node.label

The text label associated with the node.

Node.game

Gets the Game to which the node belongs.

Node.outcome

Returns the outcome attached to the node.

Node.children

The set of children of this node.

Node.parent

The parent of this node.

Node.is_subgame_root

Returns whether the node is the root of a proper subgame.

Node.is_terminal

Returns whether this is a terminal node of the game.

Node.prior_action

The action which leads to this node.

Node.prior_sibling

The node which is immediately before this one in its parent's children.

Node.next_sibling

The node which is immediately after this one in its parent's children.

Node.infoset

The information set to which this node belongs.

Node.player

The player who makes the decision at this node.

Node.is_successor_of(node)

Returns whether this node is a successor of node.

Infoset.label

Get or set the text label of the information set.

Infoset.game

The Game to which the information set belongs.

Infoset.is_chance

Whether the information set belongs to the chance player.

Infoset.player

The player who has the move at this information set.

Infoset.actions

The set of actions at the information set.

Infoset.members

The set of nodes which are members of the information set.

Infoset.precedes(node)

Return whether this information set precedes node in the game tree.

Action.label

Get or set the text label of the action.

Action.infoset

Get the information set to which the action belongs.

Action.precedes(node)

Returns whether node precedes this action in the extensive game.

Action.prob

Get the probability a chance action is played.

Strategy.label

Get or set the text label associated with the strategy.

Strategy.game

The game to which the strategy belongs.

Strategy.player

The player to which the strategy belongs.

Strategy.number

The number of the strategy.

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.support_profile()

Representation of strategic behavior#

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.mixed_strategies()

Iterate over the mixed strategies in the profile.

MixedStrategyProfile.__iter__

Iterate over the probabilities assigned to strategies by the profile.

MixedStrategyProfile.__getitem__

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

MixedStrategyProfile.__setitem__

Sets a probability or a mixed strategy to value.

MixedStrategyProfile.payoff(player)

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

MixedStrategyProfile.strategy_value(strategy)

Returns the expected payoff to playing the strategy, if all other players play according to the profile.

MixedStrategyProfile.strategy_regret(strategy)

Returns the regret to playing strategy, if all other players play according to the profile.

MixedStrategyProfile.player_regret(player)

Returns the regret of 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.strategy_value_deriv(...)

Returns the derivative of the payoff to playing strategy, with respect to the probability that other is played.

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.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(profile, player)

A probability distribution over a player's strategies.

MixedStrategy.__iter__()

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

MixedStrategy.__getitem__(index)

Returns the probability that the strategy referred to by index is played.

MixedStrategy.__setitem__(index, value)

Sets the probability a strategy is played.

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.mixed_behaviors()

Iterate over the mixed behaviors in the profile.

MixedBehaviorProfile.mixed_actions()

Iterate over the mixed actions specified by the profile.

MixedBehaviorProfile.__iter__

Iterate over the probabilities assigned to actions by the profile.

MixedBehaviorProfile.__getitem__

Access a component of the mixed behavior specified by index.

MixedBehaviorProfile.__setitem__

Sets a probability, mixed agent strategy, or mixed behavior strategy to value.

MixedBehaviorProfile.payoff(player)

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

MixedBehaviorProfile.action_regret(action)

Returns the regret to playing action, if all other players play according to the profile.

MixedBehaviorProfile.action_value(action)

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

MixedBehaviorProfile.infoset_value(infoset)

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

MixedBehaviorProfile.node_value(player, node)

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

MixedBehaviorProfile.realiz_prob(node)

Returns the probability with which a node is reached.

MixedBehaviorProfile.infoset_prob(infoset)

Returns the probability with which an information set is reached.

MixedBehaviorProfile.belief(node)

Returns the conditional probability that a node is reached, given that its information set is reached.

MixedBehaviorProfile.is_defined_at(infoset)

Returns whether the profile has probabilities defined at the 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.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(profile, player)

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

MixedBehavior.mixed_actions()

Iterate over the mixed actions specified by the mixed behavior.

MixedBehavior.__iter__()

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

MixedBehavior.__getitem__(index)

Access a component of the mixed behavior specified by index.

MixedBehavior.__setitem__(index, value)

Sets a component of the mixed behavior to value.

MixedAction(profile, infoset)

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__(index)

Returns the probability that the action referred to by index is played.

MixedAction.__setitem__(index, value)

Sets the probability an action is played.

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#

NashComputationResult(game, method, ...)

Represents the result of a method which computes Nash equilibria in a game.

enumpure_solve(game[, use_strategic])

Compute all pure-strategy Nash equilibria of game.

enummixed_solve(game[, rational, use_lrs])

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

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 approximate Nash equilibria of a game using Lyapunov function minimization.

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

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

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

Compute Nash equilibria of a game using simplicial subdivision.

ipa_solve(perturbation)

Compute Nash equilibria of a game using iterated polymatrix approximation.

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

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

Computation of quantal response equilibria#

fit_empirical(data)

Use maximum likelihood estimation to estimate a quantal response equilibrium using the empirical payoff method.

fit_fixedpoint(data)

Use maximum likelihood estimation to find the logit quantal response equilibrium on the principal branch for a strategic game which best fits empirical frequencies of play.

LogitQREMixedStrategyFitResult(data, method, ...)

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