Class: Bmg::Summarizer::Variance

Inherits:
Bmg::Summarizer show all
Defined in:
lib/bmg/summarizer/variance.rb

Overview

Variance summarizer

Example:

# direct ruby usage
Bmg::Summarizer.variance(:qty).summarize(...)

Direct Known Subclasses

Stddev

Instance Attribute Summary

Attributes inherited from Bmg::Summarizer

#functor, #options

Instance Method Summary collapse

Methods inherited from Bmg::Summarizer

avg, bucketize, by_proc, collect, concat, count, distinct, distinct_count, first, #happens, #initialize, last, max, median, median_cont, median_disc, min, multiple, percentile, percentile_cont, percentile_disc, stddev, sum, summarization, #summarize, #to_summarizer_name, value_by, variance

Constructor Details

This class inherits a constructor from Bmg::Summarizer

Instance Method Details

#_happens(memo, val) ⇒ Object

Aggregates on a tuple occurence.



19
20
21
22
23
24
25
26
# File 'lib/bmg/summarizer/variance.rb', line 19

def _happens(memo, val) 
  count, mean, m2 = memo
  count += 1
  delta = val - mean
  mean  += (delta / count)
  m2    += delta*(val - mean)
  [count, mean, m2]
end

#finalize(memo) ⇒ Object

Finalizes the computation.



29
30
31
32
# File 'lib/bmg/summarizer/variance.rb', line 29

def finalize(memo) 
  count, mean, m2 = memo
  m2 / count
end

#leastObject

Returns the least value.



14
15
16
# File 'lib/bmg/summarizer/variance.rb', line 14

def least()
  [0, 0.0, 0.0]
end