What is game theory? In his book “Playing for Real: A Text on Game Theory,” Ken Binmore characterizes it as the study of rational interaction within groups of people. Essentially, whenever you deal with another person, you’re playing a game. I was first introduced to game theory in an introductory microeconomics class. It seemed quite odd and not very intuitive. A couple of years later I found myself in an upper-division game theory course. It was heavy in mathematical notation, graphs, and misery. Unlike the econometrics and computational economics courses where I was introduced to coding (in R and Julia, respectively), I didn’t write a single line of code while studying game theory. In retrospect, the skillset I developed during that course has benefitted me greatly in my data science journey. I decided to re-visit game theory and use it to sharpen my skills in python (and reminisce on the misery).

Let’s start with the classic example: The Prisoners’ Dilemma. Our two players are Julian and Randy. They were both arrested and taken to the police station then separated into different interrogation rooms. The detectives interrogating our players don’t have enough evidence, they need a confession. Here are the strategies and payoffs for our players :

  • If one player confesses while the other stays silent, the snitch goes free while the other player serves 10 years.
  • If both players abide by the code and stay silent, each player gets a year in jail on bogus charges.
  • If both players snitch on each other, they each get nine years. (the district attorney was kind enough to shave a year off due to cooperation).

We’ll call staying silent the dove strategy and snitching the hawk strategy (I took the strategy names and payoffs from Binmore, they were better than the ones in my notes). Let’s use python to create Julian’s payoff matrix:

import numpy as np
import pandas as pd

## create an array with Julian's payoffs
x = np.array([[-1, -10],[0, -9]])
## re-label the rows and columns
jpm=pd.DataFrame(x, columns=['dove', 'hawk'])
jpm.index = ['dove', 'hawk']
jpm
Out[1]: 
      dove  hawk
dove    -1   -10
hawk     0    -9

#game-theory #nash-equilibrium #python #data-science #economics

An Introduction to Game Theory Using Python
2.05 GEEK