Class: SOM
- Inherits:
-
Object
- Object
- SOM
- Defined in:
- lib/som.rb
Instance Method Summary collapse
-
#classify(data) ⇒ Object
Return training data from the node that is closest to input data You are returned an array that look like: [node_id, [training_data_index_1, training_data_index_2…]] The index is the original index of that that was pumped into the SOM during the training process.
-
#global_distance_error ⇒ Object
Taken from AI4R SOM library #107.
-
#initialize(training_data, options = {}) ⇒ SOM
constructor
A new instance of SOM.
-
#inspect ⇒ Object
Returns an array of buckets containing the index of the training data.
- #nodes ⇒ Object
- #train ⇒ Object
Constructor Details
#initialize(training_data, options = {}) ⇒ SOM
Returns a new instance of SOM.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/som.rb', line 5 def initialize(training_data, ={}) @training_data = training_data @dimensions = training_data[0].size @iteration_count = 1 # Options @number_of_nodes = [:nodes] || 5 @learning_rate = [:learning_rate] || 0.5 @radius = [:radius] || @number_of_nodes / 2 @max_iterations = [:max_iterations] || 100 # TODO: Allow a lambda so we can use different neighborhood functions @neighborhood_function = 1 #options[:neighborhood_function] || 1 @verbose = [:verbose] create_nodes(training_data) end |
Instance Method Details
#classify(data) ⇒ Object
Return training data from the node that is closest to input data You are returned an array that look like:
- node_id, [training_data_index_1, training_data_index_2…]
-
The index is the original index of that that was pumped into the SOM during the training process
45 46 47 48 |
# File 'lib/som.rb', line 45 def classify(data) closest_node = find_closest_node(data) [closest_node.id, closest_node.bucket] end |
#global_distance_error ⇒ Object
Taken from AI4R SOM library #107
51 52 53 54 55 |
# File 'lib/som.rb', line 51 def global_distance_error @training_data.inject(0) do |sum, n| sum + find_closest_node_with_distance(n)[1] end end |
#inspect ⇒ Object
Returns an array of buckets containing the index of the training data
36 37 38 |
# File 'lib/som.rb', line 36 def inspect nodes.map {|x| [x.id, x.bucket] } end |
#nodes ⇒ Object
23 24 25 |
# File 'lib/som.rb', line 23 def nodes @nodes ||= [] end |
#train ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/som.rb', line 27 def train while train_it!(@training_data) end # Place the data in the nodes buckets so we can see how # The data has been clustered place_data_into_buckets(@training_data) end |