Class: Vector
- Inherits:
-
Object
- Object
- Vector
- Defined in:
- lib/classifier/extensions/vector.rb
Instance Method Summary collapse
Instance Method Details
#magnitude ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/classifier/extensions/vector.rb', line 10 def magnitude sumsqs = 0.0 self.size.times do |i| sumsqs += self[i] ** 2.0 end Math.sqrt(sumsqs) end |
#normalize ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/classifier/extensions/vector.rb', line 17 def normalize nv = [] mag = self.magnitude self.size.times do |i| nv << (self[i] / mag) end Vector[*nv] end |