SQL Statements to Compute the Shapley Value - Aster Analytics

Teradata AsterĀ® Analytics Foundation User GuideUpdate 2

Product
Aster Analytics
Release Number
7.00.02
Published
September 2017
Language
English (United States)
Last Update
2018-04-17
dita:mapPath
uce1497542673292.ditamap
dita:ditavalPath
AA-notempfilter_pdf_output.ditaval
dita:id
B700-1022
lifecycle
previous
Product Category
Software

Assume that the AddOnePlayer input and output tables have the names InputTable and OutputTable, respectively.

To compute a table that contains the Shapley value of each player:

  1. Create a table that contains the weighted payoff produced by adding a player to each combination. For example:
    CREATE TABLE stratum (PARTITION KEY(player)) AS
    SELECT player,
      (InputTable.value - OutputTable.value) / divisor AS partial_value,
      OutputTable.size AS size
    FROM inputTable INNER JOIN
      OutputTable ON (InputTable.comb = OutputTable.comb2);
  2. Create a table that contains the partial Shapley value produced when each player is added to a combination of a given size. For example:
    CREATE TABLE stratum_avg (PARTITION KEY(player)) AS
    SELECT player, size, SUM(partial_value) AS partial_avg
    FROM stratum GROUP BY player, size;
  3. Create a table that lists the Shapley value for each player. For example:
    CREATE TABLE shapley_values (PARTITION KEY(player)) AS
    SELECT player, SUM(partial_avg) / numberOfPlayers AS shapley_value
    FROM stratum_avg GROUP BY player;

Alternatively, combine the preceding statements into this statement:

CREATE TABLE shapley_values (PARTITION KEY(player)) AS
SELECT player, SUM(partial_avg) / numberOfPlayers AS shapley_value
FROM (
  SELECT player, size, SUM(partial_value) AS partial_avg
  FROM (
    SELECT player,
      (inputTable.value - outputTable.value) / divisor AS partial_value,
      outputTable.size AS size
    FROM inputTable INNER JOIN
      outputTable ON (inputTable.comb=outputTable.comb2)
    ) AS stratum
    GROUP BY player, size
  ) AS stratum_avg
GROUP BY player;

To normalize the Shapley values, so that their sum is 1:

SELECT player, shapley_value / (
  SELECT SUM(shapley_value)
  FROM shapley_values
  ) AS normalized__shapley_values
FROM shapley_values;