Matrix Games


In [1]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline

In [42]:
def expected_payoff(A, x, y):
    return np.dot(np.dot(x.T, A), y)

def value_of_strategy(A, x):
    return np.min(x.T @ A)


In [45]:
A = np.array([[-1, -1, -1],
              [ 1, -5, -5],
              [ 1,  5, 10]])

x = np.array([0, 0, 1])
y = np.array([1, 0, 0])

print('Expected Payoff to Player R is: {}'.format(expected_payoff(A, x, y)))
print('Value of using Strategy x: {}'.format(value_of_strategy(A, x)))
x.T @ A


Expected Payoff to Player R is: 1
Value of using Strategy x: 1
Out[45]:
array([ 1,  5, 10])


In [21]:
A = np.array([[10, -5,  5],
              [ 1,  1, -1],
              [ 0,-10, -5]])

x = np.array([0, 1, 0])
y = np.array([0, 1, 0])

print('Expected Payoff to Player R is: {}'.format(expected_payoff(A, x, y)))


Expected Payoff to Player R is: 1

In [22]:
A = np.array([[10, -5,  5],
              [ 1,  1, -1],
              [ 0,-10, -5]])

x = np.array([0, 1, 0])
y = np.array([0, 1, 0])
x.T @ A


Out[22]:
array([ 1,  1, -1])

In [39]:
A = np.array([[10, -5,  5],
              [ 1,  1, -1],
              [ 0,-10, -5]])

x = np.array([.2, .6, .2])
y = np.array([0, 0, 1])
# print('Expected Payoff to Player R is: {}'.format(expected_payoff(A, x, y)))
x.T @ A


Out[39]:
array([ 2.6, -2.4, -0.6])

In [43]:
A = np.array([[10, -5,  5],
              [ 1,  1, -1],
              [ 0,-10, -5]])

x = np.array([.2, .6, .2])
y = np.array([0, 0, 1])
# print('Expected Payoff to Player R is: {}'.format(expected_payoff(A, x, y)))
x.T @ A

print('Value of using Strategy x: {}'.format(value_of_strategy(A, x)))


Value of using Strategy x: -2.4

In [44]:
A = np.array([[10, -5,  5],
              [ 1,  1, -1],
              [ 0,-10, -5]])

x = np.array([0, 1, 0])
y = np.array([0, 0, 1])
# print('Expected Payoff to Player R is: {}'.format(expected_payoff(A, x, y)))
x.T @ A

print('Value of using Strategy x: {}'.format(value_of_strategy(A, x)))


Value of using Strategy x: -1

In [ ]: