Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #6140 > unrolled thread
| Started by | Taylor Borcyk <tborcyk1@gmail.com> |
|---|---|
| First post | 2011-11-03 08:50 +0000 |
| Last post | 2011-11-03 08:50 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.soft-sys.math.mathematica
Banzhaf Index Code Taylor Borcyk <tborcyk1@gmail.com> - 2011-11-03 08:50 +0000
| From | Taylor Borcyk <tborcyk1@gmail.com> |
|---|---|
| Date | 2011-11-03 08:50 +0000 |
| Subject | Banzhaf Index Code |
| Message-ID | <j8tkke$f09$1@smc.vnet.net> |
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]]]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web