Module: MM::Deltas
- Defined in:
- lib/mm/deltas.rb
Class Method Summary collapse
- .abs(n) ⇒ Object
- .diff(n) ⇒ Object
-
.direction(n) ⇒ Object
Have to scale by 0.5 in order to normalize to a max distance of 1.0.
-
.log_ratio(n) ⇒ Object
Accepts a tuple of anything that Math.log2 can handle.
- .mean(n) ⇒ Object
- .ratio(n) ⇒ Object
-
.tenney(n) ⇒ Object
Accepts a tuple where the quotient responds to #numerator and #denominator.
Class Method Details
.abs(n) ⇒ Object
3 4 5 |
# File 'lib/mm/deltas.rb', line 3 def self.abs n (n[0] - n[1]).abs end |
.diff(n) ⇒ Object
7 8 9 |
# File 'lib/mm/deltas.rb', line 7 def self.diff n n[0] - n[1] end |
.direction(n) ⇒ Object
Have to scale by 0.5 in order to normalize to a max distance of 1.0
16 17 18 |
# File 'lib/mm/deltas.rb', line 16 def self.direction n (n[0] <=> n[1]) * 0.5 end |
.log_ratio(n) ⇒ Object
Accepts a tuple of anything that Math.log2 can handle
26 27 28 |
# File 'lib/mm/deltas.rb', line 26 def self.log_ratio n Math.log2((n[0] / n[1]).to_f).abs end |
.mean(n) ⇒ Object
11 12 13 |
# File 'lib/mm/deltas.rb', line 11 def self.mean n n.inject(0.0, :+) / n.size end |
.ratio(n) ⇒ Object
30 31 32 |
# File 'lib/mm/deltas.rb', line 30 def self.ratio n n[0] / n[1] end |
.tenney(n) ⇒ Object
Accepts a tuple where the quotient responds to #numerator and #denominator
21 22 23 |
# File 'lib/mm/deltas.rb', line 21 def self.tenney n ->(r) { Math.log2(r.numerator * r.denominator) }.call(n[0] / n[1]) end |