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
The returned value should be rounded to 2 decimal places.
Similar Kata:
Stats:
Created | May 1, 2015 |
Published | May 1, 2015 |
Warriors Trained | 273 |
Total Skips | 52 |
Total Code Submissions | 556 |
Total Times Completed | 63 |
Python Completions | 45 |
Ruby Completions | 14 |
JavaScript Completions | 19 |
Total Stars | 6 |
% of votes with a positive feedback rating | 67% of 24 |
Total "Very Satisfied" Votes | 10 |
Total "Somewhat Satisfied" Votes | 12 |
Total "Not Satisfied" Votes | 2 |
Total Rank Assessments | 4 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 4 kyu |
Lowest Assessed Rank | 7 kyu |