Learn R Programming

TUvalues (version 0.1.0)

banzhaf: Banzhaf value

Description

Calculate the Banzhaf value

Usage

banzhaf(
  characteristic_func,
  method = "exact",
  n_rep = 10000,
  n_players = 0,
  replace = FALSE
)

Value

The Banzhaf value for each player

Arguments

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: exact for the exact calculation or appro for approximated polynomial calculation based on sampling.

n_rep

Only used if method is appro. The number of iterations to perform in the approximated calculation

n_players

Only used if characteristic_func is a function. The number of players in the game.

replace

should sampling be with replacement?

Examples

Run this code
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)

Run the code above in your browser using DataLab