K-Means Clustering in J

Perception is essentially the problem of extracting high-level patterns from large amounts of raw-data (from sensors). Correctly recognizing the pattern/shape “dog” in a bitmap is one example of a tricky perceptual task. Note that the symbol “dog/not dog” is much less information than the raw image data. This compression is vital for being able to do quick computations further on in the mental process (“if tiger: run” is a good example of a conditional that depends on very abstract patterns for both tigers and running).

If we imagine that each sensor is a dimension, then we can say that distinguishing between images of dogs and not-dogs is a matter of partitioning a multidimensional input-space into two areas. Perception in animals is (almost?) never guided by top-down labels, though; animals learn *common* patterns/shapes, and then use these patterns in higher-cognition.

Finding common patterns in an input space is the problem of clustering. Consider the following graph:
Animals by Mass and Number of Eyes
We can create 4 clusters which (due to outside knowledge) we can loosely associate with labels we’ve learned previously.

There are many algorithms that will do this sort of clustering task, but perhaps the simplest is K-Means. Yesterday I built a K-Means clusterer in J. It picks initial cluster-centers using K-Means++, and can scale to any number of dimensions. Here is is, chopping a bunch of random points spread over a circle into seven clusters (diamonds indicate the centroids a.k.a. “means”):

Here is the code on GitHub. Everything is public domain. No need to provide credit.

This entry was posted in Code and tagged , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

One Comment

  1. Posted June 18, 2011 at 2:48 am | Permalink

    What does clustering have to do with perception? I admit I’m a bit confused here.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>