Plot#

tomsup.plot#

Utility plotting functiona for tomsup

tomsup.plot.choice(df: DataFrame, agent0: str, agent1: str, agent: int = 0, sim: Optional[int] = None, plot_individual_sim: bool = False, show: bool = True)[source]#

plot the score of the agent pair

Parameters:
  • df (pd.DataFrame) – a dataframe resulting from a compete function on an AgentGroup

  • agent0 (str) – agent0 in the agent pair which you seek to plot, by default it plot agent0 performance vs. agent1, to plot agent1 set agent = 1.

  • agent1 (str) – agent1 in the agent pair which you seek to plot

  • agent (int, optional) – Indicate whether you should plot the choice of agent 0 or 1. Defaults to 0.

  • sim – (Optional[int], optional): A specific simulation you wish to plot. Defualts to None indicating it should plot all simulations.

  • plot_individual_sim (bool, optional) – Should individual simulations be plotted. Defaults to false.

  • show (bool, optional) – Should plt.show be run at the end. Defaults to True.

tomsup.plot.plot_heatmap(df: ~pandas.core.frame.DataFrame, aggregate_col: str = 'payoff_agent', aggregate_fun: ~typing.Callable = <function mean>, certainty_fun: ~typing.Union[~typing.Callable, str] = 'mean_ci_95', cmap: str = 'RdBu', na_color: str = 'xkcd:white', xlab: str = '', ylab: str = '', cbarlabel: str = 'Average score of the agent', show: bool = True) None[source]#

plot a heatmap of the agents payoffs

Parameters:
  • df (pd.DataFrame) – An outcome from the compete() function

  • aggregate_col (str, optional) – Column to be aggregated pr agent. Defaults to “payoff_agent”.

  • aggregate_fun (Callable, optional) – Function which to aggregate by, defaults is mean. Defaults to np.mean.

  • certainty_fun (Union[Callable, str], optional) – function should estimate uncertainty or string. Valid string include, mean_ci_X: where X is a float indicating the confidence interval. Defaults to “mean_ci_95”.

  • cmap (str, optional) – The color map. Defaults to “RdBu”.

  • na_color (str, optional) – The nan color. Defaults to “xkcd:white”, e.g. white.

  • xlab (str, optional) – The name on the x axis. Defaults to “”.

  • ylab (str, optional) – The name on the y axis. Defaults to “”.

  • charlabel (str, optional) – The label on the color bar, defaults to “Average score of the Agent.”

  • show (bool, optional) – Should plt.show be run at the end. Defaults to True.

tomsup.plot.plot_history(df: ~pandas.core.frame.DataFrame, agent0: str, agent1: str, state: str, agent: int = 0, fun: ~typing.Callable = <function <lambda>>, ylab: str = '', xlab: str = 'Round', show: bool = True) None[source]#

plot the history of an agent.

Parameters:
  • df (pd.DataFrame) – a dataframe resulting from a compete function on an AgentGroup

  • agent0 (str) – agent0 in the agent pair which you seek to plot, by default it plot agent0 performance vs. agent1, to plot agent1 set agent = 1.

  • agent1 (str) – agent1 in the agent pair which you seek to plot

  • state (str) – The state of the agent you wish to plot.

  • agent (int, optional) – Indicate whether you should plot the score of agent 0 or 1. Defaults to 0.

  • fun (Callable, optional) – A getter function for extracting the state. Defaults to lambdax:x[state].

  • ylab (str, optional) – Label on y-axis. Defaults to “”.

  • xlab (str, optional) – Label on the x-axis. Defaults to “Round”.

  • show (bool, optional) – Should plt.show be run at the end. Defaults to True.

tomsup.plot.plot_op_states(df: DataFrame, agent0: str, agent1: str, state: str, level: int = 0, agent: int = 0, show: bool = True)[source]#

