SOM - Self Organising Map
A pure Ruby implementation of the Self Organising Map machine learning algorithm.
Install
gem sources -a http://gemcutter.org
sudo gem install som
How To Use
require 'rubygems'
require 'som'
data = [[1,2,3], [4,5,6]...]
a = SOM.new(data, :number_of_nodes => 4, :dimensions => 3)
a.train
# To see which class a new piece of data fits into
new_data = [9,8,7]
# An array is returned containing the index of the
# training data that fits into the same class
# The index is the same as the index in the training data e.g:
# data[index_returned_by_SOM (2)] == data[2]
a.classify(new_data)
#=> [node_index, [training_data_index_1, training_data_index_2...]]
# Returns the id of a node and the
# index of the data that belongs to it
a.inspect
#=> [[0, [1, 0...]], [1, [99, 84...]], [2, [11, 23...]]]
You can also save your SOM and load a previously save SOM:
require 'rubygems'
require 'som'
data = [[1,2,3], [4,5,6]...]
a = SOM.new(data, :number_of_nodes => 4,
:dimensions => 3,
:save_to => 'file_path/to/here.som')
a.train # Saves it
b = SOM.load('file_path/to/here.som') # Loads it
b.classify(new_data) # etc...
Options
SOM.new(data, :number_of_nodes => 1, #Default: 5
:learning_rate => 0.7, #Default: 0.5
:radius => 1, #Default: number_of_nodes / 2
:max_iterations => 100, #Default: 100
:verbose => true, #Default: false
:save_to => 'file_path') #Default: nil
Copyright
Copyright © 2009 Red Davis. See LICENSE for details.