Skip to content

NetLogo/K-Means-Extension

Repository files navigation

NetLogo K-Means Extension

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.

Usage

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.

Example:

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:

sample clustering

Keep in mind that k-means is a randomized algorithm and will not necessarilly give you the same result each time it runs.

Building

Run ./sbt package to build the extension.

If the build succeeds, k-means.jar will be created.

Terms of Use

CC0

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.

About

An extension adding K-Means clustering to NetLogo

Resources

Stars

Watchers

Forks

Packages

No packages published