PayoffMatrix#
tomsup.payoffmatrix#
This scripts contains the PayoffMatrix
- class tomsup.payoffmatrix.PayoffMatrix(name: str, predefined: Optional[array] = None)[source]#
Bases:
object
A class of 2 by 2 payoff matrices.
Currently include the following games: The staghunt game: ‘staghunt’, The matching pennies game (coop and competive): ‘penny_competive’, ‘penny_cooperative’, The party dilemma: ‘party’, The Battle of the sexes: ‘sexes’, The chicken game: ‘chicken’, The deadlock: ‘deadlock’, The prisoners dilemma: ‘prisoners_dilemma’.
For custom payoff matrix supply a 2x2x2 numpy array to the predefined argument.
Examples
>>> import tomsup as ts >>> staghunt = ts.PayoffMatrix(name="staghunt") >>> staghunt.payoff(action_agent0=1, action_agent1=1, agent=0) 5 >>> staghunt.payoff(action_agent0=1, action_agent1=0, agent=0) 0 >>> staghunt.payoff(action_agent0=0, action_agent1=1, agent=0) 3 >>> chicken = ts.PayoffMatrix(name="chicken") >>> chicken.payoff(0, 1, 0) -1 >>> dead = ts.PayoffMatrix(name="deadlock") >>> dead.payoff(1, 0, 1) 0 >>> sexes = ts.PayoffMatrix(name="sexes") >>> sexes.payoff(1, 1, 0) 5 >>> custom = ts.PayoffMatrix(name="custom", np.array(([(10, 0), (0, 5)], [(5, 0), (0, 10)])))
- payoff(choice_agent0: int, choice_agent1: int, agent: int = 0) float [source]#
- Parameters:
choice_agent0 (int) – choice of agent 0
choice_agent1 (int) – choice of agent 1
agent (int, optional) – The perspective agent which should get the payoff, either 0 or 1. Defaults to 0.
- Returns:
The payoff of the agent
- Return type:
float