[Date Index]
[Thread Index]
[Author Index]
Banzhaf Index Code
*To*: mathgroup at smc.vnet.net
*Subject*: [mg122607] Banzhaf Index Code
*From*: Taylor Borcyk <tborcyk1 at gmail.com>
*Date*: Thu, 3 Nov 2011 03:45:32 -0500 (EST)
*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com
I found a code that computes Banzhaf Indices and I'm having trouble
interpreting how the code works. Help?
GenBanz [ quota_, weight_] :=
Module[{number = Length[weight], quota1 = quota - 1,
c = Table[ 0, {quota + 1}], i, j,
swings = Table[0, {Length[weight]}], cs, weightT},
c[[1]] = 1;
For[ i = 1, i <= number, i++,
For[j = quota1, j >= weight[[i]], j--,
c[[j + 1]] += c[[j + 1 - weight[[i]] ]] ]];
For[ j = 1, j <= quota1, j++, c[[j + 1]] += c[[j]]];
For[ i = 1, i <= number, i++,
cs = -2; weightT = weight[[i]]; weightSum = quota1 - weightT;
swings[[i]] = c[[quota]];
While[ weightSum >= 0, swings[[i]] += cs * c[[weightSum + 1]];
cs = - cs; weightSum -= weightT ]
];
Return[ swings]
];
Banzhaf[ quota_, weights_] :=
Module[{swings = GenBanz[ quota, weights]},
Return[ 100.0 * swings / Apply[Plus, swings]]]
Prev by Date:
**Re: How to combine 2 list**
Next by Date:
**Re: How to eliminate noises?**
Previous by thread:
**Re: How to combine 2 list**
Next by thread:
**Re: Mathematica 8.0.4 now available**
| |