df (ResultsDf): an outcome from the compete() function agent0 (str): an agent name in the agent0 column in the df agent1 (str): an agent name in the agent1 column in the df agent (0|1): An indicate of which agent of agent 0 and 1 you wish to plot the indicated agent must be a theory of mind agent (ToM) state (str): a state of the simulated opponent you wish to plot. level (str): level of the similated opponent you wish to plot. show (bool, optional): Should plt.show be run at the end. Defaults to True.

tomsup.plot.plot_p_k(df: DataFrame, agent0: str, agent1: str, level: int, agent=0, show: bool = True) None[source]#

plot the p_k of a k-ToM agent

Parameters:
  • df (pd.DataFrame) – a dataframe resulting from a compete function on an AgentGroup

  • agent0 (str) – agent0 in the agent pair which you seek to plot, by default it plot agent0 performance vs. agent1, to plot agent1 set agent = 1.

  • agent1 (str) – agent1 in the agent pair which you seek to plot

  • level (int) – The sophistication level to plot

  • agent (int, optional) – Indicate whether you should plot the score of agent 0 or 1. Defaults to 0.

  • show (bool, optional) – Should plt.show be run at the end. Defaults to True.

tomsup.plot.plot_p_op_1(df: DataFrame, agent0: str, agent1: str, agent: int = 0, show: bool = True) None[source]#

plot the p_op_1 of a k-ToM agent

Parameters:
  • df (pd.DataFrame) – a dataframe resulting from a compete function on an AgentGroup

  • agent0 (str) – agent0 in the agent pair which you seek to plot, by default it plot agent0 performance vs. agent1, to plot agent1 set agent = 1.

  • agent1 (str) – agent1 in the agent pair which you seek to plot

  • agent (int, optional) – Indicate whether you should plot the score of agent 0 or 1. Defaults to 0.

  • show (bool, optional) – Should plt.show be run at the end. Defaults to True.

tomsup.plot.plot_p_self(df: DataFrame, agent0: str, agent1: str, agent: int = 0, show: bool = True) None[source]#

plot the p_self of a k-ToM agent

Parameters:
  • df (pd.DataFrame) – a dataframe resulting from a compete function on an AgentGroup

  • agent0 (str) – agent0 in the agent pair which you seek to plot, by default it plot agent0 performance vs. agent1, to plot agent1 set agent = 1.

  • agent1 (str) – agent1 in the agent pair which you seek to plot

  • agent (int, optional) – Indicate whether you should plot the score of agent 0 or 1. Defaults to 0.

  • show (bool, optional) – Should plt.show be run at the end. Defaults to True.

tomsup.plot.score(df: DataFrame, agent0: str, agent1: str, agent: int = 0, show: bool = True)[source]#

plot the score of the agent pair

Parameters:
  • df (pd.DataFrame) – a dataframe resulting from a compete function on an AgentGroup

  • agent0 (str) – agent0 in the agent pair which you seek to plot, by default it plot agent0 performance vs. agent1, to plot agent1 set agent = 1.

  • agent1 (str) – agent1 in the agent pair which you seek to plot

  • agent (int, optional) – Indicate whether you should plot the score of agent 0 or 1. Defaults to 0.

  • show (bool, optional) – Should plt.show be run at the end. Defaults to True.

Examples

>>> agents = ['RB', 'QL', 'WSLS'] # create a list of agents
>>> start_params = [{'bias': 0.7}, {'learning_rate': 0.5}, {}]
>>> # create a list of their starting parameters
>>> # (an empty dictionary {} simply assumes defaults)
>>> # create a group of agents
>>> group = ts.create_agents(agents, start_params)
>>> # round_robin e.g. each agent will play against all other agents
>>> group.set_env(env = 'round_robin')
>>> # make them compete for 4 simulations
>>> penny = ts.PayoffMatrix("penny_competive")
>>> results = group.compete(p_matrix = penny, n_rounds = 20, n_sim = 4)
>>> ts.plot.score(results, agent0 = "RB", agent1 = "QL", agent = 0)