davidrichards / kmeans

A KMeans algorithm consistent with the goals of TeguGears and Tegu in general.

This URL has Read+Write access

kmeans /
name age message
file .gitignore Sun Jul 19 10:52:58 -0700 2009 Initial commit to kmeans. [David Richards]
file LICENSE Sun Jul 19 10:52:58 -0700 2009 Initial commit to kmeans. [David Richards]
file README.rdoc Loading commit data...
file Rakefile
file VERSION.yml
directory bin/
directory features/ Sun Jul 19 10:52:58 -0700 2009 Initial commit to kmeans. [David Richards]
file kmeans.gemspec
directory lib/
directory spec/
README.rdoc

KMeans

This is another KMeans implementation. I have a few things that I need to work on:

  • Extract the NodeList information out of the Node to make it more flexible
  • Work on an online version of this code

The basic idea is that I wanted to solve a problem for a client, but I didn’t want to throw the code away. So you get this.

Usage

For now, a very quick demonstration. This creates a one-dimensional node list with number ranges between 1 and 3, 5, and 6 through 10.

  @node_list =  (1..100).map { while (n = rand(10) + 1) == 4 or n == 6; end;  n}
  @kmeans = KMeans::Agent.call(:k => 3, *@node_list)
  puts @kmeans.centroids.inspect
  # => [KMeans::Centroid:[223/26], KMeans::Centroid:[37/17], KMeans::Centroid:[5]]
  @kmeans.centroids.map {|c| c.position.first.to_f}
  # => [8.57692307692308, 2.17647058823529, 5.0]

I’ll put a more interesting example together at another time.

Installation

sudo gem install davidrichards-kmeans

Dependencies

  • TeguGears

COPYRIGHT

Copyright © 2009 David Richards. See LICENSE for details.