Trainer

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 imperfecto.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