block by alexmacy 8592b0852145ea2808be88f673a41a55

Normalizing Clusters

Full Screen

This is an attempt at an algorithm that finds clusters of even quantity. It’s draws from k-means style clustering and Lloyd’s algorithm, but points also get traded among adjacent clusters based on their difference. The 1,000 points are purposely placed unevenly using d3.RandomNormal and the centroids are randomly selected from those points.

The process automatically stops if a cycle’s ending deviation equals zero. Otherwise it continues until the ending deviation stays the same for a few cycles, so that it doesn’t get caught in an infinite loop.

There is no real significance to the number of clusters, but you can play around with that by opening this in Blockbuilder and editing the value for k. Keep in mind that the process takes much longer when k gets higher, because it has to iterate through so many more adjacencies.

The idea for this came from wanting to find a way to draw a voronoi diagram on top of random dots in such a way that each polygon would have the same quantity. That first experiment can be found here. One next step could be to re-draw the borders for the contiguous United States so that they all have equal populations.

index.html