6 kyu

Calculating Expected Utility

Description:

In this Kata, we will be taking the first step in solving Nash Equilibria of 2 player games by learning to calculate the Expected Utility of a player in a game of Rock Paper Scissors given the Utilities of the game and the Pure/Mixed Strategy of each Player.

Let's first define a few Game Theoretic Definitions:

finite set of actions or choices for player i.

is the set of all possible combinations of actions of all players. Each possible combination of actions is called an action profile.

Probability player i chooses action

a function mapping each action profile to a vector of utilities for each player.

We refer to player i's payoff as and by convention, refers to player i's opponents.

To compute the expected utility of the game for a player, sum over each action profile the product of each player's probability of playing their action in the action profile, times the player's utility for the action profile:

For example, in Rock-Paper-Scissors, one can represent the utility table as an n-dimensional table, where each dimension has rows/columns corresponding to a single player's actions, each table entry contains a vector of utilities (a.k.a, payoffs or rewards) for each player.

The payoff table for Rock-Paper-Scissors is as follows:

 | R   |P   |S
R| 0,0 |-1,1|1,-1 
P|1,-1 | 0,0|-1,1
S|-1,1 |1,-1| 0,0

Which can be expressed in python as follows:

utilities = [[0,-1,1],[1,0,-1],[-1,1,0]]

If we take those utilities, along with an action profile of each player we can calculate the Expected Utility of Rock-Paper-Scissors for player i.

def expected_utility(p0, p1, utilities):
  '''returns expected Utility of player p0'''
  
utilities = [[0,-1,1],[1,0,-1],[-1,1,0]]
p0 = [1,0,0]
p1 = [0,1,0]
  
expected_utility(p0,p1,utilities) == -1
function expectedUtility(p0, p1, utilities):
  '''returns expected Utility of player p0'''
  
utilities = [[0,-1,1],[1,0,-1],[-1,1,0]]
p0 = [1,0,0]
p1 = [0,1,0]
  
expectedUtility(p0,p1,utilities) == -1

The returned value should be rounded to 2 decimal places.

Algorithms

More By Author:

Check out these other kata created by russelljjadams

Stats:

CreatedMay 1, 2015
PublishedMay 1, 2015
Warriors Trained273
Total Skips52
Total Code Submissions556
Total Times Completed63
Python Completions45
Ruby Completions14
JavaScript Completions19
Total Stars6
% of votes with a positive feedback rating67% of 24
Total "Very Satisfied" Votes10
Total "Somewhat Satisfied" Votes12
Total "Not Satisfied" Votes2
Total Rank Assessments4
Average Assessed Rank
5 kyu
Highest Assessed Rank
4 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • russelljjadams Avatar
  • GiacomoSorbi Avatar
  • cliffstamp Avatar
Ad