In [80]:
%pylab inline


Welcome to pylab, a matplotlib-based Python environment [backend: module://IPython.zmq.pylab.backend_inline].
For more information, type 'help(pylab)'.

In [98]:
%run ../game_theory.py

Nash equilibria examples of games

One unique Nash equilibrium


In [99]:
a_pd = BimatrixTwoStrategyGame(-1.0,-1.0, -4.0,0.0, 0.0, -4.0, -3.0,-3.0)

In [100]:
a_pd.expected_payoff((1.0, 1.0))


Out[100]:
(-1.0, -1.0)

In [101]:
a_pd.expected_payoff((0.0, 0.0))


Out[101]:
(-3.0, -3.0)

In [102]:
a_pd.plot_payoff_space()


Out[102]:

In [103]:
a_pd.find_unique_equilibrium()


Out[103]:
(0.0, 0.0)

In [116]:
(0.0, 0.0) == (0, 0)


Out[116]:
True

In [104]:
a_pd.find_risk_dominant_equilibrium()


---------------------------------------------------------------------------
NoEquilibriumSelected                     Traceback (most recent call last)
<ipython-input-104-85cdc95e4eba> in <module>()
----> 1 a_pd.find_risk_dominant_equilibrium()

/Users/garcia/Dropbox/git_repositories/game_theory/game_theory.py in find_risk_dominant_equilibrium(self, atol)
    131         candidates = self.find_nash()
    132         if (len(candidates) == 1):
--> 133             raise NoEquilibriumSelected("Risk dominanance does not make sense for game {}, not a coordination game.".format(str(self)))
    134         if (len(candidates) > 3):
    135             raise ValueError("Degenerate case")

NoEquilibriumSelected: Risk dominanance does not make sense for game [(-1.0,-1.0), (-4.0,0.0), 
 (0.0,-4.0), (-3.0,-3.0)], not a coordination game.

Coordination


In [105]:
a_coordination_game = BimatrixTwoStrategyGame(1.0,1.0, 0.0,0.0, 0.0, 0.0, 1.0,1.0)

In [106]:
a_coordination_game.plot_payoff_space()


Out[106]:

In [107]:
candidates = a_coordination_game.find_nash()
for i in candidates:
    print i, np.abs(i[0] - i[1])


(1.0, 1.0) 0.0
(0.0, 0.0) 0.0
(0.5, 0.5) 0.0

In [108]:
a_coordination_game.find_unique_equilibrium()


Out[108]:
(0.5, 0.5)

In [108]:


In [109]:
print a_coordination_game


[(1.0,1.0), (0.0,0.0), 
 (0.0,0.0), (1.0,1.0)]

In [110]:
battel  = BimatrixTwoStrategyGame.battleofthesexes()

In [111]:
print battel


[(2.0,1.0), (0.0,0.0), 
 (0.0,0.0), (1.0,2.0)]

In [112]:
battel.plot_payoff_space()


Out[112]:

In [113]:
battel.find_nash()


Out[113]:
[(1.0, 1.0), (0.0, 0.0), (0.6666666666666666, 0.3333333333333333)]

In [96]:
battel.find_unique_equilibrium()


---------------------------------------------------------------------------
NoEquilibriumSelected                     Traceback (most recent call last)
<ipython-input-96-57081f1dcaa8> in <module>()
----> 1 battel.find_unique_equilibrium()

/Users/garcia/Dropbox/git_repositories/game_theory/game_theory.py in find_unique_equilibrium(self, atol)
    173             except NoEquilibriumSelected:
    174                 #nothing works
--> 175                 raise NoEquilibriumSelected("No focal symmetry or risk dominant equilibrium for game: " + str(self))
    176 
    177     def expected_payoff(self, profile):

NoEquilibriumSelected: No focal symmetry or risk dominant equilibrium for game: [(2.0,1.0), (0.0,0.0), 
 (0.0,0.0), (1.0,2.0)]

In [12]:
pennies = BimatrixTwoStrategyGame.matchingpennies()

In [13]:
pennies.plot_payoff_space()


Out[13]:

In [14]:
pennies.find_nash()


Out[14]:
[(0.5, 0.5)]

In [ ]: