module MM::Deltas

Public Class Methods

abs(n) click to toggle source
# File lib/mm/deltas.rb, line 3
def self.abs n
  (n[0] - n[1]).abs
end
diff(n) click to toggle source
# File lib/mm/deltas.rb, line 7
def self.diff n
  n[0] - n[1]
end
direction(n) click to toggle source

Have to scale by 0.5 in order to normalize to a max distance of 1.0

# File lib/mm/deltas.rb, line 16
def self.direction n
  (n[0] <=> n[1]) * 0.5
end
log_ratio(n) click to toggle source

Accepts a tuple of anything that Math.log2 can handle

# File lib/mm/deltas.rb, line 26
def self.log_ratio n
  Math.log2((n[0] / n[1]).to_f).abs
end
mean(n) click to toggle source
# File lib/mm/deltas.rb, line 11
def self.mean n
  n.inject(0.0, :+) / n.size
end
ratio(n) click to toggle source
# File lib/mm/deltas.rb, line 30
def self.ratio n
  n[0] / n[1]
end
tenney(n) click to toggle source

Accepts a tuple where the quotient responds to numerator and denominator

# File lib/mm/deltas.rb, line 21
def self.tenney n
  ->(r) { Math.log2(r.numerator * r.denominator) }.call(n[0] / n[1])
end