This extension is a thin wrapper around Jung 2.0.1's k-means clusterer.
You can download it from here.
K-Means clustering is a method for partitioning data points into a specified number of clusters.
Historical note: k-means clustering used to be part of the NetLogo NW extension, but since k-means is not a network specific algorithm, it was moved to a separate extension.
k-means:cluster-by-xy
turtles number-of-clusters max-number-of-iterations convergence-threshold
Clusters turtles into the specified number-of-clusters according to their positions in 2D space. The algorithm will stop when max-number-of-iterations is reached, or when none of the centroids has moved as much as convergence_threshold since the previous iteration.
Reports a list of agentsets, where each agentset represents a cluster.
The following code:
extensions [ k-means ]
to try-k-means
clear-all
ask n-of 3 patches [ sprout 25 [ fd random 10 ] ]
let clusters k-means:cluster-by-xy turtles 3 100 0.1
(foreach clusters (n-of 3 base-colors) [ ask ?1 [ set color ?2 ] ])
show clusters
end
May output:
[(agentset, 20 turtles) (agentset, 31 turtles) (agentset, 24 turtles)]
And result in something like:
Keep in mind that k-means is a randomized algorithm and will not necessarilly give you the same result each time it runs.
Run ./sbt package
to build the extension.
If the build succeeds, k-means.jar
will be created.
The NetLogo K-Means extension is in the public domain. To the extent possible under law, Uri Wilensky has waived all copyright and related or neighboring rights.
Jung is licensed under the BSD license.