Last active
April 26, 2022 12:37
-
-
Save DominikPeters/e0dbe6069827360cb13896957c10bc53 to your computer and use it in GitHub Desktop.
Compute Nash via Dynamic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def nash(N, A, u, rounds=500): | |
"N is set of voters, A is set of alternatives, u is a utility dictionary" | |
"where u[i,x] >= 0 is the utility of i for x, usually either 0 or 1" | |
p = {x : 1/len(A) for x in A} | |
for _ in range(rounds): | |
q = {x : 0 for x in A} | |
for i in N: | |
util = sum(u[i,x] * p[x] for x in A) | |
for x in A: | |
q[x] += (1/len(N)) * (u[i,x] * p[x]) / util | |
if p == q: | |
return p | |
p = q | |
return p |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For proof that this converges to the optimum Nash distribution, see Theorem 2 here: https://www.sciencedirect.com/science/article/pii/S0304406821001476