Shapley value (fast)

Calculates Shapley value
285 Downloads
Updated 25 Jan 2017

View License

Any suggestions will be appreciated!
Speed (Intel Core i7, 2.2 GHz, 8 GM RAM, 64-bit)
n = 2: 0.433 ms
n = 3: 0.439 ms
n = 4: 0.542 ms
n = 5: 0.671 ms
n = 6: 0.810 ms
n = 7: 1.032 ms
n = 8: 1.306 ms
Inputs:
v:
(1, 2^n-1)
worth of each coalition
(expected sum of payoffs for the members in a coalition)
originalcoalitions:
(2^n-1, n)
OPTIONAL
if coalitions are not following the order of binary
numbers (see example below)
firstplayer:
string
OPTIONAL
'left' / 'right' (default)
'left', if the first player is denoted by
[1, 0, 0, ..., 0] in originalcoalitions, and right,
if it is denoted by [0, ... 0, 0, 1]
Output:
vector of n elements [value for player_1, player_2,..., player_n]

CONSTRUCTING THE INPUT VECTOR
Binary numbers represent the coalitions.
For example, for n = 3 players,
binary numbers from 1 to 2^n-1: [001, 010, 011, 100, 101, 110, 111]
Coalitions: {1}, {2}, {1, 2}, {3}, {1, 3}, {2, 3}, {1, 2, 3}
So v = [payoff for {1}, payoff for {2}, payoff for {1, 2}, payoff for {3},...]

[player_3, player_2, player_1]
c = [0, 0, 1;
0, 1, 0;
0, 1, 1;
1, 0, 0;
1, 0, 1;
1, 1, 0;
1, 1, 1];
v = [0, 0, 0, 0, 1, 1, 1];
shapley(v)
shapley(v, c, 'right')

In case coalitions are ordered differently:
[player_3, player_2, player_1]
c = [1, 1, 1;
0, 1, 0;
1, 0, 0;
0, 1, 1;
1, 0, 1;
1, 1, 0;
0, 0, 1];
v = [1, 0, 0, 0, 1, 1, 0];
shapley(v, c)
shapley(v, c, 'right')

Suppose that the first player now is on the left hand side:
[player_1, player_2, player_3]
c = [1, 0, 0;
0, 1, 0;
0, 0, 1;
1, 1, 0;
1, 0, 1;
0, 1, 1;
1, 1, 1];
v = [0, 0, 0, 0, 1, 1, 1];
shapley(v, c, 'left')

INTERPRETING RESULTS
The result is a vector containing n elements:
[value for player_1, player_2, player_3] independently of the position of the first player (left/right side) in the coalition matrix

Cite As

G. Czupy (2024). Shapley value (fast) (https://www.mathworks.com/matlabcentral/fileexchange/57735-shapley-value-fast), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2014a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.0.0

Works with previous versions of MATLAB as well.