Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #6140
| From | Taylor Borcyk <tborcyk1@gmail.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Banzhaf Index Code |
| Date | 2011-11-03 08:50 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <j8tkke$f09$1@smc.vnet.net> (permalink) |
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 comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Banzhaf Index Code Taylor Borcyk <tborcyk1@gmail.com> - 2011-11-03 08:50 +0000
csiph-web