Class: Bmg::Summarizer::Variance
- Inherits:
-
Bmg::Summarizer
- Object
- Bmg::Summarizer
- Bmg::Summarizer::Variance
- Defined in:
- lib/bmg/summarizer/variance.rb
Overview
Variance summarizer
Example:
# direct ruby usage
Bmg::Summarizer.variance(:qty).summarize(...)
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Bmg::Summarizer
Instance Method Summary collapse
-
#_happens(memo, val) ⇒ Object
Aggregates on a tuple occurence.
-
#finalize(memo) ⇒ Object
Finalizes the computation.
-
#least ⇒ Object
Returns the least value.
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 |
#least ⇒ Object
Returns the least value.
14 15 16 |
# File 'lib/bmg/summarizer/variance.rb', line 14 def least() [0, 0.0, 0.0] end |