Module: Enumerable
- Defined in:
- lib/indicators/calculations/helper.rb
Overview
Extra methods for mathematical calculations.
Instance Method Summary collapse
Instance Method Details
#mean ⇒ Object
77 78 79 |
# File 'lib/indicators/calculations/helper.rb', line 77 def mean return self.sum / self.length.to_f end |
#sample_variance ⇒ Object
81 82 83 84 85 |
# File 'lib/indicators/calculations/helper.rb', line 81 def sample_variance m = self.mean sum = self.inject(0){|accum, i| accum + (i - m) ** 2 } return sum / (self.length - 1).to_f end |
#standard_deviation ⇒ Object
87 88 89 |
# File 'lib/indicators/calculations/helper.rb', line 87 def standard_deviation return Math.sqrt(self.sample_variance) end |
#sum ⇒ Object
73 74 75 |
# File 'lib/indicators/calculations/helper.rb', line 73 def sum return self.inject(0){|accum, i| accum + i } end |