ramo.utils package
Submodules
ramo.utils.agent_loader module
- ramo.utils.agent_loader.create_agents(experiment, u_tpl, num_agents, player_actions, num_objectives, alpha_q=0.01, alpha_theta=0.01, alpha_fq=0.01, alpha_ftheta=0.01, alpha_cq=0.01, alpha_ctheta=0.01, alpha_q_decay=1, alpha_theta_decay=1, alpha_com_decay=1, epsilon=1, epsilon_decay=0.995, min_epsilon=0.1, rng=None)
Create a list of agents.
- Parameters:
experiment (str) – The type of experiment that is run. This is used to determine which agents to create.
u_tpl (Tuple[callable]) – A tuple of utility functions.
num_agents (int) – The number of agents to create.
player_actions (Tuple[int]) – The number of actions per player.
num_objectives (int) – The number of objectives.
alpha_q (float, optional) – The learning rate for Q-values. (Default value = 0.01)
alpha_theta (float, optional) – The learning rate for policy parameters. (Default value = 0.01)
alpha_fq (float, optional) – The learning rate for follower Q-values. (Default value = 0.01)
alpha_ftheta (float, optional) – The learning rate for follower policy parameters. (Default value = 0.01)
alpha_cq (float, optional) – The learning rate for optional commitment Q-values. (Default value = 0.01)
alpha_ctheta (float, optional) – The learning rate for optional commitment policy parameters. (Default value = 0.01)
alpha_q_decay (float, optional) – The decay for the Q-values learning rate. (Default value = 1)
alpha_theta_decay (float, optional) – The decay for the policy parameters learning rate. (Default value = 1)
alpha_com_decay (float, optional) – The decay for the optional commitment strategy learning rate. (Default value = 1)
epsilon (float, optional) – The exploration rate for a Q-learner agent. (Default value = 1)
epsilon_decay (float, optional) – The decay for the exploration rate. (Default value = 0.995)
min_epsilon (float, optional) – The minimum value for the exploration rate. (Default value = 0.1)
rng (Generator, optional) – A random number generator. (Default value = None)
- Returns:
A list of agents.
- Return type:
List[Agent]
- Raises:
Exception – When the requested agent is unknown in the context of the experiment.
ramo.utils.data module
- ramo.utils.data.load_metadata(filepath)
Load metadata from a directory.
- Parameters:
filepath (str) – The path to the metadata file.
- Returns:
A dictionary of metadata.
- Return type:
Dict
- ramo.utils.data.save_logs(logs, path, name, columns=None, index=False, mode='w')
Save the logs to a CSV file.
- Parameters:
logs (List[float]) – A list of records.
path (str) – The path to the directory.
name (str) – The name of the logs file.
columns (str, optional) – The names of the columns.
index (bool, optional) – Whether to save the index as well.
mode (str, optional) – The Python write mode. (Default value = ‘w’)
Returns:
- ramo.utils.data.save_metadata(path, metadata, name='metadata')
Save keyword arguments as metadata in a JSON file.
- Parameters:
path (str) – The path to the directory in which all files will be saved.
metadata (Dict) – A dictionary of metadata to save.
name (str, optional) – The name of the metadata file. (Default value = metadata)
ramo.utils.experiments module
- ramo.utils.experiments.calc_action_probs(actions_dict, player_actions, rollouts)
Calculate empirical action probabilities.
- Parameters:
(Dict[int] (actions_dict) – List[int]): The actions performed by each agent over the rollout period.
player_actions (Tuple[int]) – The number of actions per agent.
rollouts (int) – The number of rollouts.
- Returns:
The action probabilities for each agent.
- Return type:
List[List[float]]
- ramo.utils.experiments.calc_com_probs(commitments, rollouts)
Calculate the empirical commitment probabilities.
- Parameters:
commitments (List[int | ndarray]) – A list of commitments.
rollouts (int) – The number of rollouts.
- Returns:
The commitment probabilities for each agent.
- Return type:
List[float]
- ramo.utils.experiments.calc_returns(payoffs_dict, agents, rollouts)
Calculate the scalarised expected returns for each agent.
- Parameters:
(Dict[int] (payoffs_dict) – List[ndarray]): The vectorial payoffs obtained by the agents.
agents (List[Agent]) – A list of agents.
rollouts (int) – The amount of rollouts that were performed.
- Returns:
A list of scalarised expected returns.
- Return type:
List[float]
- ramo.utils.experiments.create_game_path(content, experiment, game, parent_dir=None, mkdir=True)
Create a new directory based on the given parameters.
- Parameters:
content (str) – The type of content this directory will hold. Most often this is either ‘data’ or ‘plots’.
experiment (str) – The name of the experiment that is being performed.
game (str) – The game that is experimented on.
parent_dir (str, optional) – Parent directory for data and plots. (Default value = None)
mkdir (bool, optional) – Whether to create the directory. (Default value = True)
- Returns:
The path that was created.
- Return type:
str
- ramo.utils.experiments.get_payoffs(actions, payoff_matrices)
Get the payoffs from the payoff matrices from the selected actions.
- Parameters:
actions (List[int]) – The actions taken by each player.
payoff_matrices (List[ndarray]) – A list of payoff matrices.
- Returns:
A list of received payoffs.
- Return type:
List[ndarray]
ramo.utils.helpers module
- ramo.utils.helpers.array_slice(array, axis, start, end, step=1)
Slice an array across a desired axis.
- Parameters:
array (ndarray) – An input array.
axis (int) – The axis to slice through.
start (int) – The start index of that axis.
end (int) – The end index of that axis.
step (int, optional) – The step size of the slice. (Default value = 1)
- Returns:
A slice across the correct axis.
- Return type:
ndarray