Shapley Value Calculator
';
// This is the reference to our CSS style sheet.'
echo '';
echo '';
echo '
Shapley Value Calculator
';
## Pointer to this file
$thisFile = "index.php";
## Decide the Number of Players
$numPlayers = $_POST["numplayers"] ?? 3;
// It sees what number of players the user has selected.
// If it's the first time the user comes to the webpage, the default will be 3
echo "";
## Power set of all players
for($n = 1; $n <= $numPlayers; $n++){
$setOfPlayers[$n] = $n;
}
$powerSet = powerSet($setOfPlayers);
$i = 0;
foreach($powerSet as $set){
$powerSetAsStrings[$i] = setToString($set);
$i++;
}
## Forms for the value of the coalition
$getCoalitionNum = $_POST['CoalitionNum']?? 0;
if($getCoalitionNum == 0){
//That is, if we haven't yet posted anything to ourselves regarding the size of the coalition
echo '';
}else{
echo '';
## Compute the Shapley values
// Now, we have posted our data to ourselves. Note that we're still inside the else{} part of the loop
// All that remains is to do the actual calculations.
$i = 0;
/*
Reminder
numPlayers: number of players
setOfPlayers: Numbers from 1 to n
powerSet: The power set of the above. All the different possible combinations.
getCoalitionNum: The value of coalitions 1 through 2^#
*/
$i = 0;
for($n = 0; $n<$numPlayers; $n++){
$Impact[$n] = 0;
}
foreach($powerSet as $set){
// in_array() function: will be useful. https://www.php.net/manual/es/function.in-array.php
$size = sizeof($set);
if($size !=0){
foreach($set as $player){
$marginalImpact = $getCoalitionNum[$i] - $getCoalitionNum[$i - pow(2,($player-1) ) ];
$Impact[$player-1] += $marginalImpact / choose($size-1,$numPlayers-1);
}
}
$i++;
}
echo '
';
for($n=1; $n <=$numPlayers; $n++){
echo "The Shapley value of player ".$n." is: ".$Impact[$n-1]/$numPlayers."";
}
echo '
';
} // this is the end of the else{} part of the "have we posted any data to ourselves yet" question. Only executes if we indeed have.
## More HTML flavor
//echo '