Permalink
Browse files

change inspect so that it returns the ids of the nodes

  • Loading branch information...
1 parent 6e75aff commit 00a80cc8022264a3001b6c1b92f6d4f933826f59 @reddavis committed Nov 30, 2009
Showing with 10 additions and 6 deletions.
  1. +3 −2 README.rdoc
  2. +1 −1 lib/som.rb
  3. +6 −3 spec/som_spec.rb
View
@@ -27,9 +27,10 @@ A pure Ruby implementation of the Self Organising Map machine learning algorithm
a.classify(new_data)
#=> [node_index, [training_data_index_1, training_data_index_2...]]
- # Returns the index of the data you gave it
+ # Returns the id of a node and the
+ # index of the data that belongs to it
a.inspect
- #=> [[1, 0...], [99, 84...], [11, 23...], [2, 6...]]
+ #=> [[0, [1, 0...]], [1, [99, 84...]], [2, [11, 23...]]]
== Options
View
@@ -34,7 +34,7 @@ def train
# Returns an array of buckets containing the index of the training data
def inspect
- nodes.map {|x| x.bucket}
+ nodes.map {|x| [x.id, x.bucket] }
end
# Return training data from the node that is closest to input data
View
@@ -32,12 +32,15 @@
before do
data = [[2,3]]
@a = SOM.new(data, :nodes => 1)
+ @a.train
+ end
+
+ it "should return the id of the nodes" do
+ @a.inspect[0][0].should == 0
end
it "should show the clusters of data indexes" do
- @a.train
- @a.inspect.should be_an(Array)
- @a.inspect.size.should == 1
+ @a.inspect[0][1].should be_an(Array)
end
end

0 comments on commit 00a80cc

Please sign in to comment.