User:Lucasvb/An upgrade to the spatial model of voters: Difference between revisions
Content added Content deleted
No edit summary |
No edit summary |
||
Line 197: | Line 197: | ||
# Earth-mover's distance (or Wasserstein distance) between two opinion distributions |
# Earth-mover's distance (or Wasserstein distance) between two opinion distributions |
||
def |
def EMD(dist1,dist2): |
||
return wasserstein_distance(_space,_space,dist1,dist2) |
return wasserstein_distance(_space,_space,dist1,dist2) |
||
Line 221: | Line 221: | ||
op = opinion(x/L,c) |
op = opinion(x/L,c) |
||
print("(%+0.03f|%0.03f)" % (x/L,c), diststr(op)) |
print("(%+0.03f|%0.03f)" % (x/L,c), diststr(op)) |
||
# Print a few distances |
|||
for i in range(10): |
|||
b1, b2 = np.random.rand()*2-1, np.random.rand()*2-1 |
|||
i1, i2 = np.random.rand(), np.random.rand() |
|||
o1 = opinion(b1, i1) |
|||
o2 = opinion(b2, i2) |
|||
print( |
|||
"(%+0.03f|%0.03f)" % (b1,i1), diststr(o1), |
|||
"vs", |
|||
diststr(o2), "(%+0.03f|%0.03f)" % (b2,i2), |
|||
"= %0.04f" % EMD(o1,o2)) |