Title: | Tools for Calculating Allocations in Game Theory using Exact and Approximated Methods |
---|---|
Description: | The main objective of cooperative games is to allocate a good among the agents involved. This package includes the most well-known allocation rules, i.e., the Shapley value, the Banzhaf value, the egalitarian rule, and the equal surplus division value. In addition, it considers the point of view of a priori unions (situations in which agents can form coalitions). For this purpose, the package includes the Owen value, the Banzhaf-Owen value, and the corresponding extensions of the egalitarian rules. All these values can be calculated exactly or estimated by sampling. |
Authors: | Maria D. Guillen [cre, aut] , Juan Carlos Gonçalves [aut] |
Maintainer: | Maria D. Guillen <[email protected]> |
License: | AGPL (>= 3) |
Version: | 0.1.0 |
Built: | 2025-01-09 06:57:44 UTC |
Source: | CRAN |
Calculate the Banzhaf value
banzhaf( characteristic_func, method = "exact", n_rep = 10000, n_players = 0, replace = FALSE )
banzhaf( characteristic_func, method = "exact", n_rep = 10000, n_players = 0, replace = FALSE )
characteristic_func |
The valued function defined on the subsets of the number of players. |
method |
Method used to calculate the Banzhaf value. Valid methods are:
|
n_rep |
Only used if |
n_players |
Only used if |
replace |
should sampling be with replacement? |
The Banzhaf value for each player
n <- 10 v <- function(coalition) { if (length(coalition) > n/2) { return(1) } else { return(0) } } banzhaf(v, method = "exact", n_players = n) banzhaf(v, method = "appro", n_rep = 4000, n_players = n, replace = TRUE) v<-c(0,0,0,1,2,1,3) banzhaf(v, method = "exact") banzhaf(v, method = "appro", n_rep = 4000, replace = TRUE)
n <- 10 v <- function(coalition) { if (length(coalition) > n/2) { return(1) } else { return(0) } } banzhaf(v, method = "exact", n_players = n) banzhaf(v, method = "appro", n_rep = 4000, n_players = n, replace = TRUE) v<-c(0,0,0,1,2,1,3) banzhaf(v, method = "exact") banzhaf(v, method = "appro", n_rep = 4000, replace = TRUE)
Calculate the approximated Banzhaf Index based on sampling
banzhaf_appro(characteristic_func, n_players, n_rep, replace = TRUE)
banzhaf_appro(characteristic_func, n_players, n_rep, replace = TRUE)
characteristic_func |
The valued function defined on the subsets of the number of players |
n_players |
Only used if |
n_rep |
The number of iterations to perform in the approximated calculation |
replace |
should sampling be with replacement? |
The Banzhaf Index for each player
Calculate the approximated Banzhaf Index based on sampling
banzhaf_appro_func(value_func, n_rep, n_players, replace = TRUE)
banzhaf_appro_func(value_func, n_rep, n_players, replace = TRUE)
value_func |
The valued function defined on the subsets of the number of players |
n_rep |
The number of iterations to perform in the approximated calculation |
n_players |
Only used if |
replace |
should sampling be with replacement? |
The Banzhaf Index for each player
Calculate the approximated Banzhaf Index based on sampling
banzhaf_appro_vector(value_func, n_rep)
banzhaf_appro_vector(value_func, n_rep)
value_func |
The valued function defined on the subsets of the number of players |
n_rep |
The number of iterations to perform in the approximated calculation |
The Banzhaf Index for each player
Calculate the approximated Banzhaf Index
banzhaf_exact(characteristic_func, n_players)
banzhaf_exact(characteristic_func, n_players)
characteristic_func |
The valued function defined on the subsets of the number of players |
n_players |
The number of players in the game. |
The Banzhaf Index for each player
Calculate the Banzhaf-Owen value
banzhaf_owen( characteristic_func, union, method = "exact", n_rep = 10000, n_players = 0, replace = TRUE )
banzhaf_owen( characteristic_func, union, method = "exact", n_rep = 10000, n_players = 0, replace = TRUE )
characteristic_func |
The valued function defined on the subsets of the number of players |
union |
List of vectors indicating the a priori unions between the players |
method |
Method used to calculate the Owen value. Valid methods are:
|
n_rep |
Only used if |
n_players |
Only used if |
replace |
should sampling be with replacement? |
The Banzhaf-Owen value for each player
characteristic_func <- c(0,0,0,0,30,30,40,40,50,50,60,70,80,90,100) union <- list(c(1,3),c(2),c(4)) banzhaf_owen(characteristic_func, union) banzhaf_owen(characteristic_func, union, method = "appro", n_rep = 4000)
characteristic_func <- c(0,0,0,0,30,30,40,40,50,50,60,70,80,90,100) union <- list(c(1,3),c(2),c(4)) banzhaf_owen(characteristic_func, union) banzhaf_owen(characteristic_func, union, method = "appro", n_rep = 4000)
Calculate the approximated Banzhaf-Owen value
banzhaf_owen_appro(characteristic_func, union, n_players, n_rep, replace)
banzhaf_owen_appro(characteristic_func, union, n_players, n_rep, replace)
characteristic_func |
The valued function defined on the subsets of the number of players |
union |
List of vectors indicating the a priori unions between the players |
n_players |
The number of players |
n_rep |
Only used if |
replace |
should sampling be with replacement? |
The Banzhaf-Owen Index for each player
Calculate the approximated Banzhaf-Owen value
banzhaf_owen_exact(characteristic_func, union, n_players)
banzhaf_owen_exact(characteristic_func, union, n_players)
characteristic_func |
The valued function defined on the subsets of the number of players |
union |
List of vectors indicating the a priori unions between the players |
n_players |
The number of players in the game. |
The Banzhaf Index for each player
Create all the possible coalitions given the number of players
coalitions(n_players)
coalitions(n_players)
n_players |
Number of players |
A list containing a data.frame
of the binary representation
of the coalitions and a vector
of the classical representation (as
sets) of the coalitions
Calculate the egalitarian value
egalitarian(characteristic_func, n_players = 0)
egalitarian(characteristic_func, n_players = 0)
characteristic_func |
The valued function defined on the subsets of the number of players |
n_players |
Only used if |
The egalitarian value for each player
n <- 10 v <- function(coalition) { if (length(coalition) > n/2) { return(1) } else { return(0) } } egalitarian(v,n)
n <- 10 v <- function(coalition) { if (length(coalition) > n/2) { return(1) } else { return(0) } } egalitarian(v,n)
Calculate the equal surplus division value
equal_surplus_division(characteristic_func, n_players = 0)
equal_surplus_division(characteristic_func, n_players = 0)
characteristic_func |
The valued function defined on the subsets of the number of players |
n_players |
Only used if |
The equal surplus division value for each player
n <- 10 v <- function(coalition) { if (length(coalition) > n/2) { return(1) } else { return(0) } } equal_surplus_division(v,n)
n <- 10 v <- function(coalition) { if (length(coalition) > n/2) { return(1) } else { return(0) } } equal_surplus_division(v,n)
Calculate the Owen value
owen( characteristic_func, union, method = "exact", n_rep = 10000, n_players = 0 )
owen( characteristic_func, union, method = "exact", n_rep = 10000, n_players = 0 )
characteristic_func |
The valued function defined on the subsets of the number of players. |
union |
List of vectors indicating the a priori unions between the players. |
method |
Method used to calculate the Owen value. Valid methods are:
|
n_rep |
Only used if |
n_players |
The number of players in the game. |
The Owen value for each player.
n <- 10 v <- function(coalition) { if (length(coalition) > n/2) { return(1) } else { return(0) } } u <- lapply(1:(n/2), function(i) c(2*i - 1, 2*i)) owen(v, union = u, method = "appro", n_rep = 4000, n_players = n) characteristic_func <- c(1,1,2,1,2,2,2) union <- list(c(1,2),c(3)) owen(characteristic_func, union) owen(characteristic_func, union, method = "appro", n_rep = 4000)
n <- 10 v <- function(coalition) { if (length(coalition) > n/2) { return(1) } else { return(0) } } u <- lapply(1:(n/2), function(i) c(2*i - 1, 2*i)) owen(v, union = u, method = "appro", n_rep = 4000, n_players = n) characteristic_func <- c(1,1,2,1,2,2,2) union <- list(c(1,2),c(3)) owen(characteristic_func, union) owen(characteristic_func, union, method = "appro", n_rep = 4000)
Calculate the approximated Owen value based on sampling
owen_appro(characteristic_func, union, n_players, n_rep)
owen_appro(characteristic_func, union, n_players, n_rep)
characteristic_func |
The valued function defined on the subsets of the number of players |
union |
List of vectors indicating the a priori unions between the players |
n_players |
The number of players |
n_rep |
The number of iterations to perform in the approximated calculation |
The Owen value for each player
Calculate the exact Owen
owen_exact(characteristic_func, union, n_players = NULL)
owen_exact(characteristic_func, union, n_players = NULL)
characteristic_func |
The valued function defined on the subsets of the number of players |
union |
List of vectors indicating the a priori unions between the players |
n_players |
The number of players |
The Owen value for each player
Given a permutation 0 of players and a player i, calculate the set of predecessors of the player i in the order 0
predecessor(permutation, player, include_player = FALSE)
predecessor(permutation, player, include_player = FALSE)
permutation |
A permutation of the players |
player |
Number of the player i |
include_player |
Whether the player i is included as predecessor of itself or not |
The set of predecessors of the player i in the order 0
Calculate the Shapley value
shapley(characteristic_func, method = "exact", n_rep = 10000, n_players = 0)
shapley(characteristic_func, method = "exact", n_rep = 10000, n_players = 0)
characteristic_func |
The valued function defined on the subsets of the number of players. |
method |
Method used to calculate the Shapley value. Valid methods are:
|
n_rep |
Only used if |
n_players |
Only used if |
The Shapley value for each player.
n <- 3 v <- c(1,1,2,1,2,2,2) shapley(v, method = "exact") shapley(v, method = "appro", n_rep = 4000)
n <- 3 v <- c(1,1,2,1,2,2,2) shapley(v, method = "exact") shapley(v, method = "appro", n_rep = 4000)
Calculate the approximated Shapley value based on sampling
shapley_appro(characteristic_func, n_players, n_rep)
shapley_appro(characteristic_func, n_players, n_rep)
characteristic_func |
The valued function defined on the subsets of the number of players |
n_players |
The number of players |
n_rep |
The number of iterations to perform in the approximated calculation |
The Shapley value for each player
Calculate the exact Shapley value
shapley_exact(characteristic_func, n_players)
shapley_exact(characteristic_func, n_players)
characteristic_func |
The valued function defined on the subsets of the number of players |
n_players |
The number of players |
The Shapley value for each player