module Nuggets::Array::BoostMixin
Public Class Methods
included(base)
click to toggle source
# File lib/nuggets/array/boost_mixin.rb 33 def self.included(base) 34 base.send :include, Nuggets::Array::MeanMixin 35 end
Public Instance Methods
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 71 def boost(factor) 72 map { |x| x * (1 + factor) } 73 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 55 def boost_factor(other, &block) 56 block ||= :mean.to_proc 57 block[other] / block[self] - 1 58 end
Also aliased as: boof