Module: Enumerable
- Defined in:
- lib/production_log/analyzer.rb
Instance Method Summary collapse
-
#average ⇒ Object
Average of all the elements of the Enumerable.
-
#sample_variance ⇒ Object
Sample variance of all the elements of the Enumerable.
-
#standard_deviation ⇒ Object
Standard deviation of all the elements of the Enumerable.
-
#sum ⇒ Object
Sum of all the elements of the Enumerable.
Instance Method Details
#average ⇒ Object
Average of all the elements of the Enumerable
The Enumerable must respond to #length
19 20 21 |
# File 'lib/production_log/analyzer.rb', line 19 def average return self.sum / self.length.to_f end |
#sample_variance ⇒ Object
Sample variance of all the elements of the Enumerable
The Enumerable must respond to #length
28 29 30 31 32 |
# File 'lib/production_log/analyzer.rb', line 28 def sample_variance avg = self.average sum = self.inject(0) { |acc, i| acc + (i - avg) ** 2 } return (1 / self.length.to_f * sum) end |
#standard_deviation ⇒ Object
Standard deviation of all the elements of the Enumerable
The Enumerable must respond to #length
39 40 41 |
# File 'lib/production_log/analyzer.rb', line 39 def standard_deviation return Math.sqrt(self.sample_variance) end |
#sum ⇒ Object
Sum of all the elements of the Enumerable
10 11 12 |
# File 'lib/production_log/analyzer.rb', line 10 def sum return self.inject(0) { |acc, i| acc + i } end |