Module: MM::Scaling

Defined in:
lib/mm/scaling.rb

Class Method Summary collapse

Class Method Details

.absolute(pairs) ⇒ Object



11
12
13
14
# File 'lib/mm/scaling.rb', line 11

def self.absolute pairs
  max = (pairs.map(&:max)).max
  pairs.map {|x| x.map {|y| y.to_f / max}}
end

.get_global(max) ⇒ Object

Note: a bit hacky. But anything starting with “get_” should be considered a meta-scaling method. This method returns a Proc that has a particular scaling value hard-coded into it, for re-use and re-use.



25
26
27
# File 'lib/mm/scaling.rb', line 25

def self.get_global max
  ->(pairs) {pairs.map {|x| x.map {|y| y.to_f / max}}}
end

.none(pairs) ⇒ Object

Scale to the max across both vector



7
8
9
# File 'lib/mm/scaling.rb', line 7

def self.none pairs
  pairs
end

.relative(pairs) ⇒ Object

Scale each vector to its own max



17
18
19
20
# File 'lib/mm/scaling.rb', line 17

def self.relative pairs
  maxes = pairs.map(&:max)
  pairs.zip(maxes).map {|pair, max| pair.map {|x| x.to_f / max}}
end