Class: Vector

Inherits:
Object
  • Object
show all
Defined in:
lib/classifier/extensions/vector.rb

Instance Method Summary collapse

Instance Method Details

#magnitudeObject



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

#normalizeObject



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