• Skip to main content
  • Skip to secondary menu
  • Skip to primary sidebar
  • Skip to footer
  • Home
  • Crypto Currency
  • Technology
  • Contact
NEO Share

NEO Share

Sharing The Latest Tech News

  • Home
  • Artificial Intelligence
  • Machine Learning
  • Computers
  • Mobile
  • Crypto Currency

Game Theory, Python, and Dinners

January 29, 2021 by systems

An intuitive introduction to Game Theory and Nash Equilibrium

Prashant Mudgal

Most of 2020 we were inside the house but once the lockdown was relaxed, my friends and I would meet for dinner or for coffee once a month or so. Where to meet was always a proverbial question. Both the other friends were in essential services so they had to go to their offices and I was the one on whom the planning part was ‘bestowed’(which I didn’t enjoy much).

Given the knowledge of their predispositions to cuisines and their favourite areas in the city to hang out, I generally present the choices in a manner that I have to travel the least amount (evil laughter 😈 )

Both of them live in the northern part of the city so meeting in the north is optimum for them. I am somewhere in the central part and prefer that. Also, given that we live in a massive city, there is no dearth of good places to eat in any area of the city but the restaurants serving their favourite cuisines are located in the different parts of the city.

The food wars (Source: Pixabay)

Question to ask : Given the predispositions to places and cuisines on a given day, what would my friends choose as a place to meet for dinner unanimously without contacting each other?

In short, the Game theory is the study of mathematical models that describe the interaction(choosing where to meet)among rational decision-makers(my friends here). Fair enough!

The outcome of the Game — One method of predicting the game’s outcome is by identifying dominant strategies for each player. A dominant strategy is the one that is the best for a given player regardless of the choice of the other player (whatever place suits my friends) — so regardless of what friend #2 does, a dominant strategy for friend #1 is the optimal strategy for friend #1.

The set of dominant strategies (place to meet) chosen by the players (friends) is called the Nash Equilibrium. It is called an equilibrium because neither of the players has anything extra to gain by changing his/her choice.

In simple words, the Nash equilibrium is a law that no one wants to break even in the absence of the police. There is no advantage for individuals to break the law, they won’t gain anything extra. People observing traffic signals and stopping/going according to the colour of the light is one such phenomenon.

We will begin by creating a Payoff/Confusion matrix for the various choices of my friends regarding the place to meet.

Payoff matrix for selecting which part of the city to go to(Image by Author)

Reading the above matrix is quite simple; if friend 1 chooses ‘Northern Part’ and friend 2 chooses ‘Central Part’, then the pay off will be 1, 5(2nd row, 1st column) and it will put friend 2 at an advantageous position compared to friend 1.

We want to find the dominant strategy for each of the friend. In this case, we can observe that for both the friends, the dominant strategy is to reach the central part(first row, first column). If friend 1 changes his strategy from central to northern then his payoff will change from 2 to 1 which isn’t desirable and if friend 2 changes from central to northern then her payoff also changes from 2 to 1.

So, both of the friends choose to come to the Central part of the city. Going to the northern part is an ideal outcome, but the ideal is not necessarily optimal.

Let’s see if we can reach the conclusion above (choosing (2, 2) i.e. both of them choose central part) using python. The library to use is Nashpy and is super easy to install using pip

                  pip install nashpy

Create an individual payoff matrix for each of the friends according to the payoff matrix described above.

Nashpy easily takes the matrices and converts them into a game. I’ll call the game ‘location_war_among_friends’.

It produces a Bi-matrix game with following payoff matrices

These payoff matrices will be used to compute the Nash equilibrium which is quite straightforward in this library.

Nash equilibrium is important as it allows us to gain an initial understanding of emergent behaviour in complex systems. In this case, the equilibrium is reached at:

It consists of two vectors, indicating each friend’s action: friend_1 [1, 0 ] and friend_2 [1, 0]. 1 in the first position for both of them means both will choose ‘Central’ and exemplifying and crystallising our hypothesis above.

You can refer the code which is fairly simple from the GitHub repo here.

We see that despite north being the optimum place, they end up choosing central in accordance to the mighty Game theory and I have to travel the least 😀

It’s merely an example of games we play in our daily lives without realising. In real-world, we always end up making compromises and end up choosing the options that aren’t optimal because of social conditioning and exogenous factors. This is an interesting observation as we see in the world around us e.g. we know that reducing carbon footprints is imperative for all the countries but then too most countries end up choosing a sub-optimal route.

  1. https://nashpy.readthedocs.io/en/latest/tutorial/index.html#creating-a-game
  2. https://simplicable.com/new/game-theory
  3. https://www.sciencedirect.com/topics/neuroscience/game-theory

Further reading

I leafed through the book Game theory 101 by William Spaniel and found it to be an enjoyable read. It is based on the YouTube series by him.

Filed Under: Machine Learning

Primary Sidebar

Stay Ahead: The Latest Tech News and Innovations

Cryptocurrency Market Updates: What’s Happening Now

Emerging Trends in Artificial Intelligence: What to Watch For

Top Cloud Computing Services to Secure Your Data

The Future of Mobile Technology: Recent Advancements and Predictions

Footer

  • Privacy Policy
  • Terms and Conditions

Copyright © 2025 NEO Share

Terms and Conditions - Privacy Policy