Path: blob/main/latex-templates/templates/economics/game_theory.tex
51 views
unlisted
\documentclass[a4paper, 11pt]{report}1\usepackage[utf8]{inputenc}2\usepackage[T1]{fontenc}3\usepackage{amsmath, amssymb}4\usepackage{graphicx}5\usepackage{siunitx}6\usepackage{booktabs}7\usepackage{xcolor}8\usepackage[makestderr]{pythontex}910\definecolor{nash}{RGB}{46, 204, 113}11\definecolor{player1}{RGB}{52, 152, 219}12\definecolor{player2}{RGB}{231, 76, 60}1314\title{Game Theory:\\15Nash Equilibrium, Mixed Strategies, and Payoff Analysis}16\author{Department of Economics\\Technical Report EC-2024-001}17\date{\today}1819\begin{document}20\maketitle2122\begin{abstract}23This report presents a computational analysis of game theory concepts. We implement Nash equilibrium finding for 2-player games, analyze mixed strategies in zero-sum and non-zero-sum games, visualize payoff matrices, and explore classic games including Prisoner's Dilemma, Battle of the Sexes, and Matching Pennies.24\end{abstract}2526\tableofcontents2728\chapter{Introduction}2930Game theory studies strategic interactions where outcomes depend on choices of multiple decision-makers (players).3132\section{Key Concepts}33\begin{itemize}34\item \textbf{Nash Equilibrium}: No player can improve by unilaterally changing strategy35\item \textbf{Dominant Strategy}: Optimal regardless of opponent's choice36\item \textbf{Mixed Strategy}: Randomizing over pure strategies37\end{itemize}3839\chapter{Two-Player Normal Form Games}4041\section{Payoff Matrix Representation}42For players 1 and 2 with strategies $S_1 = \{s_1^1, ..., s_1^m\}$ and $S_2 = \{s_2^1, ..., s_2^n\}$:43\begin{equation}44\text{Payoffs: } (u_1(s_1^i, s_2^j), u_2(s_1^i, s_2^j))45\end{equation}4647\begin{pycode}48import numpy as np49import matplotlib.pyplot as plt50from scipy.optimize import linprog51plt.rc('text', usetex=True)52plt.rc('font', family='serif')5354np.random.seed(42)5556def find_pure_nash(payoff1, payoff2):57m, n = payoff1.shape58nash = []59for i in range(m):60for j in range(n):61best_resp_1 = np.argmax(payoff1[:, j]) == i62best_resp_2 = np.argmax(payoff2[i, :]) == j63if best_resp_1 and best_resp_2:64nash.append((i, j))65return nash6667def find_mixed_nash_2x2(payoff1, payoff2):68# For 2x2 games69# Player 2's mix makes Player 1 indifferent70a, b = payoff1[0, 0], payoff1[0, 1]71c, d = payoff1[1, 0], payoff1[1, 1]72if (a - b - c + d) != 0:73q = (d - b) / (a - b - c + d)74else:75q = 0.57677# Player 1's mix makes Player 2 indifferent78a, b = payoff2[0, 0], payoff2[1, 0]79c, d = payoff2[0, 1], payoff2[1, 1]80if (a - b - c + d) != 0:81p = (d - c) / (a - b - c + d)82else:83p = 0.58485p = np.clip(p, 0, 1)86q = np.clip(q, 0, 1)87return p, q8889def expected_payoff(p, q, payoff):90return p * q * payoff[0, 0] + p * (1-q) * payoff[0, 1] + \91(1-p) * q * payoff[1, 0] + (1-p) * (1-q) * payoff[1, 1]9293# Classic games94games = {95"Prisoner's Dilemma": {96'payoff1': np.array([[-1, -3], [0, -2]]),97'payoff2': np.array([[-1, 0], [-3, -2]]),98'strategies': ['Cooperate', 'Defect']99},100'Battle of Sexes': {101'payoff1': np.array([[3, 0], [0, 2]]),102'payoff2': np.array([[2, 0], [0, 3]]),103'strategies': ['Opera', 'Football']104},105'Matching Pennies': {106'payoff1': np.array([[1, -1], [-1, 1]]),107'payoff2': np.array([[-1, 1], [1, -1]]),108'strategies': ['Heads', 'Tails']109}110}111\end{pycode}112113\chapter{Classic Games Analysis}114115\section{Prisoner's Dilemma}116117\begin{pycode}118fig, axes = plt.subplots(2, 3, figsize=(14, 8))119120for idx, (name, game) in enumerate(games.items()):121ax = axes[0, idx]122payoff1 = game['payoff1']123payoff2 = game['payoff2']124125# Plot payoff matrix126im = ax.imshow(payoff1, cmap='RdYlGn', aspect='auto')127128# Annotate cells129for i in range(2):130for j in range(2):131text = f'({payoff1[i,j]}, {payoff2[i,j]})'132ax.text(j, i, text, ha='center', va='center', fontsize=10)133134ax.set_xticks([0, 1])135ax.set_yticks([0, 1])136ax.set_xticklabels(game['strategies'])137ax.set_yticklabels(game['strategies'])138ax.set_xlabel('Player 2')139ax.set_ylabel('Player 1')140ax.set_title(name)141142# Find equilibria143pure_nash = find_pure_nash(payoff1, payoff2)144for eq in pure_nash:145rect = plt.Rectangle((eq[1]-0.5, eq[0]-0.5), 1, 1,146fill=False, edgecolor='green', linewidth=3)147ax.add_patch(rect)148149# Best response analysis for Prisoner's Dilemma150pd_payoff1 = games["Prisoner's Dilemma"]['payoff1']151pd_payoff2 = games["Prisoner's Dilemma"]['payoff2']152153ax = axes[1, 0]154p_range = np.linspace(0, 1, 100)155# Player 1's expected payoff vs strategy156for j, s2 in enumerate(['Cooperate', 'Defect']):157eu = p_range * pd_payoff1[0, j] + (1 - p_range) * pd_payoff1[1, j]158ax.plot(p_range, eu, label=f'P2 plays {s2}')159ax.set_xlabel('P1 probability of Cooperate')160ax.set_ylabel('P1 Expected Payoff')161ax.set_title("Prisoner's Dilemma: P1 Payoffs")162ax.legend()163ax.grid(True, alpha=0.3)164165# Battle of Sexes mixed equilibrium166bos_payoff1 = games['Battle of Sexes']['payoff1']167bos_payoff2 = games['Battle of Sexes']['payoff2']168p_mix, q_mix = find_mixed_nash_2x2(bos_payoff1, bos_payoff2)169170ax = axes[1, 1]171p_range = np.linspace(0, 1, 100)172q_range = np.linspace(0, 1, 100)173P, Q = np.meshgrid(p_range, q_range)174EU1 = expected_payoff(P, Q, bos_payoff1)175cs = ax.contourf(P, Q, EU1, levels=20, cmap='viridis')176ax.plot(p_mix, q_mix, 'ro', markersize=10, label='Mixed NE')177ax.scatter([1, 0], [1, 0], color='green', s=100, marker='s', label='Pure NE')178ax.set_xlabel('P1: prob(Opera)')179ax.set_ylabel('P2: prob(Opera)')180ax.set_title('Battle of Sexes: P1 Payoff')181ax.legend()182plt.colorbar(cs, ax=ax)183184# Matching Pennies185mp_payoff1 = games['Matching Pennies']['payoff1']186mp_payoff2 = games['Matching Pennies']['payoff2']187p_mp, q_mp = find_mixed_nash_2x2(mp_payoff1, mp_payoff2)188189ax = axes[1, 2]190EU1 = expected_payoff(P, Q, mp_payoff1)191cs = ax.contourf(P, Q, EU1, levels=20, cmap='RdBu')192ax.plot(p_mp, q_mp, 'ko', markersize=10, label=f'Mixed NE ({p_mp:.1f}, {q_mp:.1f})')193ax.set_xlabel('P1: prob(Heads)')194ax.set_ylabel('P2: prob(Heads)')195ax.set_title('Matching Pennies: P1 Payoff')196ax.legend()197plt.colorbar(cs, ax=ax)198199plt.tight_layout()200plt.savefig('game_theory_analysis.pdf', dpi=150, bbox_inches='tight')201plt.close()202\end{pycode}203204\begin{figure}[htbp]205\centering206\includegraphics[width=0.95\textwidth]{game_theory_analysis.pdf}207\caption{Game theory analysis: payoff matrices (top), equilibrium analysis (bottom).}208\end{figure}209210\chapter{Mixed Strategy Equilibria}211212\section{Computing Mixed Nash Equilibrium}213For a 2x2 game, player 1 mixes to make player 2 indifferent:214\begin{equation}215p \cdot u_2(s_1^1, s_2^1) + (1-p) \cdot u_2(s_1^2, s_2^1) = p \cdot u_2(s_1^1, s_2^2) + (1-p) \cdot u_2(s_1^2, s_2^2)216\end{equation}217218\begin{pycode}219# Compute all equilibria220results = []221for name, game in games.items():222pure = find_pure_nash(game['payoff1'], game['payoff2'])223p, q = find_mixed_nash_2x2(game['payoff1'], game['payoff2'])224225# Expected payoffs at mixed equilibrium226eu1 = expected_payoff(p, q, game['payoff1'])227eu2 = expected_payoff(p, q, game['payoff2'])228229results.append({230'name': name,231'pure': pure,232'mixed_p': p,233'mixed_q': q,234'eu1': eu1,235'eu2': eu2236})237238# Visualize dynamics239fig, axes = plt.subplots(1, 2, figsize=(12, 4))240241# Replicator dynamics for Matching Pennies242ax = axes[0]243dt = 0.01244T = 100245p_hist = [0.6]246q_hist = [0.4]247248for _ in range(int(T/dt)):249p, q = p_hist[-1], q_hist[-1]250251# Fitness calculations252f1_H = q * mp_payoff1[0, 0] + (1-q) * mp_payoff1[0, 1]253f1_T = q * mp_payoff1[1, 0] + (1-q) * mp_payoff1[1, 1]254f1_avg = p * f1_H + (1-p) * f1_T255256f2_H = p * mp_payoff2[0, 0] + (1-p) * mp_payoff2[1, 0]257f2_T = p * mp_payoff2[0, 1] + (1-p) * mp_payoff2[1, 1]258f2_avg = q * f2_H + (1-q) * f2_T259260dp = p * (f1_H - f1_avg) * dt261dq = q * (f2_H - f2_avg) * dt262263p_new = np.clip(p + dp, 0.01, 0.99)264q_new = np.clip(q + dq, 0.01, 0.99)265266p_hist.append(p_new)267q_hist.append(q_new)268269ax.plot(p_hist, q_hist, 'b-', alpha=0.7)270ax.plot(p_hist[0], q_hist[0], 'go', markersize=10, label='Start')271ax.plot(0.5, 0.5, 'ro', markersize=10, label='NE')272ax.set_xlabel('P1: prob(Heads)')273ax.set_ylabel('P2: prob(Heads)')274ax.set_title('Replicator Dynamics: Matching Pennies')275ax.legend()276ax.grid(True, alpha=0.3)277278# Iterated elimination279ax = axes[1]280# Show Cournot duopoly convergence281q1_hist = [10]282q2_hist = [10]283a, b, c = 100, 1, 10 # Demand: P = a - b*Q, cost = c284285for _ in range(20):286# Best response functions287q1_br = (a - c - b * q2_hist[-1]) / (2 * b)288q2_br = (a - c - b * q1_hist[-1]) / (2 * b)289q1_hist.append(max(0, q1_br))290q2_hist.append(max(0, q2_br))291292ax.plot(q1_hist, 'b-o', label='Firm 1')293ax.plot(q2_hist, 'r-s', label='Firm 2')294ax.axhline((a - c) / (3 * b), color='green', linestyle='--', label='NE')295ax.set_xlabel('Iteration')296ax.set_ylabel('Quantity')297ax.set_title('Cournot Duopoly Convergence')298ax.legend()299ax.grid(True, alpha=0.3)300301plt.tight_layout()302plt.savefig('game_dynamics.pdf', dpi=150, bbox_inches='tight')303plt.close()304\end{pycode}305306\begin{figure}[htbp]307\centering308\includegraphics[width=0.95\textwidth]{game_dynamics.pdf}309\caption{Game dynamics: replicator dynamics cycling (left), Cournot convergence (right).}310\end{figure}311312\chapter{Numerical Results}313314\begin{table}[htbp]315\centering316\caption{Nash equilibria for classic games}317\begin{tabular}{@{}lccc@{}}318\toprule319Game & Pure NE & Mixed $(p, q)$ & Expected Payoffs \\320\midrule321\py{results[0]['name']} & \py{str(results[0]['pure'])} & (\py{f"{results[0]['mixed_p']:.2f}"}, \py{f"{results[0]['mixed_q']:.2f}"}) & (\py{f"{results[0]['eu1']:.2f}"}, \py{f"{results[0]['eu2']:.2f}"}) \\322\py{results[1]['name']} & \py{str(results[1]['pure'])} & (\py{f"{results[1]['mixed_p']:.2f}"}, \py{f"{results[1]['mixed_q']:.2f}"}) & (\py{f"{results[1]['eu1']:.2f}"}, \py{f"{results[1]['eu2']:.2f}"}) \\323\py{results[2]['name']} & \py{str(results[2]['pure'])} & (\py{f"{results[2]['mixed_p']:.2f}"}, \py{f"{results[2]['mixed_q']:.2f}"}) & (\py{f"{results[2]['eu1']:.2f}"}, \py{f"{results[2]['eu2']:.2f}"}) \\324\bottomrule325\end{tabular}326\end{table}327328\chapter{Conclusions}329330\begin{enumerate}331\item Prisoner's Dilemma: Dominant strategy leads to Pareto-inferior outcome332\item Battle of Sexes: Multiple equilibria require coordination333\item Matching Pennies: Only mixed strategy equilibrium exists334\item Replicator dynamics may cycle rather than converge335\item Nash equilibrium provides predictions for strategic behavior336\end{enumerate}337338\end{document}339340341