Module: MultiMeasure::MathHelpers
- Defined in:
- lib/multi_measure/math_helpers.rb
Overview
Class Method Summary collapse
Class Method Details
.mean(a) ⇒ Object
8 9 10 |
# File 'lib/multi_measure/math_helpers.rb', line 8 def self.mean(a) sum(a) / a.length.to_f end |
.sample_variance(a) ⇒ Object
12 13 14 15 16 |
# File 'lib/multi_measure/math_helpers.rb', line 12 def self.sample_variance(a) m = mean(a) sum = a.inject(0){ |accum, i| accum + (i - m) ** 2 } sum / (a.length - 1).to_f end |
.standard_deviation(a) ⇒ Object
18 19 20 21 |
# File 'lib/multi_measure/math_helpers.rb', line 18 def self.standard_deviation(a) return 0.0 if a.length < 2 Math.sqrt(sample_variance(a)) end |
.sum(a) ⇒ Object
4 5 6 |
# File 'lib/multi_measure/math_helpers.rb', line 4 def self.sum(a) a.inject(0){ |accum, i| accum + i } end |