module Nuggets::Array::BoostMixin

Public Class Methods

included(base) click to toggle source
# File lib/nuggets/array/boost_mixin.rb, line 33
def self.included(base)
  base.send :include, Nuggets::Array::MeanMixin
end

Public Instance Methods

boof(other, &block)
Alias for: boost_factor
boost(factor) → anArray click to toggle source

Maps each value in array to its “boosted” value according to factor. (Cf. boost_factor)

Example:

a.boost(a.boost_factor(b)).mean == b.mean
# File lib/nuggets/array/boost_mixin.rb, line 71
def boost(factor)
  map { |x| x * (1 + factor) }
end
boost_factor(other_array) → aFloat click to toggle source
boost_factor(other_array) { |array| ... } → aFloat

Calculates the “boost factor” from the series of values in array to the series of values in other_array by means of their arithmetic mean or the value returned from the block given.

Example:

# series of runtime measurements for old version
a = [1.5, 1.6, 1.4]

# series of runtime measurements for new version
b = [0.7, 0.8, 0.8]

# what speedup did we get? => almost 50%
a.boost_factor(b)  #=> -0.48888888888888893
# File lib/nuggets/array/boost_mixin.rb, line 55
def boost_factor(other, &block)
  block ||= :mean.to_proc
  block[other] / block[self] - 1
end
Also aliased as: boof