tucoopy.power.banzhaf¶
Banzhaf power index.¶
This module provides the Banzhaf index for simple (0–1) games, as well as an efficient dynamic-programming variant for integer weighted voting games.
banzhaf_index ¶
banzhaf_index(game, *, normalized=True)
Compute the Banzhaf power index for a simple game.
In a simple game (\(v(S) \in \{0,1\}\)), a player \(i\) is critical (or a swing player) in a coalition \(S\) if:
The (raw) Banzhaf value of player \(i\) is the number of coalitions in which \(i\) is critical. The normalized Banzhaf index divides these counts by the total across all players so that the index sums to 1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
game | GameProtocol | A simple game. | required |
normalized | bool | If True, return the normalized Banzhaf index. If False, return the raw Banzhaf value (number of swings scaled by \(2^{-(n-1)}\)). | True |
Returns:
| Type | Description |
|---|---|
list[float] | Banzhaf index for each player. |
Raises:
| Type | Description |
|---|---|
InvalidParameterError | If the game is not a valid simple game. |
Notes
- The Banzhaf index measures criticality across all coalitions, without weighting by coalition size or permutations.
- It differs from the Shapley–Shubik index, which is based on pivotality in permutations.
Examples:
>>> bi = banzhaf_index(g)
>>> len(bi) == g.n_players
True
banzhaf_index_weighted_voting ¶
banzhaf_index_weighted_voting(
weights, quota, *, normalized=True
)
Compute the Banzhaf index for an integer weighted voting game using dynamic programming (without enumerating all \(2^n\) coalitions).
A weighted voting game is defined by weights \(w_1,\ldots,w_n\) and a quota \(q\). A coalition \(S\) is winning if:
A player \(i\) is critical in a coalition if removing \(i\) changes the coalition from winning to losing. This implementation counts how many subsets of the other players have total weight in the pivotal interval \([q-w_i,\, q-1]\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weights | Sequence[int] | Integer player weights. | required |
quota | int | Decision quota. | required |
normalized | bool | If True, normalize the index to sum to 1. | True |
Returns:
| Type | Description |
|---|---|
list[float] | Banzhaf index for each player. |
Notes
- Complexity is pseudo-polynomial in the quota/weight scale.
- Much faster than full coalition enumeration for moderate weights.
- If \(q = 0\) or \(q > \sum_{i=1}^n w_i\), no player is critical and all indices are zero.
Examples:
>>> banzhaf_index_weighted_voting([2, 1, 1], quota=3)
[0.5, 0.25, 0.25]