Jump to content

User:Lucasvb/An upgrade to the spatial model of voters: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 197:
# Earth-mover's distance (or Wasserstein distance) between two opinion distributions
def wdistanceEMD(dist1,dist2):
return wasserstein_distance(_space,_space,dist1,dist2)
Line 221:
op = opinion(x/L,c)
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))
295

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.