Class: Node
- Inherits:
-
Object
- Object
- Node
- Defined in:
- lib/som/node.rb
Instance Attribute Summary collapse
-
#bucket ⇒ Object
readonly
Returns the value of attribute bucket.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
-
#<<(data) ⇒ Object
A bucket is a place to put the data that is closest to it.
-
#distance_from(data_points) ⇒ Object
Euclidean Distance.
-
#initialize(id, number_of_weights) ⇒ Node
constructor
A new instance of Node.
- #update_weight(learning_rate, inputs, neighborhood_function = 1) ⇒ Object
- #weights ⇒ Object
Constructor Details
#initialize(id, number_of_weights) ⇒ Node
Returns a new instance of Node.
5 6 7 8 9 |
# File 'lib/som/node.rb', line 5 def initialize(id, number_of_weights) create_weights(number_of_weights) @id = id @bucket = [] end |
Instance Attribute Details
#bucket ⇒ Object (readonly)
Returns the value of attribute bucket.
3 4 5 |
# File 'lib/som/node.rb', line 3 def bucket @bucket end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/som/node.rb', line 3 def id @id end |
Instance Method Details
#<<(data) ⇒ Object
A bucket is a place to put the data that is closest to it
22 23 24 |
# File 'lib/som/node.rb', line 22 def <<(data) @bucket << data end |
#distance_from(data_points) ⇒ Object
Euclidean Distance
27 28 29 30 31 32 33 |
# File 'lib/som/node.rb', line 27 def distance_from(data_points) distance = 0 data_points.each_with_index do |point, index| distance += (point - weights[index]) ** 2 end Math.sqrt(distance) end |
#update_weight(learning_rate, inputs, neighborhood_function = 1) ⇒ Object
15 16 17 18 19 |
# File 'lib/som/node.rb', line 15 def update_weight(learning_rate, inputs, neighborhood_function=1) weights.each_with_index do |weight, index| @weights[index] += learning_rate * neighborhood_function * (inputs[index] - weight) end end |
#weights ⇒ Object
11 12 13 |
# File 'lib/som/node.rb', line 11 def weights @weights ||= [] end |