Module: Enumerable
- Included in:
- Meta::Pool
- Defined in:
- lib/enumerable.rb
Overview
enumerable.rb - Add Math functionalities to enumerable
ToDo: refactor, it’s not the right approach: used in Bio::Ngs::Cufflinks::Diff.process_de
- Copyright
-
Copyright © 2011
Raoul Bonnal <[email protected]>,
Francesco Strozzi <[email protected]>
- License
-
The Ruby License
Instance Method Summary collapse
-
#average ⇒ Object
average of an array of numbers.
-
#sample_variance ⇒ Object
variance of an array of numbers.
-
#standard_deviation ⇒ Object
standard deviation of an array of numbers.
-
#sum ⇒ Object
sum of an array of numbers.
Instance Method Details
#average ⇒ Object
average of an array of numbers
21 22 23 |
# File 'lib/enumerable.rb', line 21 def average return self.sum/self.length.to_f end |
#sample_variance ⇒ Object
variance of an array of numbers
26 27 28 29 30 |
# File 'lib/enumerable.rb', line 26 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 an array of numbers
33 34 35 |
# File 'lib/enumerable.rb', line 33 def standard_deviation return Math.sqrt(self.sample_variance) end |
#sum ⇒ Object
sum of an array of numbers
16 17 18 |
# File 'lib/enumerable.rb', line 16 def sum return self.inject(0){|acc,i|acc +i} end |