module MM::Scaling

Public Class Methods

absolute(pairs) click to toggle source
# 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) click to toggle source

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.

# 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) click to toggle source

Scale to the max across both vector

# File lib/mm/scaling.rb, line 7
def self.none pairs
  pairs
end
relative(pairs) click to toggle source

Scale each vector to its own max

# 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