Module: Nuggets::Array::BoostMixin
- Included in:
- Array
- Defined in:
- lib/nuggets/array/boost_mixin.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#boost(factor) ⇒ Object
call-seq: array.boost(factor) => anArray.
-
#boost_factor(other, &block) ⇒ Object
(also: #boof)
call-seq: array.boost_factor(other_array) => aFloat array.boost_factor(other_array) { |array| … } => aFloat.
Class Method Details
Instance Method Details
#boost(factor) ⇒ Object
call-seq:
array.boost(factor) => anArray
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
71 72 73 |
# File 'lib/nuggets/array/boost_mixin.rb', line 71 def boost(factor) map { |x| x * (1 + factor) } end |
#boost_factor(other, &block) ⇒ Object Also known as: boof
call-seq:
array.boost_factor(other_array) => aFloat
array.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
55 56 57 58 |
# File 'lib/nuggets/array/boost_mixin.rb', line 55 def boost_factor(other, &block) block ||= :mean.to_proc block[other] / block[self] - 1 end |