misc package

Submodules

misc.evaluate module

A collection of functions for evaluating strategies given a game.

misc.evaluate.evaluate_strategies(Game, strategies, n_iters)[source]

Evaluates a set of strategies on a game.

Parameters
  • Game (Type[ExtensiveFormGame]) – The game class to evaluate the strategies on (e.g., RockPaperScissorGame).

  • strategies (Sequence[dict]) –

    A list of strategies, one strategy per each player in the game. Example:

    player0_strat = {"P0": [1/3, 1/3, 1/3]} # equally likely rock-paper-scissor
    player1_strat = {"P1": [0.4, 0.4, 0.2]}
    strategies = [player0_strat, player1_strat]
    

  • n_iters (int) – The number of iterations to run the game for.

Return type

Sequence[float]

Returns

A list of the average payoffs of each strategy.

misc.trainer module

A class to train players in an extensive form game.

The players are trained over a number of games by calling each player’s update_strategy method after each game. The average payoffs and the average strategies during training are recorded.

class misc.trainer.NormalFormTrainer(Game, players, n_iters=100, display_status_bar=True)[source]

Bases: object

A class to train players in an extensive form game.

Parameters
  • Game (Type[ExtensiveFormGame]) – The game class to train players in.

  • players (Sequence[Player]) – The players to train.

  • n_iters (int) – The number of games to train for.

  • display_status_bar (bool) – Whether to display a status bar during training.

game

The game to train players in.

Type

ExtensiveFormGame

n_iter

The number of games to train for.

Type

int

ep_strategies

The strategies of each player in each game.

Type

dict

ep_payoffs

The payoffs of each player in each game over the course of this trainer instance.

Type

np.ndarray

display_status_bar

Whether to display a status bar during training.

Type

bool

manager

The enlighten manager to display the status bar.

Type

enlighten.Manager

pbar

The enlighten counter to display the status bar.

Type

enlighten.Counter

train(freeze_ls=[])[source]

Train the players for n_iter games using each player’s update_strategy function.

Note

Players in the freeze_ls list will not be trained.

Parameters

freeze_ls (Sequence[Player]) – The players to freeze during training.

Return type

ndarray

Returns

The average payoffs of each player during this train call.

property avg_payoffs: numpy.ndarray

Get the average payoffs of each player over the course of this trainer instance.

Return type

ndarray

Returns

The average payoffs of each player.

property avg_strategies: dict

Get the average strategies of each player.

Return type

dict

Returns

The average strategies of each player.

moving_avg(arr)[source]

Compute the moving average of an array.

Parameters

arr (ndarray) – The array to compute the moving average of.

Return type

ndarray

Returns

The moving average of the array.

make_df(strategies, player_name)[source]

Make a dataframe from a strategy array.

Parameters
  • strategies (ndarray) – The strategies to make a dataframe from.

  • player_name (str) – The name of the player.

Return type

DataFrame

store_strategies(filenames)[source]

Store the episodic strategies and average strategies of each player in json files.

Parameters

filenames (dict) – The names of the json files to store the strategies and average strategies in. Must have key ‘strategy_file’ and ‘avg_strategy_file’ and string values corresponding to the file locations.

Return type

None

store_histories_payoffs(filenames)[source]

Store the episodic histories and payoffs of each player in json files.

Parameters

filenames (dict) – The names of the json files to store the histories and payoffs in. Must have key ‘history_payoffs_file’.

Return type

None

store_data(filenames)[source]

Record data about the training process. :type filenames: dict :param filenames: The names of the json files to store data in.

Return type

None

misc.utils module

A collection of helper functions and classes.

class misc.utils.lessVerboseEnum(value)[source]

Bases: enum.Enum

A less verbose version of the Enum class.

Example:

class Test(lessVerboseEnum):
    TEST=0

print(Test.TEST) # prints "TEST" instead of "Test.TEST"
misc.utils.get_action(action_probs)[source]

Sample an action from an action probability distribution.

Parameters

action_probs (ndarray) – a numpy array of probabilities of length n_actions

Return type

int

Returns

the index of the action sampled with the given probabilities

Module contents