Thursday, July 5, 2018

Using Excel's Matrix Operations for Evolutionary Game Theory

I've been reading John Maynard-Smith's classic book Evolution and the Theory of Games. It reminds me of Syntactic Structures by Chomsky in that it's a very short little book but it takes more effort to really understand it than books that are orders of magnitude larger. One thing I've found that helps me to understand complex topics is to develop some model as I'm reading. I've developed several OWL ontologies as I was reading up on a topic just to help me get clear on various concepts. In this case I started with a wonderful Gnu tool called Octave which is a scaled down (but still very powerful) free version of MatLab and does matrix and linear algebra computations. But as I was working it occurred to me it would be much more re-usable and amenable to "what if" games if I had the info in spreadsheet format rather than in the format that Octave uses. So just for grins I googled "matrix operations in Excel" and was amazed at how well Excel supports matrix operations now (I haven't used Excel in quite a while).

I've developed the following spread sheet: Evolutionary Game Theory in Excel  (Note: you can download the spreadsheet by right clicking and selecting "Save Link As")

So far I've implemented Appendices A, B, and D in Maynard Smith's book. Appendix C is a proof which I don't think can be implemented in a spreadsheet. Appendix A shows how to calculate the payoff between two players when each player has a different payoff matrix. The payoff for player 1 is "P Payoff" and for player 2 is "Q Payoff".  The strategy for player one is the column vector p and for player two the column vector q. So if p = [.3; .6; .1] it means that player 1 plays Hawk 30% of the time, Dove 60% and Retreat 10%. Note I'm using the same notation here as Octave where a ";" means a new column and a "," means another element in the same row. So the Transpose of p (denoted p') would be  [.3, .6, .1].

Appendix B shows how to compute the ESS (which is also a Nash Equilibrium) for a two person game that meets the requirements in the book.  That computation uses the same P Payoff matrix as for Appendix A so the computation is only valid when there are two strategies, i.e., when one strategy is dominated by another and hence can be eliminated. In the case as I've set it up in the spreadsheet Dove dominates Retreat so the formula holds. Note: as I read further in the book I realized that R stands for Retaliate which is quite different from Retreat, however I'm leaving the spreadsheet as is because with R dominated by D the ESS formula is valid. If you change the value of R so that it is no longer dominated (e.g., to make it consistent with Retaliate) the spreadsheet will still give values for the ESS but they won't be valid since that formula only works with two strategy games.

Appendix D (sheet 2, A and B are in sheet 1) shows the fitness W for a player playing a pure strategy. It also shows the mean fitness for the population based on which percent are playing which strategy (again the P Payoff matrix is used). It also computes the fitness for the next iteration of the game for each group playing the particular strategy. Note that when R is dominated by D and you compute the ESS you can play "what if" by setting the values for H and D to be different than the ESS and you will see that in the next round they are converging toward the ESS. E.g., if percentage of H is greater than the ESS and percentage of D is less than the ESS in the next iteration the percentage of H will decrease and the percentage of D will increase. This will of course continue until they reach the ESS at which point it will be stable.

I thought this spreadsheet might be useful for others trying to learn the topic as well as for people who want to start doing actual modeling. The current example has 3 strategies but it would be trivial to expand it to more. I have some ideas on altruism that I want to try out with game theory modeling and I think this spreadsheet is a good first step toward what I will need and I hope it may help others as well. Also, there is always a chance I made some error so that's another reason to post it, if anyone finds any errors please let me know. You can comment below, I usually respond to comments within a day.

No comments:

Post a Comment