Method: Axiom::Aggregate::Variance.call
- Defined in:
- lib/axiom/aggregate/variance.rb
.call(accumulator, value) ⇒ Array(Integer, Numeric, Numeric)
Return the count, mean, and sum of squares for a sequence of numbers
23 24 25 26 27 28 29 30 |
# File 'lib/axiom/aggregate/variance.rb', line 23 def self.call(accumulator, value) return accumulator if value.nil? mean, sum_of_squares = accumulator.last(2) delta = mean.nil? ? value : value - mean count, new_mean = Mean.call(accumulator, value) sum_of_squares += delta * (value - new_mean) [ count, new_mean, sum_of_squares ] end |