A pip library for computing the marginal contribution (Shapley Value) for each client in a Federated Learning environment.
The Shapley Value is a game theory concept that explores how to equitably distribute rewards and costs among members of a coalition. It is extensively used in incentive mechanisms for Federated Learning to fairly distribute rewards to clients based on their contribution to the system.
Let
The marginal contribution of the
Let's see this equation in action, consider a Federated Learning environment with three clients, so
Subset | Client #0 | Client #1 | Client #2 |
---|---|---|---|
40 | 30 | 20 | |
40 | 15 | 35 | |
10 | 60 | 20 | |
5 | 60 | 25 | |
0 | 10 | 80 | |
5 | 5 | 80 | |
100 | 180 | 260 | |
16.67 | 30 | 43.33 |
The arrow signifies the order in which each client joins the coalition. Consider the
first iteration
- Client 0's marginal contribution is given as
$v({0}) = 40$ . - Client 1's marginal contribution is given as
$v({0, 1}) - v({0}) = 30$ . - Client 2's marginal contribution is given as
$v({0, 1, 2}) - v({0, 1}) - v({0}) = 20$ .
The marginal contribution is calculated for each permutation likewise, and the Shapley Value is derived by averaging all of these marginal contributions.
from svfl.svfl import calculate_sv
models = {
"client-id-1" : ModelUpdate(),
"client-id-2" : ModelUpdate(),
"client-id-3" : ModelUpdate(),
}
def evaluate_model(model):
# function to compute evaluation metric, ex: accuracy, precision
return metric
def fed_avg(models):
# function to merge the model updates into one model for evaluation, ex: FedAvg, FedProx
return model
# returns a key value pair with the client identifier and it's respective Shapley Value
contribution_measure = calculate_sv(models, evaluate_model, fed_avg)
- Built-in support for standard averaging methods like FedAvg, & FedProx.
Any feedback/corrections/additions are welcome:
If this was helpful, please leave a star on the github page.