how can I calculate coalitions for Shapley implementation
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have calcualted risk for a number of instituions. I would like to get there marginal contribution to the overall risk. to do this I need to obtain their Shapley values. The Data is structure as follows;
Firm Expected Losses
A 6103.4
B 12370.25
C 11897.43
D 5199.82
Total sys loss 35570.9
I woul like to get the different coalitions total loss with the exclusion of a single firm and calculate the shapley value. Any suggestion will be high appreciated
0 Commenti
Risposte (1)
Vinayak
il 18 Apr 2024
Hi Charles,
I noticed you have got the losses for each firm as well as the total loss. To calculate the Shapley values, typically you will need to calculate sum of losses for every possible combination excluding one firm at a time.
For instance, for firm A, you will need to calculate the loss from the coalitions {BCD, BC, BD, CD, B, C, D}. Although you can achieve this through a loop, another approach would be using binary numbers from 0 to 2^n -1, which would be 0 to 15 in your case. We can create a matrix using them of size 16x4.
coalitions = dec2bin(0:2^num_firms-1) - '0';
coalitions = coalitions(2:end,:); % skipping all zeros
That way you can calculate the losses for each coalition by simply multiplying the matrices.
coal_losses = coalitions * expected_losses;
Now, for each firm, we can exclude the losses where the firm was included, and we can have the mean to have the shapley values.
for i = 1:num_firms
% Exclude Firm i
coal_losses_i = coal_losses(coalitions(:, i) == 0, :);
% Calculate the marginal contributions
marginal_contributions = total_sys_loss - coal_losses_i;
% Calculate Shapley value for firm i
shapley_values(i) = mean(marginal_contributions);
end
For more details on logical indexing in MATLAB, please refer to the following documentation:
I hope that helps.
0 Commenti
Vedere anche
Categorie
Scopri di più su Statistics and Machine Learning Toolbox in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!